From: Ocean He <[email protected]>

During runtime, if a namespace seed is used for new namespace creation
but fail, then it needs to be reset for next namespace creation.

Add function nd_region_reset_ns_seed for namespace seed reset and
declare it in nd-core.h.

Signed-off-by: Ocean He <[email protected]>
---
 drivers/nvdimm/namespace_devs.c | 32 ++++++++++++++++++++++++++++++++
 drivers/nvdimm/nd-core.h        |  1 +
 2 files changed, 33 insertions(+)

diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index 4a42662..6678bbe 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -2129,6 +2129,38 @@ void nd_region_create_ns_seed(struct nd_region 
*nd_region)
                nd_device_register(nd_region->ns_seed);
 }
 
+void nd_region_reset_ns_seed(struct nd_region *nd_region)
+{
+       struct device *dev = nd_region->ns_seed;
+       unsigned long long val = 0;
+       ssize_t rc;
+       u8 **uuid = NULL;
+
+       rc = __holder_class_store(dev, "");
+       dev_dbg(dev, "%s(%zd)\n", rc < 0 ? "fail to reset claim_class " : "", 
rc);
+
+       rc = __size_store(dev, val);
+       if (rc >= 0)
+               rc = nd_namespace_label_update(nd_region, dev);
+       dev_dbg(dev, "%s(%zd)\n", rc < 0 ? "fail to reset size " : "", rc);
+
+       if (is_namespace_pmem(dev)) {
+               struct nd_namespace_pmem *nspm = to_nd_namespace_pmem(dev);
+
+               uuid = &nspm->uuid;
+       } else if (is_namespace_blk(dev)) {
+               struct nd_namespace_blk *nsblk = to_nd_namespace_blk(dev);
+
+               uuid = &nsblk->uuid;
+       }
+
+       if (rc == 0 && val == 0 && uuid) {
+               /* setting size zero == 'delete namespace' */
+               kfree(*uuid);
+               *uuid = NULL;
+       }
+}
+
 void nd_region_create_dax_seed(struct nd_region *nd_region)
 {
        WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev));
diff --git a/drivers/nvdimm/nd-core.h b/drivers/nvdimm/nd-core.h
index 7fd74d0..3ec6909 100644
--- a/drivers/nvdimm/nd-core.h
+++ b/drivers/nvdimm/nd-core.h
@@ -81,6 +81,7 @@ static inline bool is_memory(struct device *dev)
 void nd_region_probe_success(struct nvdimm_bus *nvdimm_bus, struct device 
*dev);
 struct nd_region;
 void nd_region_create_ns_seed(struct nd_region *nd_region);
+void nd_region_reset_ns_seed(struct nd_region *nd_region);
 void nd_region_create_btt_seed(struct nd_region *nd_region);
 void nd_region_create_pfn_seed(struct nd_region *nd_region);
 void nd_region_create_dax_seed(struct nd_region *nd_region);
-- 
1.8.3.1

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

Reply via email to