bdev/nvme: Factor out depopulate all namespaces into a helper function
We have two functions, remove_cb() and bdev_nvme_library_fini() to depopulate all existing namespaces. Factoring out the operation into a helper function nvme_ctrlr_depopulate_namespaces() will improve the readability. Besides, change the line after return value for two functions to adjust format. Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: Ibda921bdc94a50c14cca0ece462f76197efc5ccb Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4642 Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Paul Luse <paul.e.luse@intel.com> Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
0004476aac
commit
edced1368d
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user