Commit ae07bdf1 authored by Ziye Yang's avatar Ziye Yang Committed by Jim Harris
Browse files

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: default avatarZiye Yang <ziye.yang@intel.com>
parent 0c01cc56
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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];

+7 −2
Original line number Diff line number Diff line
@@ -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) {
		lun->ref--;
		if (lun->ref == 0) {
			spdk_put_io_channel(lun->io_channel);
			lun->io_channel = NULL;
		}
	}
}