libnvdimm/labels: Add blk isetcookie set / validation helpers
authorDan Williams <dan.j.williams@intel.com>
Tue, 24 Aug 2021 16:05:51 +0000 (09:05 -0700)
committerDan Williams <dan.j.williams@intel.com>
Tue, 24 Aug 2021 19:08:28 +0000 (12:08 -0700)
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>
drivers/nvdimm/label.c
drivers/nvdimm/namespace_devs.c
drivers/nvdimm/nd.h

index 3f73412dd4380b5d3c400b2903bf3eef42927017..d1a7f399cfe4aa680f292b9cb49cc393c75b9b36 100644 (file)
@@ -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));
index fb9e080ce654f057c65e570ca7e54bdcfebbaf5b..fbd0c2fcea4a8b9275433da09d951c41e3c5535c 100644 (file)
@@ -2272,14 +2272,9 @@ static struct device *create_namespace_blk(struct nd_region *nd_region,
                                        &nd_label->type_guid);
                        return ERR_PTR(-EAGAIN);
                }
-
-               if (nd_label->isetcookie != __cpu_to_le64(nd_set->cookie2)) {
-                       dev_dbg(ndd->dev, "expect cookie %#llx got %#llx\n",
-                                       nd_set->cookie2,
-                                       nsl_get_isetcookie(ndd, nd_label));
-                       return ERR_PTR(-EAGAIN);
-               }
        }
+       if (!nsl_validate_blk_isetcookie(ndd, nd_label, nd_set->cookie2))
+               return ERR_PTR(-EAGAIN);
 
        nsblk = kzalloc(sizeof(*nsblk), GFP_KERNEL);
        if (!nsblk)
index 9bf9cd4a9a2d04af8ca7280b5e93d33e280cdf44..955c4395a8e309cf4c9c053142a6b71e7c7e8778 100644 (file)
@@ -177,6 +177,10 @@ static inline void nsl_set_lbasize(struct nvdimm_drvdata *ndd,
        nd_label->lbasize = __cpu_to_le64(lbasize);
 }
 
+bool nsl_validate_blk_isetcookie(struct nvdimm_drvdata *ndd,
+                                struct nd_namespace_label *nd_label,
+                                u64 isetcookie);
+
 struct nd_region_data {
        int ns_count;
        int ns_active;