From 6db4a00c5894446606aeb5c0810a198e31a9ea61 Mon Sep 17 00:00:00 2001 From: Konrad Sztyber Date: Tue, 17 Dec 2019 13:40:56 +0100 Subject: [PATCH] bdev/nvme: depopulate namespaces in module_fini callback Currently the namespaces are depopulated in two cases: if the controller is detached (either due to its hot unplug or RPC call) or due to "namespace attribute changed" asynchronous event. It means that during shutdown, when nvme_bdev_ctrlr is destroyed, the namespaces aren't depopulated. For regular NVMe namespaces it isn't a big issue, since their only depopulate task is to unregister bdevs created on that namespace, which is already done by the bdev layer. However, it can be a problem for other types of namespaces (e.g. Open Channel), as they might allocate their own context in nvme_bdev_ns.type_ctx, which, unless the namespace is depopulated, cannot be freed. Change-Id: I91c7f2a50b206b45eb5bdcada278d6454c4cf144 Signed-off-by: Konrad Sztyber Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478190 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- module/bdev/nvme/bdev_nvme.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/module/bdev/nvme/bdev_nvme.c b/module/bdev/nvme/bdev_nvme.c index d6400b3aad..b2a79ae0aa 100644 --- a/module/bdev/nvme/bdev_nvme.c +++ b/module/bdev/nvme/bdev_nvme.c @@ -1794,6 +1794,8 @@ 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); @@ -1820,6 +1822,17 @@ bdev_nvme_library_fini(void) nvme_bdev_ctrlr->destruct = true; 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_bdev_ctrlr_destruct(nvme_bdev_ctrlr); pthread_mutex_lock(&g_bdev_nvme_mutex); }