From ae07bdf1251a3142f5bd8cea191ee21f5df1f837 Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Fri, 23 Dec 2016 15:34:53 +0800 Subject: [PATCH] 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 --- include/spdk/scsi.h | 3 +++ lib/scsi/lun.c | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/spdk/scsi.h b/include/spdk/scsi.h index a26ec1744..7613df504 100644 --- a/include/spdk/scsi.h +++ b/include/spdk/scsi.h @@ -212,6 +212,9 @@ struct spdk_scsi_lun { */ 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. */ char name[SPDK_SCSI_LUN_MAX_NAME_LENGTH]; diff --git a/lib/scsi/lun.c b/lib/scsi/lun.c index abc268a12..79914a391 100644 --- a/lib/scsi/lun.c +++ b/lib/scsi/lun.c @@ -395,6 +395,7 @@ int spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_lun *lun) { if (lun->io_channel != NULL) { if (pthread_self() == lun->thread_id) { + lun->ref++; return 0; } 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; } lun->thread_id = pthread_self(); + lun->ref = 1; return 0; } void spdk_scsi_lun_free_io_channel(struct spdk_scsi_lun *lun) { if (lun->io_channel != NULL) { - spdk_put_io_channel(lun->io_channel); - lun->io_channel = NULL; + lun->ref--; + if (lun->ref == 0) { + spdk_put_io_channel(lun->io_channel); + lun->io_channel = NULL; + } } }