From f555a8af97e2744535bead96b3f7a4087105a8f3 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Mon, 18 Oct 2021 13:34:44 -0700 Subject: [PATCH] nvme: Add nvme_ctrlr_destruct_namespace This function destructs a single namespace and removes it from the controller. Change-Id: I4b7b3576beda85c9ddad4e0f2db6d1964fa72b82 Signed-off-by: Ben Walker Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10024 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Eugene Kochetov Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto Reviewed-by: Aleksey Marchuk Reviewed-by: Jim Harris --- lib/nvme/nvme_ctrlr.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/lib/nvme/nvme_ctrlr.c b/lib/nvme/nvme_ctrlr.c index 4088e8d6ba..7cb70c28fe 100644 --- a/lib/nvme/nvme_ctrlr.c +++ b/lib/nvme/nvme_ctrlr.c @@ -2138,6 +2138,23 @@ nvme_active_ns_ctx_destroy(struct nvme_active_ns_ctx *ctx) free(ctx); } +static int +nvme_ctrlr_destruct_namespace(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid) +{ + struct spdk_nvme_ns *ns; + + assert(ctrlr != NULL); + + if (nsid < 1 || nsid > ctrlr->num_ns) { + return -EINVAL; + } + + ns = &ctrlr->ns[nsid - 1]; + nvme_ns_destruct(ns); + + return 0; +} + static void nvme_ctrlr_identify_active_ns_swap(struct spdk_nvme_ctrlr *ctrlr, uint32_t **new_ns_list, size_t max_entries) @@ -2848,8 +2865,8 @@ nvme_ctrlr_destruct_namespaces(struct spdk_nvme_ctrlr *ctrlr) if (ctrlr->ns) { uint32_t i, num_ns = ctrlr->num_ns; - for (i = 0; i < num_ns; i++) { - nvme_ns_destruct(&ctrlr->ns[i]); + for (i = 1; i <= num_ns; i++) { + nvme_ctrlr_destruct_namespace(ctrlr, i); } spdk_free(ctrlr->ns); @@ -2890,7 +2907,7 @@ nvme_ctrlr_update_namespaces(struct spdk_nvme_ctrlr *ctrlr) if (nsdata->ncap && !ns_is_active) { NVME_CTRLR_DEBUGLOG(ctrlr, "Namespace %u was removed\n", nsid); - nvme_ns_destruct(ns); + nvme_ctrlr_destruct_namespace(ctrlr, nsid); } } } @@ -4495,7 +4512,6 @@ spdk_nvme_ctrlr_detach_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid, { struct nvme_completion_poll_status *status; int res; - struct spdk_nvme_ns *ns; if (nsid == 0) { return -EINVAL; @@ -4527,12 +4543,7 @@ spdk_nvme_ctrlr_detach_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid, return res; } - ns = spdk_nvme_ctrlr_get_ns(ctrlr, nsid); - assert(ns != NULL); - /* Inactive NS */ - nvme_ns_destruct(ns); - - return 0; + return nvme_ctrlr_destruct_namespace(ctrlr, nsid); } uint32_t @@ -4584,7 +4595,6 @@ spdk_nvme_ctrlr_delete_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid) { struct nvme_completion_poll_status *status; int res; - struct spdk_nvme_ns *ns; if (nsid == 0) { return -EINVAL; @@ -4615,11 +4625,7 @@ spdk_nvme_ctrlr_delete_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid) return res; } - ns = spdk_nvme_ctrlr_get_ns(ctrlr, nsid); - assert(ns != NULL); - nvme_ns_destruct(ns); - - return 0; + return nvme_ctrlr_destruct_namespace(ctrlr, nsid); } int