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

nvmf: protect subsystem->changing_state with a mutex



We'll want to do more in this critical section concurrently, so an
atomic operation won't be enough.

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


Community-CI: Mellanox Build Bot
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 8de19363
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -568,7 +568,10 @@ nvmf_subsystem_state_change_complete(struct nvmf_subsystem_state_change_ctx *ctx
{
	struct spdk_nvmf_subsystem *subsystem = ctx->subsystem;

	pthread_mutex_lock(&subsystem->mutex);
	subsystem->changing_state = false;
	pthread_mutex_unlock(&subsystem->mutex);

	if (ctx->cb_fn != NULL) {
		ctx->cb_fn(subsystem, ctx->cb_arg, status);
	}
@@ -695,11 +698,16 @@ nvmf_subsystem_state_change(struct spdk_nvmf_subsystem *subsystem,
	ctx->cb_fn = cb_fn;
	ctx->cb_arg = cb_arg;

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

	subsystem->changing_state = true;
	pthread_mutex_unlock(&subsystem->mutex);

	SPDK_DTRACE_PROBE3(nvmf_subsystem_change_state, subsystem->subnqn,
			   requested_state, subsystem->state);
	/* If we are already in the requested state, just call the callback immediately. */