summaryrefslogtreecommitdiff
path: root/drivers/nvdimm/label.c
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2021-08-24 19:05:51 +0300
committerDan Williams <dan.j.williams@intel.com>2021-08-24 22:08:28 +0300
commitf56541a7122c68ef3074e41c2cb14182eb11d3a5 (patch)
tree733d4c7dc832733b4b0fc50aeb39da8f50b5b397 /drivers/nvdimm/label.c
parent7cd35b2920500908eb3d9d00939f2aea3e8f8361 (diff)
downloadlinux-f56541a7122c68ef3074e41c2cb14182eb11d3a5.tar.xz
libnvdimm/labels: Add blk isetcookie set / validation helpers
In preparation for LIBNVDIMM to manage labels on CXL devices deploy helpers that abstract the label type from the implementation. The CXL label format is mostly similar to the EFI label format with concepts / fields added, like dynamic region creation and label type guids, and other concepts removed like BLK-mode and interleave-set-cookie ids. Given BLK-mode is not even supported on CXL push hide the BLK-mode specific details inside the helpers. Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Link: https://lore.kernel.org/r/162982115185.1124374.13459190993792729776.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'drivers/nvdimm/label.c')
-rw-r--r--drivers/nvdimm/label.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c
index 3f73412dd438..d1a7f399cfe4 100644
--- a/drivers/nvdimm/label.c
+++ b/drivers/nvdimm/label.c
@@ -898,6 +898,33 @@ static struct resource *to_resource(struct nvdimm_drvdata *ndd,
return NULL;
}
+static void nsl_set_blk_isetcookie(struct nvdimm_drvdata *ndd,
+ struct nd_namespace_label *nd_label,
+ u64 isetcookie)
+{
+ if (namespace_label_has(ndd, type_guid)) {
+ nsl_set_isetcookie(ndd, nd_label, isetcookie);
+ return;
+ }
+ nsl_set_isetcookie(ndd, nd_label, 0); /* N/A */
+}
+
+bool nsl_validate_blk_isetcookie(struct nvdimm_drvdata *ndd,
+ struct nd_namespace_label *nd_label,
+ u64 isetcookie)
+{
+ if (!namespace_label_has(ndd, type_guid))
+ return true;
+
+ if (nsl_get_isetcookie(ndd, nd_label) != isetcookie) {
+ dev_dbg(ndd->dev, "expect cookie %#llx got %#llx\n", isetcookie,
+ nsl_get_isetcookie(ndd, nd_label));
+ return false;
+ }
+
+ return true;
+}
+
/*
* 1/ Account all the labels that can be freed after this update
* 2/ Allocate and write the label to the staging (next) index
@@ -1042,12 +1069,11 @@ static int __blk_label_update(struct nd_region *nd_region,
nsl_set_nlabel(ndd, nd_label, 0xffff);
nsl_set_position(ndd, nd_label, 0xffff);
}
- nsl_set_isetcookie(ndd, nd_label, nd_set->cookie2);
} else {
nsl_set_nlabel(ndd, nd_label, 0); /* N/A */
nsl_set_position(ndd, nd_label, 0); /* N/A */
- nsl_set_isetcookie(ndd, nd_label, 0); /* N/A */
}
+ nsl_set_blk_isetcookie(ndd, nd_label, nd_set->cookie2);
nsl_set_dpa(ndd, nd_label, res->start);
nsl_set_rawsize(ndd, nd_label, resource_size(res));