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 <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/417807
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Shuhei Matsumoto 2018-07-10 16:17:34 +09:00 committed by Ben Walker
parent c740e56928
commit fec7c88e45
5 changed files with 32 additions and 10 deletions

View File

@ -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
}

View File

@ -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;

View File

@ -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)
{

View File

@ -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);

View File

@ -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)
{
}