bdev/nvme: Merge decrementing ref. count into nvme_bdev_ctrlr_destruct()

For further simplification, merge decrementing reference count of
nvme_bdev_ctrlr into nvme_bdev_ctrlr_destruct().

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I604039c3f38a60b316ae465d4649e9eb11bfb6cc
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5573
Community-CI: Broadcom CI
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
Shuhei Matsumoto 2021-01-04 14:09:27 +09:00 committed by Tomasz Zawadzki
parent 2caff467ea
commit 528cec83fb
3 changed files with 12 additions and 43 deletions

View File

@ -1313,17 +1313,7 @@ nvme_ctrlr_depopulate_namespace_done(struct nvme_bdev_ns *nvme_ns)
{
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = nvme_ns->ctrlr;
pthread_mutex_lock(&g_bdev_nvme_mutex);
assert(nvme_bdev_ctrlr->ref > 0);
nvme_bdev_ctrlr->ref--;
if (nvme_bdev_ctrlr->ref == 0 && nvme_bdev_ctrlr->destruct) {
pthread_mutex_unlock(&g_bdev_nvme_mutex);
nvme_bdev_ctrlr_destruct(nvme_bdev_ctrlr);
return;
}
pthread_mutex_unlock(&g_bdev_nvme_mutex);
nvme_bdev_ctrlr_destruct(nvme_bdev_ctrlr);
}
static void
@ -1650,17 +1640,7 @@ _nvme_bdev_ctrlr_destruct(void *ctx)
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = ctx;
nvme_ctrlr_depopulate_namespaces(nvme_bdev_ctrlr);
pthread_mutex_lock(&g_bdev_nvme_mutex);
assert(nvme_bdev_ctrlr->ref > 0);
nvme_bdev_ctrlr->ref--;
if (nvme_bdev_ctrlr->ref == 0) {
pthread_mutex_unlock(&g_bdev_nvme_mutex);
nvme_bdev_ctrlr_destruct(nvme_bdev_ctrlr);
} else {
pthread_mutex_unlock(&g_bdev_nvme_mutex);
}
nvme_bdev_ctrlr_destruct(nvme_bdev_ctrlr);
}
static void

View File

@ -168,13 +168,17 @@ nvme_bdev_ctrlr_do_destruct(void *ctx)
void
nvme_bdev_ctrlr_destruct(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr)
{
assert(nvme_bdev_ctrlr->destruct);
pthread_mutex_lock(&g_bdev_nvme_mutex);
if (nvme_bdev_ctrlr->resetting) {
assert(nvme_bdev_ctrlr->ref > 0);
nvme_bdev_ctrlr->ref--;
if (nvme_bdev_ctrlr->ref > 0 || !nvme_bdev_ctrlr->destruct ||
nvme_bdev_ctrlr->resetting) {
pthread_mutex_unlock(&g_bdev_nvme_mutex);
return;
}
pthread_mutex_unlock(&g_bdev_nvme_mutex);
nvme_bdev_ctrlr_do_destruct(nvme_bdev_ctrlr);
@ -196,16 +200,8 @@ nvme_bdev_detach_bdev_from_ns(struct nvme_bdev *nvme_disk)
struct nvme_bdev_ctrlr *ctrlr = nvme_disk->nvme_ns->ctrlr;
pthread_mutex_lock(&g_bdev_nvme_mutex);
assert(ctrlr->ref > 0);
ctrlr->ref--;
TAILQ_REMOVE(&nvme_disk->nvme_ns->bdevs, nvme_disk, tailq);
if (ctrlr->ref == 0 && ctrlr->destruct) {
pthread_mutex_unlock(&g_bdev_nvme_mutex);
nvme_bdev_ctrlr_destruct(ctrlr);
return;
}
pthread_mutex_unlock(&g_bdev_nvme_mutex);
nvme_bdev_ctrlr_destruct(ctrlr);
}

View File

@ -199,12 +199,7 @@ nvme_ctrlr_depopulate_namespace_done(struct nvme_bdev_ns *ns)
{
struct nvme_bdev_ctrlr *ctrlr = ns->ctrlr;
CU_ASSERT(ctrlr->ref > 0);
ctrlr->ref--;
if (ctrlr->ref == 0 && ctrlr->destruct) {
nvme_bdev_ctrlr_destruct(ctrlr);
}
nvme_bdev_ctrlr_destruct(ctrlr);
}
static struct nvme_bdev_ctrlr *
@ -542,8 +537,6 @@ delete_nvme_bdev_controller(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr)
bdev_ocssd_depopulate_namespace(nvme_bdev_ctrlr->namespaces[nsid]);
}
CU_ASSERT(nvme_bdev_ctrlr->ref == 1);
nvme_bdev_ctrlr->ref--;
nvme_bdev_ctrlr_destruct(nvme_bdev_ctrlr);
spdk_delay_us(1000);