diff --git a/module/bdev/nvme/bdev_nvme.c b/module/bdev/nvme/bdev_nvme.c index df2fc0c9b..6790bc63a 100644 --- a/module/bdev/nvme/bdev_nvme.c +++ b/module/bdev/nvme/bdev_nvme.c @@ -1260,13 +1260,15 @@ nvme_ctrlr_depopulate_standard_namespace(struct nvme_bdev_ns *ns) nvme_ctrlr_depopulate_namespace_done(ns->ctrlr); } -static void nvme_ctrlr_populate_namespace(struct nvme_bdev_ctrlr *ctrlr, struct nvme_bdev_ns *ns, - struct nvme_async_probe_ctx *ctx) +static void +nvme_ctrlr_populate_namespace(struct nvme_bdev_ctrlr *ctrlr, struct nvme_bdev_ns *ns, + struct nvme_async_probe_ctx *ctx) { g_populate_namespace_fn[ns->type](ctrlr, ns, ctx); } -static void nvme_ctrlr_depopulate_namespace(struct nvme_bdev_ctrlr *ctrlr, struct nvme_bdev_ns *ns) +static void +nvme_ctrlr_depopulate_namespace(struct nvme_bdev_ctrlr *ctrlr, struct nvme_bdev_ns *ns) { g_depopulate_namespace_fn[ns->type](ns); } @@ -1373,6 +1375,23 @@ nvme_ctrlr_populate_namespaces(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, } +static void +nvme_ctrlr_depopulate_namespaces(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr) +{ + uint32_t i; + struct nvme_bdev_ns *ns; + + for (i = 0; i < nvme_bdev_ctrlr->num_ns; i++) { + uint32_t nsid = i + 1; + + ns = nvme_bdev_ctrlr->namespaces[nsid - 1]; + if (ns->populated) { + assert(ns->id == nsid); + nvme_ctrlr_depopulate_namespace(nvme_bdev_ctrlr, ns); + } + } +} + static void aer_cb(void *arg, const struct spdk_nvme_cpl *cpl) { @@ -1547,9 +1566,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, static void remove_cb(void *cb_ctx, struct spdk_nvme_ctrlr *ctrlr) { - uint32_t i; struct nvme_bdev_ctrlr *nvme_bdev_ctrlr; - struct nvme_bdev_ns *ns; pthread_mutex_lock(&g_bdev_nvme_mutex); TAILQ_FOREACH(nvme_bdev_ctrlr, &g_nvme_bdev_ctrlrs, tailq) { @@ -1560,15 +1577,8 @@ remove_cb(void *cb_ctx, struct spdk_nvme_ctrlr *ctrlr) return; } pthread_mutex_unlock(&g_bdev_nvme_mutex); - for (i = 0; i < nvme_bdev_ctrlr->num_ns; i++) { - uint32_t nsid = i + 1; - ns = nvme_bdev_ctrlr->namespaces[nsid - 1]; - if (ns->populated) { - assert(ns->id == nsid); - nvme_ctrlr_depopulate_namespace(nvme_bdev_ctrlr, ns); - } - } + nvme_ctrlr_depopulate_namespaces(nvme_bdev_ctrlr); pthread_mutex_lock(&g_bdev_nvme_mutex); nvme_bdev_ctrlr->destruct = true; @@ -2226,8 +2236,6 @@ bdev_nvme_library_fini(void) { struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, *tmp; struct nvme_probe_skip_entry *entry, *entry_tmp; - struct nvme_bdev_ns *ns; - uint32_t i; spdk_poller_unregister(&g_hotplug_poller); free(g_hotplug_probe_ctx); @@ -2248,15 +2256,7 @@ bdev_nvme_library_fini(void) pthread_mutex_unlock(&g_bdev_nvme_mutex); - for (i = 0; i < nvme_bdev_ctrlr->num_ns; i++) { - uint32_t nsid = i + 1; - - ns = nvme_bdev_ctrlr->namespaces[nsid - 1]; - if (ns->populated) { - assert(ns->id == nsid); - nvme_ctrlr_depopulate_namespace(nvme_bdev_ctrlr, ns); - } - } + nvme_ctrlr_depopulate_namespaces(nvme_bdev_ctrlr); pthread_mutex_lock(&g_bdev_nvme_mutex); nvme_bdev_ctrlr->destruct = true;