Skip to content

Commit

Permalink
libnvdimm: write blk label set
Browse files Browse the repository at this point in the history
After 'uuid', 'size', 'sector_size', and optionally 'alt_name' have been
set to valid values the labels on the dimm can be updated.  The
difference with the pmem case is that blk namespaces are limited to one
dimm and can cover discontiguous ranges in dpa space.

Also, after allocating label slots, it is useful for userspace to know
how many slots are left.  Export this information in sysfs.

Cc: Greg KH <gregkh@linuxfoundation.org>
Cc: Neil Brown <neilb@suse.de>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
  • Loading branch information
Dan Williams committed Jun 25, 2015
1 parent f524bf2 commit 0ba1c63
Show file tree
Hide file tree
Showing 6 changed files with 369 additions and 24 deletions.
4 changes: 4 additions & 0 deletions drivers/nvdimm/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ static void nd_async_device_unregister(void *d, async_cookie_t cookie)
{
struct device *dev = d;

/* flush bus operations before delete */
nvdimm_bus_lock(dev);
nvdimm_bus_unlock(dev);

device_unregister(dev);
put_device(dev);
}
Expand Down
25 changes: 25 additions & 0 deletions drivers/nvdimm/dimm_devs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
};

Expand Down
Loading

0 comments on commit 0ba1c63

Please sign in to comment.