libnvdimm: write blk label set
[deliverable/linux.git] / drivers / nvdimm / dimm_devs.c
index 156d518a089c4d37c0ae522b74388033d4d5c7ad..83b179ed6d61c64e85c0f0e3d7ea0cabcd8fa270 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/fs.h>
 #include <linux/mm.h>
 #include "nd-core.h"
+#include "label.h"
 #include "nd.h"
 
 static DEFINE_IDA(dimm_ida);
@@ -296,9 +297,33 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(state);
 
+static ssize_t available_slots_show(struct device *dev,
+               struct device_attribute *attr, char *buf)
+{
+       struct nvdimm_drvdata *ndd = dev_get_drvdata(dev);
+       ssize_t rc;
+       u32 nfree;
+
+       if (!ndd)
+               return -ENXIO;
+
+       nvdimm_bus_lock(dev);
+       nfree = nd_label_nfree(ndd);
+       if (nfree - 1 > nfree) {
+               dev_WARN_ONCE(dev, 1, "we ate our last label?\n");
+               nfree = 0;
+       } else
+               nfree--;
+       rc = sprintf(buf, "%d\n", nfree);
+       nvdimm_bus_unlock(dev);
+       return rc;
+}
+static DEVICE_ATTR_RO(available_slots);
+
 static struct attribute *nvdimm_attributes[] = {
        &dev_attr_state.attr,
        &dev_attr_commands.attr,
+       &dev_attr_available_slots.attr,
        NULL,
 };
 
This page took 0.035457 seconds and 5 git commands to generate.