Commit 799e0a84 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

lib/scsi: Merge append and execute SCSI task into a single function



Both for SCSI IO task and management task, append and execute
operations bad bbeen separated into different functions.

Append operation was for LUN reset, and separating into two different
functions was for clarification and readability.

LUN reset is sufficiently stable now.

Merging append and execute SCSI task into a single function is good
as API and enables us to do optimization.

For SCSI management task, merge spdk_scsi_lun_append_mgmt_task into
spdk_scsi_lun_execute_mgmt_task() simply.

For SCSI IO task, merge spdk_scsi_lun_append_task into
spdk_scsi_lun_execute_task() and do a small optimization.
The refined spdk_scsi_lun_execute_task() adds the IO task to the
pending list if there is any pending management task, executes all
existing penging IO tasks first and then the IO task if there is any
pending IO task, or executes the IO task directly otherwise.

Update unit test accordingly.

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


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom CI
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 2aa74d8b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

SO_VER := 2
SO_VER := 3
SO_MINOR := 0
SO_SUFFIX := $(SO_VER).$(SO_MINOR)

+2 −4
Original line number Diff line number Diff line
@@ -262,8 +262,7 @@ spdk_scsi_dev_queue_mgmt_task(struct spdk_scsi_dev *dev,
{
	assert(task != NULL);

	spdk_scsi_lun_append_mgmt_task(task->lun, task);
	spdk_scsi_lun_execute_mgmt_task(task->lun);
	spdk_scsi_lun_execute_mgmt_task(task->lun, task);
}

void
@@ -272,8 +271,7 @@ spdk_scsi_dev_queue_task(struct spdk_scsi_dev *dev,
{
	assert(task != NULL);

	spdk_scsi_lun_append_task(task->lun, task);
	spdk_scsi_lun_execute_tasks(task->lun);
	spdk_scsi_lun_execute_task(task->lun, task);
}

static struct spdk_scsi_port *
+35 −15
Original line number Diff line number Diff line
@@ -40,6 +40,9 @@
#include "spdk/util.h"
#include "spdk/likely.h"

static void scsi_lun_execute_tasks(struct spdk_scsi_lun *lun);
static void scsi_lun_execute_mgmt_task(struct spdk_scsi_lun *lun);

void
spdk_scsi_lun_complete_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task)
{
@@ -58,7 +61,7 @@ scsi_lun_complete_mgmt_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *ta
	task->cpl_fn(task);

	/* Try to execute the first pending mgmt task if it exists. */
	spdk_scsi_lun_execute_mgmt_task(lun);
	scsi_lun_execute_mgmt_task(lun);
}

static bool
@@ -116,15 +119,15 @@ spdk_scsi_lun_complete_reset_task(struct spdk_scsi_lun *lun, struct spdk_scsi_ta
	scsi_lun_complete_mgmt_task(lun, task);
}

void
spdk_scsi_lun_append_mgmt_task(struct spdk_scsi_lun *lun,
static void
scsi_lun_append_mgmt_task(struct spdk_scsi_lun *lun,
			  struct spdk_scsi_task *task)
{
	TAILQ_INSERT_TAIL(&lun->pending_mgmt_tasks, task, scsi_link);
}

void
spdk_scsi_lun_execute_mgmt_task(struct spdk_scsi_lun *lun)
static void
scsi_lun_execute_mgmt_task(struct spdk_scsi_lun *lun)
{
	struct spdk_scsi_task *task;

@@ -135,7 +138,7 @@ spdk_scsi_lun_execute_mgmt_task(struct spdk_scsi_lun *lun)
	task = TAILQ_FIRST(&lun->pending_mgmt_tasks);
	if (spdk_likely(task == NULL)) {
		/* Try to execute all pending tasks */
		spdk_scsi_lun_execute_tasks(lun);
		scsi_lun_execute_tasks(lun);
		return;
	}
	TAILQ_REMOVE(&lun->pending_mgmt_tasks, task, scsi_link);
@@ -177,6 +180,14 @@ spdk_scsi_lun_execute_mgmt_task(struct spdk_scsi_lun *lun)
	scsi_lun_complete_mgmt_task(lun, task);
}

void
spdk_scsi_lun_execute_mgmt_task(struct spdk_scsi_lun *lun,
				struct spdk_scsi_task *task)
{
	scsi_lun_append_mgmt_task(lun, task);
	scsi_lun_execute_mgmt_task(lun);
}

static void
_scsi_lun_execute_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task)
{
@@ -212,8 +223,8 @@ _scsi_lun_execute_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task)
	}
}

