Skip to content

Commit de8fa48

Browse files
committed
libnvdimm/labels: Add blk special cases for nlabel and position 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. Finish off the BLK-mode specific helper conversion with the nlabel and position behaviour that is specific to EFI v1.2 labels and not the original v1.1 definition. Reviewed-by: Jonathan Cameron <[email protected]> Link: https://lore.kernel.org/r/162982115698.1124374.10182273478536799613.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Dan Williams <[email protected]>
1 parent f56541a commit de8fa48

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

drivers/nvdimm/label.c

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

901+
/*
902+
* Use the presence of the type_guid as a flag to determine isetcookie
903+
* usage and nlabel + position policy for blk-aperture namespaces.
904+
*/
901905
static void nsl_set_blk_isetcookie(struct nvdimm_drvdata *ndd,
902906
struct nd_namespace_label *nd_label,
903907
u64 isetcookie)
@@ -925,6 +929,28 @@ bool nsl_validate_blk_isetcookie(struct nvdimm_drvdata *ndd,
925929
return true;
926930
}
927931

932+
static void nsl_set_blk_nlabel(struct nvdimm_drvdata *ndd,
933+
struct nd_namespace_label *nd_label, int nlabel,
934+
bool first)
935+
{
936+
if (!namespace_label_has(ndd, type_guid)) {
937+
nsl_set_nlabel(ndd, nd_label, 0); /* N/A */
938+
return;
939+
}
940+
nsl_set_nlabel(ndd, nd_label, first ? nlabel : 0xffff);
941+
}
942+
943+
static void nsl_set_blk_position(struct nvdimm_drvdata *ndd,
944+
struct nd_namespace_label *nd_label,
945+
bool first)
946+
{
947+
if (!namespace_label_has(ndd, type_guid)) {
948+
nsl_set_position(ndd, nd_label, 0);
949+
return;
950+
}
951+
nsl_set_position(ndd, nd_label, first ? 0 : 0xffff);
952+
}
953+
928954
/*
929955
* 1/ Account all the labels that can be freed after this update
930956
* 2/ Allocate and write the label to the staging (next) index
@@ -1056,23 +1082,9 @@ static int __blk_label_update(struct nd_region *nd_region,
10561082
nsl_set_name(ndd, nd_label, nsblk->alt_name);
10571083
nsl_set_flags(ndd, nd_label, NSLABEL_FLAG_LOCAL);
10581084

1059-
/*
1060-
* Use the presence of the type_guid as a flag to
1061-
* determine isetcookie usage and nlabel + position
1062-
* policy for blk-aperture namespaces.
1063-
*/
1064-
if (namespace_label_has(ndd, type_guid)) {
1065-
if (i == min_dpa_idx) {
1066-
nsl_set_nlabel(ndd, nd_label, nsblk->num_resources);
1067-
nsl_set_position(ndd, nd_label, 0);
1068-
} else {
1069-
nsl_set_nlabel(ndd, nd_label, 0xffff);
1070-
nsl_set_position(ndd, nd_label, 0xffff);
1071-
}
1072-
} else {
1073-
nsl_set_nlabel(ndd, nd_label, 0); /* N/A */
1074-
nsl_set_position(ndd, nd_label, 0); /* N/A */
1075-
}
1085+
nsl_set_blk_nlabel(ndd, nd_label, nsblk->num_resources,
1086+
i == min_dpa_idx);
1087+
nsl_set_blk_position(ndd, nd_label, i == min_dpa_idx);
10761088
nsl_set_blk_isetcookie(ndd, nd_label, nd_set->cookie2);
10771089

10781090
nsl_set_dpa(ndd, nd_label, res->start);

0 commit comments

Comments
 (0)