Commit 322e5046 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Ben Walker
Browse files

scsi: Use not pthread_self but spdk_get_thread for LUN affinity



spdk_thread is recommended to be used in SPDK library.

Change-Id: I5b75f390ddb2069e1266a3fc4f28732b281df725
Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/416482


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarZiye Yang <optimistyzy@gmail.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 1e1e0dd7
Loading
Loading
Loading
Loading
+14 −8
Original line number Diff line number Diff line
@@ -302,7 +302,7 @@ spdk_scsi_lun_destruct(struct spdk_scsi_lun *lun)
int spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_lun *lun)
{
	if (lun->io_channel != NULL) {
		if (pthread_self() == lun->thread_id) {
		if (spdk_get_thread() == spdk_io_channel_get_thread(lun->io_channel)) {
			lun->ref++;
			return 0;
		}
@@ -315,21 +315,27 @@ int spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_lun *lun)
	if (lun->io_channel == NULL) {
		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) {
	if (lun->io_channel == NULL) {
		return;
	}

	if (spdk_get_thread() != spdk_io_channel_get_thread(lun->io_channel)) {
		SPDK_ERRLOG("io_channel was freed by different thread\n");
		return;
	}

	lun->ref--;
	if (lun->ref == 0) {
		spdk_put_io_channel(lun->io_channel);
		lun->io_channel = NULL;
	}
}
}

int
spdk_scsi_lun_get_id(const struct spdk_scsi_lun *lun)
+0 −5
Original line number Diff line number Diff line
@@ -88,11 +88,6 @@ struct spdk_scsi_lun {
	/** I/O channel for the bdev associated with this LUN. */
	struct spdk_io_channel *io_channel;

	/** Thread ID for the thread that allocated the I/O channel for this
	 *   LUN.  All I/O to this LUN must be performed from this thread.
	 */
	pthread_t thread_id;

	/**  The reference number for this LUN, thus we can correctly free the io_channel */
	uint32_t ref;