void
spdk_scsi_lun_append_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task)
static void
scsi_lun_append_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task)
{
	TAILQ_INSERT_TAIL(&lun->pending_tasks, task, scsi_link);
}
@@ -230,15 +241,24 @@ scsi_lun_execute_tasks(struct spdk_scsi_lun *lun)
}

void
spdk_scsi_lun_execute_tasks(struct spdk_scsi_lun *lun)
spdk_scsi_lun_execute_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task)
{
	if (scsi_lun_has_pending_mgmt_tasks(lun) ||
	    scsi_lun_has_outstanding_mgmt_tasks(lun)) {
		/* Pending IO tasks will wait for completion of existing mgmt tasks.
	if (spdk_unlikely(scsi_lun_has_pending_mgmt_tasks(lun))) {
		/* Add the IO task to pending list and wait for completion of
		 * existing mgmt tasks.
		 */
		return;
	}
		scsi_lun_append_task(lun, task);
	} else if (spdk_unlikely(scsi_lun_has_pending_tasks(lun))) {
		/* If there is any pending IO task, append the IO task to the
		 * tail of the pending list, and then execute all pending IO tasks
		 * from the head to submit IO tasks in order.
		 */
		scsi_lun_append_task(lun, task);
		scsi_lun_execute_tasks(lun);
	} else {
		/* Execute the IO task directly. */
		_scsi_lun_execute_task(lun, task);
	}
}

static void
+2 −4
Original line number Diff line number Diff line
@@ -176,10 +176,8 @@ struct spdk_scsi_lun *spdk_scsi_lun_construct(struct spdk_bdev *bdev,
		void *hotremove_ctx);
void spdk_scsi_lun_destruct(struct spdk_scsi_lun *lun);

void spdk_scsi_lun_append_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task);
void spdk_scsi_lun_execute_tasks(struct spdk_scsi_lun *lun);
void spdk_scsi_lun_append_mgmt_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task);
void spdk_scsi_lun_execute_mgmt_task(struct spdk_scsi_lun *lun);
void spdk_scsi_lun_execute_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task);
void spdk_scsi_lun_execute_mgmt_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task);
bool spdk_scsi_lun_has_pending_mgmt_tasks(const struct spdk_scsi_lun *lun,
		const struct spdk_scsi_port *initiator_port);
void spdk_scsi_lun_complete_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task);
+2 −6
Original line number Diff line number Diff line
@@ -115,16 +115,12 @@ spdk_bdev_get_by_name(const char *bdev_name)
	return NULL;
}

DEFINE_STUB_V(spdk_scsi_lun_append_mgmt_task,
DEFINE_STUB_V(spdk_scsi_lun_execute_mgmt_task,
	      (struct spdk_scsi_lun *lun, struct spdk_scsi_task *task));

DEFINE_STUB_V(spdk_scsi_lun_execute_mgmt_task, (struct spdk_scsi_lun *lun));

DEFINE_STUB_V(spdk_scsi_lun_append_task,
DEFINE_STUB_V(spdk_scsi_lun_execute_task,
	      (struct spdk_scsi_lun *lun, struct spdk_scsi_task *task));

DEFINE_STUB_V(spdk_scsi_lun_execute_tasks, (struct spdk_scsi_lun *lun));

DEFINE_STUB(_spdk_scsi_lun_allocate_io_channel, int,
	    (struct spdk_scsi_lun *lun), 0);

Loading