bdev/nvme: Factor out nvme_bdev_ctrlr destruction further
Factor out the common operation to destruct nvme_bdev_ctrlr further into an new helper function _nvme_bdev_ctrlr_destruct() from remove_cb(), bdev_nvme_delete(), and bdev_nvme_library_fini(). The next patch will use SPDK message to fix the race condition by locking/unlocking during linked list parse. Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: If5392bebcf830fac6165aa424b06aec0c9274dc8 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5320 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
parent
e5b2304448
commit
6bd83dd1c7
@ -1594,6 +1594,23 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
||||
free(name);
|
||||
}
|
||||
|
||||
static void
|
||||
_nvme_bdev_ctrlr_destruct(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
remove_cb(void *cb_ctx, struct spdk_nvme_ctrlr *ctrlr)
|
||||
{
|
||||
@ -1610,17 +1627,7 @@ remove_cb(void *cb_ctx, struct spdk_nvme_ctrlr *ctrlr)
|
||||
nvme_bdev_ctrlr->destruct = true;
|
||||
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
||||
|
||||
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);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -2057,17 +2064,7 @@ bdev_nvme_delete(const char *name)
|
||||
nvme_bdev_ctrlr->destruct = true;
|
||||
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
||||
|
||||
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);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -2110,17 +2107,9 @@ bdev_nvme_library_fini(void)
|
||||
|
||||
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
||||
|
||||
nvme_ctrlr_depopulate_namespaces(nvme_bdev_ctrlr);
|
||||
_nvme_bdev_ctrlr_destruct(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);
|
||||
pthread_mutex_lock(&g_bdev_nvme_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
g_bdev_nvme_module_finish = true;
|
||||
|
Loading…
Reference in New Issue
Block a user