scsi: make the io channel of scsi lun free correct
Previously, we did not calculate the ref for the LUN. Change-Id: If2b7bc7d129e7efd994a7987ae2c421048969acb Signed-off-by: Ziye Yang <ziye.yang@intel.com>
This commit is contained in:
parent
0c01cc5664
commit
ae07bdf125
@ -212,6 +212,9 @@ struct spdk_scsi_lun {
|
|||||||
*/
|
*/
|
||||||
pthread_t thread_id;
|
pthread_t thread_id;
|
||||||
|
|
||||||
|
/** The reference number for this LUN, thus we can correctly free the io_channel */
|
||||||
|
uint32_t ref;
|
||||||
|
|
||||||
/** Name for this LUN. */
|
/** Name for this LUN. */
|
||||||
char name[SPDK_SCSI_LUN_MAX_NAME_LENGTH];
|
char name[SPDK_SCSI_LUN_MAX_NAME_LENGTH];
|
||||||
|
|
||||||
|
@ -395,6 +395,7 @@ int spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_lun *lun)
|
|||||||
{
|
{
|
||||||
if (lun->io_channel != NULL) {
|
if (lun->io_channel != NULL) {
|
||||||
if (pthread_self() == lun->thread_id) {
|
if (pthread_self() == lun->thread_id) {
|
||||||
|
lun->ref++;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
SPDK_ERRLOG("io_channel already allocated for lun %s\n", lun->name);
|
SPDK_ERRLOG("io_channel already allocated for lun %s\n", lun->name);
|
||||||
@ -406,13 +407,17 @@ int spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_lun *lun)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
lun->thread_id = pthread_self();
|
lun->thread_id = pthread_self();
|
||||||
|
lun->ref = 1;
|
||||||
return 0;
|
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) {
|
if (lun->io_channel != NULL) {
|
||||||
|
lun->ref--;
|
||||||
|
if (lun->ref == 0) {
|
||||||
spdk_put_io_channel(lun->io_channel);
|
spdk_put_io_channel(lun->io_channel);
|
||||||
lun->io_channel = NULL;
|
lun->io_channel = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user