libnvdimm/namespace: Differentiate between probe mapping and runtime mapping
[linux-2.6-block.git] / drivers / nvdimm / namespace_devs.c
index 43401325c874440823bbbce1ade81353bc0d6a23..c90664387ee5b7893427db814dbb8cd4af796f70 100644 (file)
@@ -1510,16 +1510,20 @@ static ssize_t holder_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(holder);
 
-static ssize_t __holder_class_store(struct device *dev, const char *buf)
+static int __holder_class_store(struct device *dev, const char *buf)
 {
        struct nd_namespace_common *ndns = to_ndns(dev);
 
        if (dev->driver || ndns->claim)
                return -EBUSY;
 
-       if (sysfs_streq(buf, "btt"))
-               ndns->claim_class = btt_claim_class(dev);
-       else if (sysfs_streq(buf, "pfn"))
+       if (sysfs_streq(buf, "btt")) {
+               int rc = btt_claim_class(dev);
+
+               if (rc < NVDIMM_CCLASS_NONE)
+                       return rc;
+               ndns->claim_class = rc;
+       } else if (sysfs_streq(buf, "pfn"))
                ndns->claim_class = NVDIMM_CCLASS_PFN;
        else if (sysfs_streq(buf, "dax"))
                ndns->claim_class = NVDIMM_CCLASS_DAX;
@@ -1528,10 +1532,6 @@ static ssize_t __holder_class_store(struct device *dev, const char *buf)
        else
                return -EINVAL;
 
-       /* btt_claim_class() could've returned an error */
-       if (ndns->claim_class < 0)
-               return ndns->claim_class;
-
        return 0;
 }
 
@@ -1539,7 +1539,7 @@ static ssize_t holder_class_store(struct device *dev,
                struct device_attribute *attr, const char *buf, size_t len)
 {
        struct nd_region *nd_region = to_nd_region(dev->parent);
-       ssize_t rc;
+       int rc;
 
        nd_device_lock(dev);
        nvdimm_bus_lock(dev);
@@ -1547,7 +1547,7 @@ static ssize_t holder_class_store(struct device *dev,
        rc = __holder_class_store(dev, buf);
        if (rc >= 0)
                rc = nd_namespace_label_update(nd_region, dev);
-       dev_dbg(dev, "%s(%zd)\n", rc < 0 ? "fail " : "", rc);
+       dev_dbg(dev, "%s(%d)\n", rc < 0 ? "fail " : "", rc);
        nvdimm_bus_unlock(dev);
        nd_device_unlock(dev);
 
@@ -1759,6 +1759,23 @@ struct nd_namespace_common *nvdimm_namespace_common_probe(struct device *dev)
 }
 EXPORT_SYMBOL(nvdimm_namespace_common_probe);
 
+int devm_namespace_enable(struct device *dev, struct nd_namespace_common *ndns,
+               resource_size_t size)
+{
+       if (is_namespace_blk(&ndns->dev))
+               return 0;
+       return devm_nsio_enable(dev, to_nd_namespace_io(&ndns->dev), size);
+}
+EXPORT_SYMBOL_GPL(devm_namespace_enable);
+
+void devm_namespace_disable(struct device *dev, struct nd_namespace_common *ndns)
+{
+       if (is_namespace_blk(&ndns->dev))
+               return;
+       devm_nsio_disable(dev, to_nd_namespace_io(&ndns->dev));
+}
+EXPORT_SYMBOL_GPL(devm_namespace_disable);
+
 static struct device **create_namespace_io(struct nd_region *nd_region)
 {
        struct nd_namespace_io *nsio;
@@ -1987,7 +2004,7 @@ static struct device *create_namespace_pmem(struct nd_region *nd_region,
                nd_mapping = &nd_region->mapping[i];
                label_ent = list_first_entry_or_null(&nd_mapping->labels,
                                typeof(*label_ent), list);
-               label0 = label_ent ? label_ent->label : 0;
+               label0 = label_ent ? label_ent->label : NULL;
 
                if (!label0) {
                        WARN_ON(1);
@@ -2322,8 +2339,9 @@ static struct device **scan_labels(struct nd_region *nd_region)
                        continue;
 
                /* skip labels that describe extents outside of the region */
-               if (nd_label->dpa < nd_mapping->start || nd_label->dpa > map_end)
-                       continue;
+               if (__le64_to_cpu(nd_label->dpa) < nd_mapping->start ||
+                   __le64_to_cpu(nd_label->dpa) > map_end)
+                               continue;
 
                i = add_namespace_resource(nd_region, nd_label, devs, count);
                if (i < 0)