bdev/nvme: Factor out decrementing ref. count of nvme_bdev_ns
Factor out the common operation of nvme_ctrlr_depopulate_namespace_done() and nvme_bdev_attach_bdev_to_ns() into a helper function nvme_bdev_ns_detach(). Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: I8efa8bc2c2d455d0fd9e0865ff85fd265d14ee06 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5613 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:
parent
723d9443f9
commit
060495b140
@ -1312,16 +1312,7 @@ timeout_cb(void *cb_arg, struct spdk_nvme_ctrlr *ctrlr,
|
|||||||
void
|
void
|
||||||
nvme_ctrlr_depopulate_namespace_done(struct nvme_bdev_ns *nvme_ns)
|
nvme_ctrlr_depopulate_namespace_done(struct nvme_bdev_ns *nvme_ns)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&g_bdev_nvme_mutex);
|
nvme_bdev_ns_detach(nvme_ns);
|
||||||
assert(nvme_ns->ref > 0);
|
|
||||||
nvme_ns->ref--;
|
|
||||||
if (nvme_ns->ref > 0) {
|
|
||||||
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
|
||||||
|
|
||||||
nvme_bdev_ctrlr_destruct(nvme_ns->ctrlr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -184,6 +184,21 @@ nvme_bdev_ctrlr_destruct(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr)
|
|||||||
nvme_bdev_ctrlr_do_destruct(nvme_bdev_ctrlr);
|
nvme_bdev_ctrlr_do_destruct(nvme_bdev_ctrlr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nvme_bdev_ns_detach(struct nvme_bdev_ns *nvme_ns)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(&g_bdev_nvme_mutex);
|
||||||
|
assert(nvme_ns->ref > 0);
|
||||||
|
nvme_ns->ref--;
|
||||||
|
if (nvme_ns->ref > 0) {
|
||||||
|
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
||||||
|
|
||||||
|
nvme_bdev_ctrlr_destruct(nvme_ns->ctrlr);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nvme_bdev_attach_bdev_to_ns(struct nvme_bdev_ns *nvme_ns, struct nvme_bdev *nvme_disk)
|
nvme_bdev_attach_bdev_to_ns(struct nvme_bdev_ns *nvme_ns, struct nvme_bdev *nvme_disk)
|
||||||
{
|
{
|
||||||
@ -201,14 +216,7 @@ nvme_bdev_detach_bdev_from_ns(struct nvme_bdev *nvme_disk)
|
|||||||
|
|
||||||
pthread_mutex_lock(&g_bdev_nvme_mutex);
|
pthread_mutex_lock(&g_bdev_nvme_mutex);
|
||||||
TAILQ_REMOVE(&nvme_disk->nvme_ns->bdevs, nvme_disk, tailq);
|
TAILQ_REMOVE(&nvme_disk->nvme_ns->bdevs, nvme_disk, tailq);
|
||||||
|
|
||||||
assert(nvme_ns->ref > 0);
|
|
||||||
nvme_ns->ref--;
|
|
||||||
if (nvme_ns->ref > 0) {
|
|
||||||
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
||||||
|
|
||||||
nvme_bdev_ctrlr_destruct(nvme_ns->ctrlr);
|
nvme_bdev_ns_detach(nvme_ns);
|
||||||
}
|
}
|
||||||
|
@ -167,6 +167,7 @@ void nvme_bdev_dump_trid_json(const struct spdk_nvme_transport_id *trid,
|
|||||||
|
|
||||||
void nvme_bdev_ctrlr_destruct(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr);
|
void nvme_bdev_ctrlr_destruct(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr);
|
||||||
void nvme_bdev_ctrlr_do_destruct(void *ctx);
|
void nvme_bdev_ctrlr_do_destruct(void *ctx);
|
||||||
|
void nvme_bdev_ns_detach(struct nvme_bdev_ns *nvme_ns);
|
||||||
void nvme_bdev_attach_bdev_to_ns(struct nvme_bdev_ns *nvme_ns, struct nvme_bdev *nvme_disk);
|
void nvme_bdev_attach_bdev_to_ns(struct nvme_bdev_ns *nvme_ns, struct nvme_bdev *nvme_disk);
|
||||||
void nvme_bdev_detach_bdev_from_ns(struct nvme_bdev *nvme_disk);
|
void nvme_bdev_detach_bdev_from_ns(struct nvme_bdev *nvme_disk);
|
||||||
|
|
||||||
|
@ -197,13 +197,7 @@ nvme_ctrlr_populate_namespace_done(struct nvme_async_probe_ctx *ctx,
|
|||||||
void
|
void
|
||||||
nvme_ctrlr_depopulate_namespace_done(struct nvme_bdev_ns *ns)
|
nvme_ctrlr_depopulate_namespace_done(struct nvme_bdev_ns *ns)
|
||||||
{
|
{
|
||||||
CU_ASSERT(ns->ref > 0);
|
nvme_bdev_ns_detach(ns);
|
||||||
ns->ref--;
|
|
||||||
if (ns->ref > 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
nvme_bdev_ctrlr_destruct(ns->ctrlr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct nvme_bdev_ctrlr *
|
static struct nvme_bdev_ctrlr *
|
||||||
|
Loading…
Reference in New Issue
Block a user