Commit 6a6bef90 authored by Dave Jiang's avatar Dave Jiang Committed by Dan Williams

libnvdimm: add mechanism to publish badblocks at the region level

badblocks sysfs file will be export at region level. When nvdimm event
notifier happens for NVDIMM_REVALIATE_POISON, the badblocks in the
region will be updated.
Signed-off-by: default avatarDave Jiang <dave.jiang@intel.com>
Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
parent 3c87f372
...@@ -154,6 +154,7 @@ struct nd_region { ...@@ -154,6 +154,7 @@ struct nd_region {
u64 ndr_start; u64 ndr_start;
int id, num_lanes, ro, numa_node; int id, num_lanes, ro, numa_node;
void *provider_data; void *provider_data;
struct badblocks bb;
struct nd_interleave_set *nd_set; struct nd_interleave_set *nd_set;
struct nd_percpu_lane __percpu *lane; struct nd_percpu_lane __percpu *lane;
struct nd_mapping mapping[0]; struct nd_mapping mapping[0];
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/nd.h> #include <linux/nd.h>
#include "nd-core.h"
#include "nd.h" #include "nd.h"
static int nd_region_probe(struct device *dev) static int nd_region_probe(struct device *dev)
...@@ -52,6 +53,17 @@ static int nd_region_probe(struct device *dev) ...@@ -52,6 +53,17 @@ static int nd_region_probe(struct device *dev)
if (rc && err && rc == err) if (rc && err && rc == err)
return -ENODEV; return -ENODEV;
if (is_nd_pmem(&nd_region->dev)) {
struct resource ndr_res;
if (devm_init_badblocks(dev, &nd_region->bb))
return -ENODEV;
ndr_res.start = nd_region->ndr_start;
ndr_res.end = nd_region->ndr_start + nd_region->ndr_size - 1;
nvdimm_badblocks_populate(nd_region,
&nd_region->bb, &ndr_res);
}
nd_region->btt_seed = nd_btt_create(nd_region); nd_region->btt_seed = nd_btt_create(nd_region);
nd_region->pfn_seed = nd_pfn_create(nd_region); nd_region->pfn_seed = nd_pfn_create(nd_region);
nd_region->dax_seed = nd_dax_create(nd_region); nd_region->dax_seed = nd_dax_create(nd_region);
...@@ -104,6 +116,18 @@ static int child_notify(struct device *dev, void *data) ...@@ -104,6 +116,18 @@ static int child_notify(struct device *dev, void *data)
static void nd_region_notify(struct device *dev, enum nvdimm_event event) static void nd_region_notify(struct device *dev, enum nvdimm_event event)
{ {
if (event == NVDIMM_REVALIDATE_POISON) {
struct nd_region *nd_region = to_nd_region(dev);
struct resource res;
if (is_nd_pmem(&nd_region->dev)) {
res.start = nd_region->ndr_start;
res.end = nd_region->ndr_start +
nd_region->ndr_size - 1;
nvdimm_badblocks_populate(nd_region,
&nd_region->bb, &res);
}
}
device_for_each_child(dev, &event, child_notify); device_for_each_child(dev, &event, child_notify);
} }
......
...@@ -448,6 +448,21 @@ static ssize_t read_only_store(struct device *dev, ...@@ -448,6 +448,21 @@ static ssize_t read_only_store(struct device *dev,
} }
static DEVICE_ATTR_RW(read_only); static DEVICE_ATTR_RW(read_only);
static ssize_t nd_badblocks_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct nd_region *nd_region = to_nd_region(dev);
return badblocks_show(&nd_region->bb, buf, 0);
}
static struct device_attribute dev_attr_nd_badblocks = {
.attr = {
.name = "badblocks",
.mode = S_IRUGO
},
.show = nd_badblocks_show,
};
static struct attribute *nd_region_attributes[] = { static struct attribute *nd_region_attributes[] = {
&dev_attr_size.attr, &dev_attr_size.attr,
&dev_attr_nstype.attr, &dev_attr_nstype.attr,
...@@ -460,6 +475,7 @@ static struct attribute *nd_region_attributes[] = { ...@@ -460,6 +475,7 @@ static struct attribute *nd_region_attributes[] = {
&dev_attr_available_size.attr, &dev_attr_available_size.attr,
&dev_attr_namespace_seed.attr, &dev_attr_namespace_seed.attr,
&dev_attr_init_namespaces.attr, &dev_attr_init_namespaces.attr,
&dev_attr_nd_badblocks.attr,
NULL, NULL,
}; };
...@@ -476,6 +492,9 @@ static umode_t region_visible(struct kobject *kobj, struct attribute *a, int n) ...@@ -476,6 +492,9 @@ static umode_t region_visible(struct kobject *kobj, struct attribute *a, int n)
if (!is_nd_pmem(dev) && a == &dev_attr_dax_seed.attr) if (!is_nd_pmem(dev) && a == &dev_attr_dax_seed.attr)
return 0; return 0;
if (!is_nd_pmem(dev) && a == &dev_attr_nd_badblocks.attr)
return 0;
if (a != &dev_attr_set_cookie.attr if (a != &dev_attr_set_cookie.attr
&& a != &dev_attr_available_size.attr) && a != &dev_attr_available_size.attr)
return a->mode; return a->mode;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment