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 <konrad.sztyber@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478190
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Konrad Sztyber 2019-12-17 13:40:56 +01:00 committed by Tomasz Zawadzki
parent 5e0fa7e9c2
commit 6db4a00c58

View File

@ -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);
}