Skip to content

Commit 8176f14

Browse files
committed
libnvdimm/labels: Introduce label setter 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. Reported-by: kernel test robot <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Link: https://lore.kernel.org/r/162982114123.1124374.17153270107594686116.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Dan Williams <[email protected]>
1 parent 9761b02 commit 8176f14

File tree

3 files changed

+99
-33
lines changed

3 files changed

+99
-33
lines changed

drivers/nvdimm/label.c

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,9 @@ static bool slot_valid(struct nvdimm_drvdata *ndd,
358358
u64 sum, sum_save;
359359

360360
sum_save = nsl_get_checksum(ndd, nd_label);
361-
nd_label->checksum = __cpu_to_le64(0);
361+
nsl_set_checksum(ndd, nd_label, 0);
362362
sum = nd_fletcher64(nd_label, sizeof_namespace_label(ndd), 1);
363-
nd_label->checksum = __cpu_to_le64(sum_save);
363+
nsl_set_checksum(ndd, nd_label, sum_save);
364364
if (sum != sum_save) {
365365
dev_dbg(ndd->dev, "fail checksum. slot: %d expect: %#llx\n",
366366
slot, sum);
@@ -797,16 +797,15 @@ static int __pmem_label_update(struct nd_region *nd_region,
797797
nd_label = to_label(ndd, slot);
798798
memset(nd_label, 0, sizeof_namespace_label(ndd));
799799
memcpy(nd_label->uuid, nspm->uuid, NSLABEL_UUID_LEN);
800-
if (nspm->alt_name)
801-
memcpy(nd_label->name, nspm->alt_name, NSLABEL_NAME_LEN);
802-
nd_label->flags = __cpu_to_le32(flags);
803-
nd_label->nlabel = __cpu_to_le16(nd_region->ndr_mappings);
804-
nd_label->position = __cpu_to_le16(pos);
805-
nd_label->isetcookie = __cpu_to_le64(cookie);
806-
nd_label->rawsize = __cpu_to_le64(resource_size(res));
807-
nd_label->lbasize = __cpu_to_le64(nspm->lbasize);
808-
nd_label->dpa = __cpu_to_le64(res->start);
809-
nd_label->slot = __cpu_to_le32(slot);
800+
nsl_set_name(ndd, nd_label, nspm->alt_name);
801+
nsl_set_flags(ndd, nd_label, flags);
802+
nsl_set_nlabel(ndd, nd_label, nd_region->ndr_mappings);
803+
nsl_set_position(ndd, nd_label, pos);
804+
nsl_set_isetcookie(ndd, nd_label, cookie);
805+
nsl_set_rawsize(ndd, nd_label, resource_size(res));
806+
nsl_set_lbasize(ndd, nd_label, nspm->lbasize);
807+
nsl_set_dpa(ndd, nd_label, res->start);
808+
nsl_set_slot(ndd, nd_label, slot);
810809
if (namespace_label_has(ndd, type_guid))
811810
guid_copy(&nd_label->type_guid, &nd_set->type_guid);
812811
if (namespace_label_has(ndd, abstraction_guid))
@@ -816,9 +815,9 @@ static int __pmem_label_update(struct nd_region *nd_region,
816815
if (namespace_label_has(ndd, checksum)) {
817816
u64 sum;
818817

819-
nd_label->checksum = __cpu_to_le64(0);
818+
nsl_set_checksum(ndd, nd_label, 0);
820819
sum = nd_fletcher64(nd_label, sizeof_namespace_label(ndd), 1);
821-
nd_label->checksum = __cpu_to_le64(sum);
820+
nsl_set_checksum(ndd, nd_label, sum);
822821
}
823822
nd_dbg_dpa(nd_region, ndd, res, "\n");
824823

@@ -1017,10 +1016,8 @@ static int __blk_label_update(struct nd_region *nd_region,
10171016
nd_label = to_label(ndd, slot);
10181017
memset(nd_label, 0, sizeof_namespace_label(ndd));
10191018
memcpy(nd_label->uuid, nsblk->uuid, NSLABEL_UUID_LEN);
1020-
if (nsblk->alt_name)
1021-
memcpy(nd_label->name, nsblk->alt_name,
1022-
NSLABEL_NAME_LEN);
1023-
nd_label->flags = __cpu_to_le32(NSLABEL_FLAG_LOCAL);
1019+
nsl_set_name(ndd, nd_label, nsblk->alt_name);
1020+
nsl_set_flags(ndd, nd_label, NSLABEL_FLAG_LOCAL);
10241021

10251022
/*
10261023
* Use the presence of the type_guid as a flag to
@@ -1029,23 +1026,23 @@ static int __blk_label_update(struct nd_region *nd_region,
10291026
*/
10301027
if (namespace_label_has(ndd, type_guid)) {
10311028
if (i == min_dpa_idx) {
1032-
nd_label->nlabel = __cpu_to_le16(nsblk->num_resources);
1033-
nd_label->position = __cpu_to_le16(0);
1029+
nsl_set_nlabel(ndd, nd_label, nsblk->num_resources);
1030+
nsl_set_position(ndd, nd_label, 0);
10341031
} else {
1035-
nd_label->nlabel = __cpu_to_le16(0xffff);
1036-
nd_label->position = __cpu_to_le16(0xffff);
1032+
nsl_set_nlabel(ndd, nd_label, 0xffff);
1033+
nsl_set_position(ndd, nd_label, 0xffff);
10371034
}
1038-
nd_label->isetcookie = __cpu_to_le64(nd_set->cookie2);
1035+
nsl_set_isetcookie(ndd, nd_label, nd_set->cookie2);
10391036
} else {
1040-
nd_label->nlabel = __cpu_to_le16(0); /* N/A */
1041-
nd_label->position = __cpu_to_le16(0); /* N/A */
1042-
nd_label->isetcookie = __cpu_to_le64(0); /* N/A */
1037+
nsl_set_nlabel(ndd, nd_label, 0); /* N/A */
1038+
nsl_set_position(ndd, nd_label, 0); /* N/A */
1039+
nsl_set_isetcookie(ndd, nd_label, 0); /* N/A */
10431040
}
10441041

1045-
nd_label->dpa = __cpu_to_le64(res->start);
1046-
nd_label->rawsize = __cpu_to_le64(resource_size(res));
1047-
nd_label->lbasize = __cpu_to_le64(nsblk->lbasize);
1048-
nd_label->slot = __cpu_to_le32(slot);
1042+
nsl_set_dpa(ndd, nd_label, res->start);
1043+
nsl_set_rawsize(ndd, nd_label, resource_size(res));
1044+
nsl_set_lbasize(ndd, nd_label, nsblk->lbasize);
1045+
nsl_set_slot(ndd, nd_label, slot);
10491046
if (namespace_label_has(ndd, type_guid))
10501047
guid_copy(&nd_label->type_guid, &nd_set->type_guid);
10511048
if (namespace_label_has(ndd, abstraction_guid))
@@ -1056,10 +1053,10 @@ static int __blk_label_update(struct nd_region *nd_region,
10561053
if (namespace_label_has(ndd, checksum)) {
10571054
u64 sum;
10581055

1059-
nd_label->checksum = __cpu_to_le64(0);
1056+
nsl_set_checksum(ndd, nd_label, 0);
10601057
sum = nd_fletcher64(nd_label,
10611058
sizeof_namespace_label(ndd), 1);
1062-
nd_label->checksum = __cpu_to_le64(sum);
1059+
nsl_set_checksum(ndd, nd_label, sum);
10631060
}
10641061

10651062
/* update label */

drivers/nvdimm/namespace_devs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2569,7 +2569,7 @@ static int init_active_labels(struct nd_region *nd_region)
25692569
u32 flags = nsl_get_flags(ndd, label);
25702570

25712571
flags &= ~NSLABEL_FLAG_LOCAL;
2572-
label->flags = __cpu_to_le32(flags);
2572+
nsl_set_flags(ndd, label, flags);
25732573
}
25742574
label_ent->label = label;
25752575

drivers/nvdimm/nd.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,42 +47,89 @@ static inline u8 *nsl_get_name(struct nvdimm_drvdata *ndd,
4747
return memcpy(name, nd_label->name, NSLABEL_NAME_LEN);
4848
}
4949

50+
static inline u8 *nsl_set_name(struct nvdimm_drvdata *ndd,
51+
struct nd_namespace_label *nd_label, u8 *name)
52+
{
53+
if (!name)
54+
return NULL;
55+
return memcpy(nd_label->name, name, NSLABEL_NAME_LEN);
56+
}
57+
5058
static inline u32 nsl_get_slot(struct nvdimm_drvdata *ndd,
5159
struct nd_namespace_label *nd_label)
5260
{
5361
return __le32_to_cpu(nd_label->slot);
5462
}
5563

64+
static inline void nsl_set_slot(struct nvdimm_drvdata *ndd,
65+
struct nd_namespace_label *nd_label, u32 slot)
66+
{
67+
nd_label->slot = __cpu_to_le32(slot);
68+
}
69+
5670
static inline u64 nsl_get_checksum(struct nvdimm_drvdata *ndd,
5771
struct nd_namespace_label *nd_label)
5872
{
5973
return __le64_to_cpu(nd_label->checksum);
6074
}
6175

76+
static inline void nsl_set_checksum(struct nvdimm_drvdata *ndd,
77+
struct nd_namespace_label *nd_label,
78+
u64 checksum)
79+
{
80+
nd_label->checksum = __cpu_to_le64(checksum);
81+
}
82+
6283
static inline u32 nsl_get_flags(struct nvdimm_drvdata *ndd,
6384
struct nd_namespace_label *nd_label)
6485
{
6586
return __le32_to_cpu(nd_label->flags);
6687
}
6788

89+
static inline void nsl_set_flags(struct nvdimm_drvdata *ndd,
90+
struct nd_namespace_label *nd_label, u32 flags)
91+
{
92+
nd_label->flags = __cpu_to_le32(flags);
93+
}
94+
6895
static inline u64 nsl_get_dpa(struct nvdimm_drvdata *ndd,
6996
struct nd_namespace_label *nd_label)
7097
{
7198
return __le64_to_cpu(nd_label->dpa);
7299
}
73100

101+
static inline void nsl_set_dpa(struct nvdimm_drvdata *ndd,
102+
struct nd_namespace_label *nd_label, u64 dpa)
103+
{
104+
nd_label->dpa = __cpu_to_le64(dpa);
105+
}
106+
74107
static inline u64 nsl_get_rawsize(struct nvdimm_drvdata *ndd,
75108
struct nd_namespace_label *nd_label)
76109
{
77110
return __le64_to_cpu(nd_label->rawsize);
78111
}
79112

113+
static inline void nsl_set_rawsize(struct nvdimm_drvdata *ndd,
114+
struct nd_namespace_label *nd_label,
115+
u64 rawsize)
116+
{
117+
nd_label->rawsize = __cpu_to_le64(rawsize);
118+
}
119+
80120
static inline u64 nsl_get_isetcookie(struct nvdimm_drvdata *ndd,
81121
struct nd_namespace_label *nd_label)
82122
{
83123
return __le64_to_cpu(nd_label->isetcookie);
84124
}
85125

126+
static inline void nsl_set_isetcookie(struct nvdimm_drvdata *ndd,
127+
struct nd_namespace_label *nd_label,
128+
u64 isetcookie)
129+
{
130+
nd_label->isetcookie = __cpu_to_le64(isetcookie);
131+
}
132+
86133
static inline bool nsl_validate_isetcookie(struct nvdimm_drvdata *ndd,
87134
struct nd_namespace_label *nd_label,
88135
u64 cookie)
@@ -96,18 +143,40 @@ static inline u16 nsl_get_position(struct nvdimm_drvdata *ndd,
96143
return __le16_to_cpu(nd_label->position);
97144
}
98145

146+
static inline void nsl_set_position(struct nvdimm_drvdata *ndd,
147+
struct nd_namespace_label *nd_label,
148+
u16 position)
149+
{
150+
nd_label->position = __cpu_to_le16(position);
151+
}
152+
153+
99154
static inline u16 nsl_get_nlabel(struct nvdimm_drvdata *ndd,
100155
struct nd_namespace_label *nd_label)
101156
{
102157
return __le16_to_cpu(nd_label->nlabel);
103158
}
104159

160+
static inline void nsl_set_nlabel(struct nvdimm_drvdata *ndd,
161+
struct nd_namespace_label *nd_label,
162+
u16 nlabel)
163+
{
164+
nd_label->nlabel = __cpu_to_le16(nlabel);
165+
}
166+
105167
static inline u64 nsl_get_lbasize(struct nvdimm_drvdata *ndd,
106168
struct nd_namespace_label *nd_label)
107169
{
108170
return __le64_to_cpu(nd_label->lbasize);
109171
}
110172

173+
static inline void nsl_set_lbasize(struct nvdimm_drvdata *ndd,
174+
struct nd_namespace_label *nd_label,
175+
u64 lbasize)
176+
{
177+
nd_label->lbasize = __cpu_to_le64(lbasize);
178+
}
179+
111180
struct nd_region_data {
112181
int ns_count;
113182
int ns_active;

0 commit comments

Comments
 (0)