Commit 7cef60b6 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

lib/scsi: Close block device on the thread which opened it



All connections to a single LUN run on a single thread but
this thread may not be the same as the one which opened the backed
bdev. So hold pointer to the thread which opened the backed bdev
to struct spdk_scsi_lun and use it when calling spdk_bdev_close().

All resource of LUN are accessed on a single thread after getting
I/O channel, and so lock is not still necessary.

    Fixes issue #1024.

Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: Ifc1e238d333afcde0cdf9e9b4af3b56ef65a4f7d
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/473002


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avataryidong0635 <dongx.yi@intel.com>
parent 9889ab2d
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -233,19 +233,33 @@ spdk_scsi_lun_execute_tasks(struct spdk_scsi_lun *lun)
	}
}

static void
_scsi_lun_remove(void *arg)
{
	struct spdk_scsi_lun *lun = (struct spdk_scsi_lun *)arg;

	spdk_bdev_close(lun->bdev_desc);
	spdk_scsi_dev_delete_lun(lun->dev, lun);
	free(lun);
}

static void
scsi_lun_remove(struct spdk_scsi_lun *lun)
{
	struct spdk_scsi_pr_registrant *reg, *tmp;
	struct spdk_thread *thread;

	TAILQ_FOREACH_SAFE(reg, &lun->reg_head, link, tmp) {
		TAILQ_REMOVE(&lun->reg_head, reg, link);
		free(reg);
	}
	spdk_bdev_close(lun->bdev_desc);

	spdk_scsi_dev_delete_lun(lun->dev, lun);
	free(lun);
	thread = spdk_get_thread();
	if (thread != lun->thread) {
		spdk_thread_send_msg(lun->thread, _scsi_lun_remove, lun);
	} else {
		_scsi_lun_remove(lun);
	}
}

static int
@@ -375,6 +389,8 @@ spdk_scsi_lun_construct(struct spdk_bdev *bdev,
		return NULL;
	}

	lun->thread = spdk_get_thread();

	TAILQ_INIT(&lun->tasks);
	TAILQ_INIT(&lun->pending_tasks);
	TAILQ_INIT(&lun->mgmt_tasks);
+3 −0
Original line number Diff line number Diff line
@@ -117,6 +117,9 @@ struct spdk_scsi_lun {
	/** Descriptor for opened block device. */
	struct spdk_bdev_desc *bdev_desc;

	/** The thread which opens this LUN. */
	struct spdk_thread *thread;

	/** I/O channel for the bdev associated with this LUN. */
	struct spdk_io_channel *io_channel;