[PATCH 3/3] libnvdimm, region_devs: reset related seeds when fail to create namespace

From: Ocean He
Date: Mon Sep 10 2018 - 02:24:13 EST


From: Ocean He <hehy1@xxxxxxxxxx>

During runtime, namespace creation may fail if blocked by
commit 15d36fecd0bdc7510b70 ("mm: disallow mappings that conflict for
devm_memremap_pages()"). To ensure pfn_seed/dax_seed and namespace_seed
are ready for next namespace creation, here to do detach and reset.

Signed-off-by: Ocean He <hehy1@xxxxxxxxxx>
---
drivers/nvdimm/region_devs.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)

diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c
index fa37afc..4c46fb6 100644
--- a/drivers/nvdimm/region_devs.c
+++ b/drivers/nvdimm/region_devs.c
@@ -703,7 +703,27 @@ void nd_mapping_free_labels(struct nd_mapping *nd_mapping)
kfree(label_ent);
}
}
+/*
+ * To ensure pfn_seed/dax_seed and namespace_seed are ready for
+ * next namespace creation, here to do detach and reset.
+ */
+void nd_region_detach_and_reset(struct device *dev,
+ struct nd_region *nd_region)
+{
+ /* Only nd_pmem has been verified, fix me for other dev type. */
+ if (!is_nd_pmem(&nd_region->dev))
+ return;

+ if (is_nd_pfn(dev) || is_nd_dax(dev)) {
+ struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev);
+ struct nd_namespace_common *ndns = to_ndns(nd_region->ns_seed);
+
+ if (nd_pfn->ndns == ndns && ndns->claim == dev) {
+ nd_detach_and_reset(dev, &nd_pfn->ndns);
+ nd_region_reset_ns_seed(nd_region);
+ }
+ }
+}
/*
* Upon successful probe/remove, take/release a reference on the
* associated interleave set (if present), and plant new btt + namespace
@@ -774,6 +794,20 @@ static void nd_region_notify_driver_action(struct nvdimm_bus *nvdimm_bus,
nd_region_create_ns_seed(nd_region);
nvdimm_bus_unlock(dev);
}
+ if (is_nd_pfn(dev) && !probe) {
+ nd_region = to_nd_region(dev->parent);
+ nvdimm_bus_lock(dev);
+ if (nd_region->pfn_seed == dev)
+ nd_region_detach_and_reset(dev, nd_region);
+ nvdimm_bus_unlock(dev);
+ }
+ if (is_nd_dax(dev) && !probe) {
+ nd_region = to_nd_region(dev->parent);
+ nvdimm_bus_lock(dev);
+ if (nd_region->dax_seed == dev)
+ nd_region_detach_and_reset(dev, nd_region);
+ nvdimm_bus_unlock(dev);
+ }
}

void nd_region_probe_success(struct nvdimm_bus *nvdimm_bus, struct device *dev)
--
1.8.3.1