From fec7c88e45fc5f7352fcb02dcee2d31e0511d44e Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Tue, 10 Jul 2018 16:17:34 +0900 Subject: [PATCH] scsi: Enforce to open LUN and then alloc IO channel by using descriptor Use a descriptor got by opening the LUN to allocate IO channel of the LUN. This requires opening the LUN is done before allocating IO channel of the LUN. Use the descriptor to free IO channel of the LUN too. Additionally, assert is added to the close LUN function to check if IO channel is freed before the last close LUN function is called. Change-Id: Iafb2f9ce790fff25801ea45b3286f3e26943807b Signed-off-by: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/417807 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Changpeng Liu Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- include/spdk/scsi.h | 8 ++++---- lib/scsi/dev.c | 4 ++-- lib/scsi/lun.c | 24 ++++++++++++++++++++++-- lib/scsi/scsi_internal.h | 2 ++ test/unit/lib/scsi/dev.c/dev_ut.c | 4 ++-- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/include/spdk/scsi.h b/include/spdk/scsi.h index fc05232e9..18126a212 100644 --- a/include/spdk/scsi.h +++ b/include/spdk/scsi.h @@ -488,18 +488,18 @@ void spdk_scsi_lun_close(struct spdk_scsi_desc *desc); /** * Allocate I/O channel for the LUN * - * \param lun Logical unit. + * \param desc Descriptor of the logical unit. * * \return 0 on success, -1 on failure. */ -int spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_lun *lun); +int spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_desc *desc); /** * Free I/O channel from the logical unit * - * \param lun Logical unit. + * \param desc Descriptor of the logical unit. */ -void spdk_scsi_lun_free_io_channel(struct spdk_scsi_lun *lun); +void spdk_scsi_lun_free_io_channel(struct spdk_scsi_desc *desc); #ifdef __cplusplus } diff --git a/lib/scsi/dev.c b/lib/scsi/dev.c index c86eaee8a..335ffacba 100644 --- a/lib/scsi/dev.c +++ b/lib/scsi/dev.c @@ -355,7 +355,7 @@ spdk_scsi_dev_free_io_channels(struct spdk_scsi_dev *dev) if (dev->lun[i] == NULL) { continue; } - spdk_scsi_lun_free_io_channel(dev->lun[i]); + _spdk_scsi_lun_free_io_channel(dev->lun[i]); } } @@ -368,7 +368,7 @@ spdk_scsi_dev_allocate_io_channels(struct spdk_scsi_dev *dev) if (dev->lun[i] == NULL) { continue; } - rc = spdk_scsi_lun_allocate_io_channel(dev->lun[i]); + rc = _spdk_scsi_lun_allocate_io_channel(dev->lun[i]); if (rc < 0) { spdk_scsi_dev_free_io_channels(dev); return -1; diff --git a/lib/scsi/lun.c b/lib/scsi/lun.c index 8bc90e9f4..33f4cd822 100644 --- a/lib/scsi/lun.c +++ b/lib/scsi/lun.c @@ -361,9 +361,12 @@ spdk_scsi_lun_close(struct spdk_scsi_desc *desc) TAILQ_REMOVE(&lun->open_descs, desc, link); free(desc); + + assert(!TAILQ_EMPTY(&lun->open_descs) || lun->io_channel == NULL); } -int spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_lun *lun) +int +_spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_lun *lun) { if (lun->io_channel != NULL) { if (spdk_get_thread() == spdk_io_channel_get_thread(lun->io_channel)) { @@ -383,7 +386,8 @@ int spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_lun *lun) return 0; } -void spdk_scsi_lun_free_io_channel(struct spdk_scsi_lun *lun) +void +_spdk_scsi_lun_free_io_channel(struct spdk_scsi_lun *lun) { if (lun->io_channel == NULL) { return; @@ -401,6 +405,22 @@ void spdk_scsi_lun_free_io_channel(struct spdk_scsi_lun *lun) } } +int +spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_desc *desc) +{ + struct spdk_scsi_lun *lun = desc->lun; + + return _spdk_scsi_lun_allocate_io_channel(lun); +} + +void +spdk_scsi_lun_free_io_channel(struct spdk_scsi_desc *desc) +{ + struct spdk_scsi_lun *lun = desc->lun; + + _spdk_scsi_lun_free_io_channel(lun); +} + int spdk_scsi_lun_get_id(const struct spdk_scsi_lun *lun) { diff --git a/lib/scsi/scsi_internal.h b/lib/scsi/scsi_internal.h index b2e63eb2a..85caf7621 100644 --- a/lib/scsi/scsi_internal.h +++ b/lib/scsi/scsi_internal.h @@ -139,6 +139,8 @@ int spdk_scsi_lun_task_mgmt_execute(struct spdk_scsi_task *task, enum spdk_scsi_ void spdk_scsi_lun_complete_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task); void spdk_scsi_lun_complete_mgmt_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task); bool spdk_scsi_lun_has_pending_tasks(const struct spdk_scsi_lun *lun); +int _spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_lun *lun); +void _spdk_scsi_lun_free_io_channel(struct spdk_scsi_lun *lun); struct spdk_scsi_dev *spdk_scsi_dev_get_list(void); diff --git a/test/unit/lib/scsi/dev.c/dev_ut.c b/test/unit/lib/scsi/dev.c/dev_ut.c index 60c4c0555..6fa906772 100644 --- a/test/unit/lib/scsi/dev.c/dev_ut.c +++ b/test/unit/lib/scsi/dev.c/dev_ut.c @@ -123,13 +123,13 @@ spdk_scsi_lun_execute_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *tas } int -spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_lun *lun) +_spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_lun *lun) { return 0; } void -spdk_scsi_lun_free_io_channel(struct spdk_scsi_lun *lun) +_spdk_scsi_lun_free_io_channel(struct spdk_scsi_lun *lun) { }