mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-30 03:27:44 -04:00
libnvdimm, label: add v1.2 interleave-set-cookie algorithm
The interleave-set-cookie algorithm is extended to incorporate all the same components that are used to generate an nvdimm unique-id. For backwards compatibility we still maintain the old v1.1 definition. Reported-by: Nicholas Moulin <[email protected]> Reported-by: Kaushik Kanetkar <[email protected]> Signed-off-by: Dan Williams <[email protected]>
This commit is contained in:
parent
564e871aa6
commit
c12c48ce86
6 changed files with 104 additions and 12 deletions
|
|
@ -553,7 +553,6 @@ static int __pmem_label_update(struct nd_region *nd_region,
|
|||
struct nd_mapping *nd_mapping, struct nd_namespace_pmem *nspm,
|
||||
int pos)
|
||||
{
|
||||
u64 cookie = nd_region_interleave_set_cookie(nd_region);
|
||||
struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
|
||||
struct nd_label_ent *label_ent, *victim = NULL;
|
||||
struct nd_namespace_label *nd_label;
|
||||
|
|
@ -563,11 +562,13 @@ static int __pmem_label_update(struct nd_region *nd_region,
|
|||
unsigned long *free;
|
||||
u32 nslot, slot;
|
||||
size_t offset;
|
||||
u64 cookie;
|
||||
int rc;
|
||||
|
||||
if (!preamble_next(ndd, &nsindex, &free, &nslot))
|
||||
return -ENXIO;
|
||||
|
||||
cookie = nd_region_interleave_set_cookie(nd_region, nsindex);
|
||||
nd_label_gen_id(&label_id, nspm->uuid, 0);
|
||||
for_each_dpa_resource(ndd, res)
|
||||
if (strcmp(res->name, label_id.id) == 0)
|
||||
|
|
|
|||
|
|
@ -1698,10 +1698,11 @@ static int select_pmem_id(struct nd_region *nd_region, u8 *pmem_id)
|
|||
* @nd_label: target pmem namespace label to evaluate
|
||||
*/
|
||||
struct device *create_namespace_pmem(struct nd_region *nd_region,
|
||||
struct nd_namespace_index *nsindex,
|
||||
struct nd_namespace_label *nd_label)
|
||||
{
|
||||
u64 cookie = nd_region_interleave_set_cookie(nd_region, nsindex);
|
||||
u64 altcookie = nd_region_interleave_set_altcookie(nd_region);
|
||||
u64 cookie = nd_region_interleave_set_cookie(nd_region);
|
||||
struct nd_label_ent *label_ent;
|
||||
struct nd_namespace_pmem *nspm;
|
||||
struct nd_mapping *nd_mapping;
|
||||
|
|
@ -2108,7 +2109,11 @@ static struct device **scan_labels(struct nd_region *nd_region)
|
|||
goto err;
|
||||
devs[count++] = dev;
|
||||
} else {
|
||||
dev = create_namespace_pmem(nd_region, nd_label);
|
||||
struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
|
||||
struct nd_namespace_index *nsindex;
|
||||
|
||||
nsindex = to_namespace_index(ndd, ndd->ns_current);
|
||||
dev = create_namespace_pmem(nd_region, nsindex, nd_label);
|
||||
if (IS_ERR(dev)) {
|
||||
switch (PTR_ERR(dev)) {
|
||||
case -EAGAIN:
|
||||
|
|
|
|||
|
|
@ -336,7 +336,8 @@ static inline struct device *nd_dax_create(struct nd_region *nd_region)
|
|||
struct nd_region *to_nd_region(struct device *dev);
|
||||
int nd_region_to_nstype(struct nd_region *nd_region);
|
||||
int nd_region_register_namespaces(struct nd_region *nd_region, int *err);
|
||||
u64 nd_region_interleave_set_cookie(struct nd_region *nd_region);
|
||||
u64 nd_region_interleave_set_cookie(struct nd_region *nd_region,
|
||||
struct nd_namespace_index *nsindex);
|
||||
u64 nd_region_interleave_set_altcookie(struct nd_region *nd_region);
|
||||
void nvdimm_bus_lock(struct device *dev);
|
||||
void nvdimm_bus_unlock(struct device *dev);
|
||||
|
|
|
|||
|
|
@ -307,13 +307,41 @@ static ssize_t set_cookie_show(struct device *dev,
|
|||
{
|
||||
struct nd_region *nd_region = to_nd_region(dev);
|
||||
struct nd_interleave_set *nd_set = nd_region->nd_set;
|
||||
ssize_t rc = 0;
|
||||
|
||||
if (is_nd_pmem(dev) && nd_set)
|
||||
/* pass, should be precluded by region_visible */;
|
||||
else
|
||||
return -ENXIO;
|
||||
|
||||
return sprintf(buf, "%#llx\n", nd_set->cookie);
|
||||
/*
|
||||
* The cookie to show depends on which specification of the
|
||||
* labels we are using. If there are not labels then default to
|
||||
* the v1.1 namespace label cookie definition. To read all this
|
||||
* data we need to wait for probing to settle.
|
||||
*/
|
||||
device_lock(dev);
|
||||
nvdimm_bus_lock(dev);
|
||||
wait_nvdimm_bus_probe_idle(dev);
|
||||
if (nd_region->ndr_mappings) {
|
||||
struct nd_mapping *nd_mapping = &nd_region->mapping[0];
|
||||
struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
|
||||
|
||||
if (ndd) {
|
||||
struct nd_namespace_index *nsindex;
|
||||
|
||||
nsindex = to_namespace_index(ndd, ndd->ns_current);
|
||||
rc = sprintf(buf, "%#llx\n",
|
||||
nd_region_interleave_set_cookie(nd_region,
|
||||
nsindex));
|
||||
}
|
||||
}
|
||||
nvdimm_bus_unlock(dev);
|
||||
device_unlock(dev);
|
||||
|
||||
if (rc)
|
||||
return rc;
|
||||
return sprintf(buf, "%#llx\n", nd_set->cookie1);
|
||||
}
|
||||
static DEVICE_ATTR_RO(set_cookie);
|
||||
|
||||
|
|
@ -564,13 +592,18 @@ struct attribute_group nd_region_attribute_group = {
|
|||
};
|
||||
EXPORT_SYMBOL_GPL(nd_region_attribute_group);
|
||||
|
||||
u64 nd_region_interleave_set_cookie(struct nd_region *nd_region)
|
||||
u64 nd_region_interleave_set_cookie(struct nd_region *nd_region,
|
||||
struct nd_namespace_index *nsindex)
|
||||
{
|
||||
struct nd_interleave_set *nd_set = nd_region->nd_set;
|
||||
|
||||
if (nd_set)
|
||||
return nd_set->cookie;
|
||||
return 0;
|
||||
if (!nd_set)
|
||||
return 0;
|
||||
|
||||
if (nsindex && __le16_to_cpu(nsindex->major) == 1
|
||||
&& __le16_to_cpu(nsindex->minor) == 1)
|
||||
return nd_set->cookie1;
|
||||
return nd_set->cookie2;
|
||||
}
|
||||
|
||||
u64 nd_region_interleave_set_altcookie(struct nd_region *nd_region)
|
||||
|
|
|
|||
Loading…
Reference in a new issue