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: Jim Harris <james.r.harris@intel.com>
Change-Id: Ica019cd90dc3b46ef6a13dd311054dbdc95855aa

Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1252
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
Jim Harris 2020-03-12 10:39:27 -07:00 committed by Tomasz Zawadzki
parent 9f51cf3238
commit 2571cbd807

View File

@ -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,