Commit 2571cbd8 authored by Jim Harris's avatar Jim Harris Committed by Tomasz Zawadzki
Browse files

bdev/nvme: use mutex to protect 'resetting' member



This isn't in the performance path, so using the mutex
here makes it a bit more consistent with other ctrlr
members such as 'destruct'.

This prepares for a future patch which will defer
ctrlr destruction on removal if a reset is in progress.

Signed-off-by: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: Ica019cd90dc3b46ef6a13dd311054dbdc95855aa

Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1252


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
parent 9f51cf32
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -329,7 +329,9 @@ _bdev_nvme_reset_complete(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, int rc)
		SPDK_NOTICELOG("Resetting controller successful.\n");
	}

	__atomic_clear(&nvme_bdev_ctrlr->resetting, __ATOMIC_RELAXED);
	pthread_mutex_lock(&g_bdev_nvme_mutex);
	nvme_bdev_ctrlr->resetting = false;
	pthread_mutex_unlock(&g_bdev_nvme_mutex);
	/* Make sure we clear any pending resets before returning. */
	spdk_for_each_channel(nvme_bdev_ctrlr,
			      _bdev_nvme_complete_pending_resets,
@@ -426,7 +428,11 @@ bdev_nvme_reset(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, struct nvme_bdev_io *bi
	struct spdk_io_channel *ch;
	struct nvme_io_channel *nvme_ch;

	if (__atomic_test_and_set(&nvme_bdev_ctrlr->resetting, __ATOMIC_RELAXED)) {
	pthread_mutex_lock(&g_bdev_nvme_mutex);
	if (!nvme_bdev_ctrlr->resetting) {
		nvme_bdev_ctrlr->resetting = true;
	} else {
		pthread_mutex_unlock(&g_bdev_nvme_mutex);
		SPDK_NOTICELOG("Unable to perform reset, already in progress.\n");
		/*
		 * The internal reset calls won't be queued. This is on purpose so that we don't
@@ -443,6 +449,7 @@ bdev_nvme_reset(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, struct nvme_bdev_io *bi
		return 0;
	}

	pthread_mutex_unlock(&g_bdev_nvme_mutex);
	/* First, delete all NVMe I/O queue pairs. */
	spdk_for_each_channel(nvme_bdev_ctrlr,
			      _bdev_nvme_reset_destroy_qpair,