Commit a516cd4b authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Jim Harris
Browse files

nvmf: exec state change cpl callbacks on requesting thread



It's prep for when we queue these state change requests and the
completion might end up on a different thread than the one that
requested the state change.

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: Ic46e471521e129e58da7bed4bea213e858ba60f7
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/22939


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
parent 15a7b105
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -261,6 +261,8 @@ struct nvmf_subsystem_state_change_ctx {

	enum spdk_nvmf_subsystem_state		original_state;
	enum spdk_nvmf_subsystem_state		requested_state;
	int					status;
	struct spdk_thread			*thread;

	spdk_nvmf_subsystem_state_change_done	cb_fn;
	void					*cb_arg;
+17 −2
Original line number Diff line number Diff line
@@ -564,8 +564,9 @@ nvmf_subsystem_set_state(struct spdk_nvmf_subsystem *subsystem,
}

static void
nvmf_subsystem_state_change_complete(struct nvmf_subsystem_state_change_ctx *ctx, int status)
_nvmf_subsystem_state_change_complete(void *_ctx)
{
	struct nvmf_subsystem_state_change_ctx *ctx = _ctx;
	struct spdk_nvmf_subsystem *subsystem = ctx->subsystem;

	pthread_mutex_lock(&subsystem->mutex);
@@ -573,12 +574,19 @@ nvmf_subsystem_state_change_complete(struct nvmf_subsystem_state_change_ctx *ctx
	pthread_mutex_unlock(&subsystem->mutex);

	if (ctx->cb_fn != NULL) {
		ctx->cb_fn(subsystem, ctx->cb_arg, status);
		ctx->cb_fn(subsystem, ctx->cb_arg, ctx->status);
	}

	free(ctx);
}

static void
nvmf_subsystem_state_change_complete(struct nvmf_subsystem_state_change_ctx *ctx, int status)
{
	ctx->status = status;
	spdk_thread_exec_msg(ctx->thread, _nvmf_subsystem_state_change_complete, ctx);
}

static void
subsystem_state_change_revert_done(struct spdk_io_channel_iter *i, int status)
{
@@ -685,8 +693,14 @@ nvmf_subsystem_state_change(struct spdk_nvmf_subsystem *subsystem,
{
	struct nvmf_subsystem_state_change_ctx *ctx;
	enum spdk_nvmf_subsystem_state intermediate_state;
	struct spdk_thread *thread;
	int rc;

	thread = spdk_get_thread();
	if (thread == NULL) {
		return -EINVAL;
	}

	ctx = calloc(1, sizeof(*ctx));
	if (!ctx) {
		return -ENOMEM;
@@ -697,6 +711,7 @@ nvmf_subsystem_state_change(struct spdk_nvmf_subsystem *subsystem,
	ctx->requested_state = requested_state;
	ctx->cb_fn = cb_fn;
	ctx->cb_arg = cb_arg;
	ctx->thread = thread;

	pthread_mutex_lock(&subsystem->mutex);
	if (subsystem->changing_state) {