Skip to content

Commit f56541a

Browse files
committed
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 <[email protected]> Link: https://lore.kernel.org/r/162982115185.1124374.13459190993792729776.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Dan Williams <[email protected]>
1 parent 7cd35b2 commit f56541a

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

drivers/nvdimm/label.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,33 @@ static struct resource *to_resource(struct nvdimm_drvdata *ndd,
898898
return NULL;
899899
}
900900

901+
static void nsl_set_blk_isetcookie(struct nvdimm_drvdata *ndd,
902+
struct nd_namespace_label *nd_label,
903+
u64 isetcookie)
904+
{
905+
if (namespace_label_has(ndd, type_guid)) {
906+
nsl_set_isetcookie(ndd, nd_label, isetcookie);
907+
return;
908+
}
909+
nsl_set_isetcookie(ndd, nd_label, 0); /* N/A */
910+
}
911+
912+
bool nsl_validate_blk_isetcookie(struct nvdimm_drvdata *ndd,
913+
struct nd_namespace_label *nd_label,
914+
u64 isetcookie)
915+
{
916+
if (!namespace_label_has(ndd, type_guid))
917+
return true;
918+
919+
if (nsl_get_isetcookie(ndd, nd_label) != isetcookie) {
920+
dev_dbg(ndd->dev, "expect cookie %#llx got %#llx\n", isetcookie,
921+
nsl_get_isetcookie(ndd, nd_label));
922+
return false;
923+
}
924+
925+
return true;
926+
}
927+
901928
/*
902929
* 1/ Account all the labels that can be freed after this update
903930
* 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,
10421069
nsl_set_nlabel(ndd, nd_label, 0xffff);
10431070
nsl_set_position(ndd, nd_label, 0xffff);
10441071
}
1045-
nsl_set_isetcookie(ndd, nd_label, nd_set->cookie2);
10461072
} else {
10471073
nsl_set_nlabel(ndd, nd_label, 0); /* N/A */
10481074
nsl_set_position(ndd, nd_label, 0); /* N/A */
1049-
nsl_set_isetcookie(ndd, nd_label, 0); /* N/A */
10501075
}
1076+
nsl_set_blk_isetcookie(ndd, nd_label, nd_set->cookie2);
10511077

10521078
nsl_set_dpa(ndd, nd_label, res->start);
10531079
nsl_set_rawsize(ndd, nd_label, resource_size(res));

drivers/nvdimm/namespace_devs.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,14 +2272,9 @@ static struct device *create_namespace_blk(struct nd_region *nd_region,
22722272
&nd_label->type_guid);
22732273
return ERR_PTR(-EAGAIN);
22742274
}
2275-
2276-
if (nd_label->isetcookie != __cpu_to_le64(nd_set->cookie2)) {
2277-
dev_dbg(ndd->dev, "expect cookie %#llx got %#llx\n",
2278-
nd_set->cookie2,
2279-
nsl_get_isetcookie(ndd, nd_label));
2280-
return ERR_PTR(-EAGAIN);
2281-
}
22822275
}
2276+
if (!nsl_validate_blk_isetcookie(ndd, nd_label, nd_set->cookie2))
2277+
return ERR_PTR(-EAGAIN);
22832278

22842279
nsblk = kzalloc(sizeof(*nsblk), GFP_KERNEL);
22852280
if (!nsblk)

drivers/nvdimm/nd.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ static inline void nsl_set_lbasize(struct nvdimm_drvdata *ndd,
177177
nd_label->lbasize = __cpu_to_le64(lbasize);
178178
}
179179

180+
bool nsl_validate_blk_isetcookie(struct nvdimm_drvdata *ndd,
181+
struct nd_namespace_label *nd_label,
182+
u64 isetcookie);
183+
180184
struct nd_region_data {
181185
int ns_count;
182186
int ns_active;

0 commit comments

Comments
 (0)