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

nvmf: move subsystem_state_change_ctx allocation up



We'll want to queue those contexts, so allocate them as the first thing
done in this function.

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


Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 8571999d
Loading
Loading
Loading
Loading
+13 −12
Original line number Diff line number Diff line
@@ -690,7 +690,19 @@ nvmf_subsystem_state_change(struct spdk_nvmf_subsystem *subsystem,
	enum spdk_nvmf_subsystem_state intermediate_state;
	int rc;

	ctx = calloc(1, sizeof(*ctx));
	if (!ctx) {
		return -ENOMEM;
	}

	ctx->subsystem = subsystem;
	ctx->nsid = nsid;
	ctx->requested_state = requested_state;
	ctx->cb_fn = cb_fn;
	ctx->cb_arg = cb_arg;

	if (__sync_val_compare_and_swap(&subsystem->changing_state, false, true)) {
		free(ctx);
		return -EBUSY;
	}

@@ -702,18 +714,13 @@ nvmf_subsystem_state_change(struct spdk_nvmf_subsystem *subsystem,
		if (cb_fn) {
			cb_fn(subsystem, cb_arg, 0);
		}
		free(ctx);
		return 0;
	}

	intermediate_state = nvmf_subsystem_get_intermediate_state(subsystem->state, requested_state);
	assert(intermediate_state != SPDK_NVMF_SUBSYSTEM_NUM_STATES);

	ctx = calloc(1, sizeof(*ctx));
	if (!ctx) {
		subsystem->changing_state = false;
		return -ENOMEM;
	}

	ctx->original_state = subsystem->state;
	rc = nvmf_subsystem_set_state(subsystem, intermediate_state);
	if (rc) {
@@ -722,12 +729,6 @@ nvmf_subsystem_state_change(struct spdk_nvmf_subsystem *subsystem,
		return rc;
	}

	ctx->subsystem = subsystem;
	ctx->nsid = nsid;
	ctx->requested_state = requested_state;
	ctx->cb_fn = cb_fn;
	ctx->cb_arg = cb_arg;

	spdk_for_each_channel(subsystem->tgt,
			      subsystem_state_change_on_pg,
			      ctx,