bdev/nvme: Factor out checking if nvme_ctrlr can be unregistered

Checking if nvme_ctrlr can be unregistered is not so simple and
a few changes will be added. So factoring out the check into a
helper function will be valuable.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I310c7e3ad2dae9583df4db575d342c2cb111f3f3
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10461
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
Shuhei Matsumoto 2021-11-26 04:50:57 +09:00 committed by Tomasz Zawadzki
parent 7329c1e683
commit 74f18d6a07

View File

@ -520,6 +520,28 @@ nvme_ctrlr_unregister(struct nvme_ctrlr *nvme_ctrlr)
spdk_io_device_unregister(nvme_ctrlr, nvme_ctrlr_unregister_cb);
}
static bool
nvme_ctrlr_can_be_unregistered(struct nvme_ctrlr *nvme_ctrlr)
{
if (!nvme_ctrlr->destruct) {
return false;
}
if (nvme_ctrlr->ref > 0) {
return false;
}
if (nvme_ctrlr->resetting) {
return false;
}
if (nvme_ctrlr->ana_log_page_updating) {
return false;
}
return true;
}
static void
nvme_ctrlr_release(struct nvme_ctrlr *nvme_ctrlr)
{
@ -528,8 +550,7 @@ nvme_ctrlr_release(struct nvme_ctrlr *nvme_ctrlr)
assert(nvme_ctrlr->ref > 0);
nvme_ctrlr->ref--;
if (nvme_ctrlr->ref > 0 || !nvme_ctrlr->destruct ||
nvme_ctrlr->resetting || nvme_ctrlr->ana_log_page_updating) {
if (!nvme_ctrlr_can_be_unregistered(nvme_ctrlr)) {
pthread_mutex_unlock(&nvme_ctrlr->mutex);
return;
}
@ -1270,8 +1291,7 @@ _bdev_nvme_reset_complete(struct spdk_io_channel_iter *i, int status)
path_id->is_failed = !success;
if (nvme_ctrlr->ref == 0 && nvme_ctrlr->destruct &&
!nvme_ctrlr->ana_log_page_updating) {
if (nvme_ctrlr_can_be_unregistered(nvme_ctrlr)) {
/* Complete pending destruct after reset completes. */
complete_pending_destruct = true;
}
@ -2933,8 +2953,7 @@ bdev_nvme_clear_io_path_cache_done(struct spdk_io_channel_iter *i, int status)
assert(nvme_ctrlr->ana_log_page_updating == true);
nvme_ctrlr->ana_log_page_updating = false;
if (nvme_ctrlr->ref > 0 || !nvme_ctrlr->destruct ||
nvme_ctrlr->resetting) {
if (!nvme_ctrlr_can_be_unregistered(nvme_ctrlr)) {
pthread_mutex_unlock(&nvme_ctrlr->mutex);
return;
}