Skip to content

Commit 8b03aa0

Browse files
committed
libnvdimm/labels: Add type-guid helpers
In preparation for CXL label support, which does not have the type-guid concept, wrap the existing users with nsl_set_type_guid, and nsl_validate_type_guid. Recall that the type-guid is a value in the ACPI NFIT table to indicate how the memory range is used / should be presented to upper layers. Reviewed-by: Jonathan Cameron <[email protected]> Link: https://lore.kernel.org/r/162982116208.1124374.13938280892226800953.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Dan Williams <[email protected]>
1 parent de8fa48 commit 8b03aa0

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

drivers/nvdimm/label.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,26 @@ static void reap_victim(struct nd_mapping *nd_mapping,
772772
victim->label = NULL;
773773
}
774774

775+
static void nsl_set_type_guid(struct nvdimm_drvdata *ndd,
776+
struct nd_namespace_label *nd_label, guid_t *guid)
777+
{
778+
if (namespace_label_has(ndd, type_guid))
779+
guid_copy(&nd_label->type_guid, guid);
780+
}
781+
782+
bool nsl_validate_type_guid(struct nvdimm_drvdata *ndd,
783+
struct nd_namespace_label *nd_label, guid_t *guid)
784+
{
785+
if (!namespace_label_has(ndd, type_guid))
786+
return true;
787+
if (!guid_equal(&nd_label->type_guid, guid)) {
788+
dev_dbg(ndd->dev, "expect type_guid %pUb got %pUb\n", guid,
789+
&nd_label->type_guid);
790+
return false;
791+
}
792+
return true;
793+
}
794+
775795
static int __pmem_label_update(struct nd_region *nd_region,
776796
struct nd_mapping *nd_mapping, struct nd_namespace_pmem *nspm,
777797
int pos, unsigned long flags)
@@ -822,8 +842,7 @@ static int __pmem_label_update(struct nd_region *nd_region,
822842
nsl_set_lbasize(ndd, nd_label, nspm->lbasize);
823843
nsl_set_dpa(ndd, nd_label, res->start);
824844
nsl_set_slot(ndd, nd_label, slot);
825-
if (namespace_label_has(ndd, type_guid))
826-
guid_copy(&nd_label->type_guid, &nd_set->type_guid);
845+
nsl_set_type_guid(ndd, nd_label, &nd_set->type_guid);
827846
if (namespace_label_has(ndd, abstraction_guid))
828847
guid_copy(&nd_label->abstraction_guid,
829848
to_abstraction_guid(ndns->claim_class,
@@ -1091,8 +1110,7 @@ static int __blk_label_update(struct nd_region *nd_region,
10911110
nsl_set_rawsize(ndd, nd_label, resource_size(res));
10921111
nsl_set_lbasize(ndd, nd_label, nsblk->lbasize);
10931112
nsl_set_slot(ndd, nd_label, slot);
1094-
if (namespace_label_has(ndd, type_guid))
1095-
guid_copy(&nd_label->type_guid, &nd_set->type_guid);
1113+
nsl_set_type_guid(ndd, nd_label, &nd_set->type_guid);
10961114
if (namespace_label_has(ndd, abstraction_guid))
10971115
guid_copy(&nd_label->abstraction_guid,
10981116
to_abstraction_guid(ndns->claim_class,

drivers/nvdimm/namespace_devs.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,14 +1859,9 @@ static bool has_uuid_at_pos(struct nd_region *nd_region, u8 *uuid,
18591859
if (memcmp(nd_label->uuid, uuid, NSLABEL_UUID_LEN) != 0)
18601860
continue;
18611861

1862-
if (namespace_label_has(ndd, type_guid)
1863-
&& !guid_equal(&nd_set->type_guid,
1864-
&nd_label->type_guid)) {
1865-
dev_dbg(ndd->dev, "expect type_guid %pUb got %pUb\n",
1866-
&nd_set->type_guid,
1867-
&nd_label->type_guid);
1862+
if (!nsl_validate_type_guid(ndd, nd_label,
1863+
&nd_set->type_guid))
18681864
continue;
1869-
}
18701865

18711866
if (found_uuid) {
18721867
dev_dbg(ndd->dev, "duplicate entry for uuid\n");
@@ -2265,14 +2260,8 @@ static struct device *create_namespace_blk(struct nd_region *nd_region,
22652260
struct device *dev = NULL;
22662261
struct resource *res;
22672262

2268-
if (namespace_label_has(ndd, type_guid)) {
2269-
if (!guid_equal(&nd_set->type_guid, &nd_label->type_guid)) {
2270-
dev_dbg(ndd->dev, "expect type_guid %pUb got %pUb\n",
2271-
&nd_set->type_guid,
2272-
&nd_label->type_guid);
2273-
return ERR_PTR(-EAGAIN);
2274-
}
2275-
}
2263+
if (!nsl_validate_type_guid(ndd, nd_label, &nd_set->type_guid))
2264+
return ERR_PTR(-EAGAIN);
22762265
if (!nsl_validate_blk_isetcookie(ndd, nd_label, nd_set->cookie2))
22772266
return ERR_PTR(-EAGAIN);
22782267

drivers/nvdimm/nd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ static inline void nsl_set_lbasize(struct nvdimm_drvdata *ndd,
180180
bool nsl_validate_blk_isetcookie(struct nvdimm_drvdata *ndd,
181181
struct nd_namespace_label *nd_label,
182182
u64 isetcookie);
183+
bool nsl_validate_type_guid(struct nvdimm_drvdata *ndd,
184+
struct nd_namespace_label *nd_label, guid_t *guid);
183185

184186
struct nd_region_data {
185187
int ns_count;

0 commit comments

Comments
 (0)