[PATCH v3 3/7] nvdimm: pmem: assign a parent resource for vmemmap region for the fsdax

Li Zhijian
2024-03-06T10:29:21Z

When the pmem is configured as fsdax, set the vmemmap region as a child
of the namespace region so that it can be registered as a separate
resource later.

CC: Dan Williams <dan.j.williams@intel.com>
CC: Vishal Verma <vishal.l.verma@intel.com>
CC: Dave Jiang <dave.jiang@intel.com>
CC: Ira Weiny <ira.weiny@intel.com>
CC: Baoquan He <bhe@redhat.com>
CC: nvdimm@lists.linux.dev
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
drivers/nvdimm/pmem.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index 4e8fdcb3f1c8..b2640a3fb693 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -452,7 +452,7 @@ static int pmem_attach_disk(struct device *dev,
struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
struct nd_region *nd_region = to_nd_region(dev->parent);
int nid = dev_to_node(dev), fua;
- struct resource *res = &nsio->res;
+ struct resource *res = &nsio->res, *parent;
struct range bb_range;
struct nd_pfn *nd_pfn = NULL;
struct dax_device *dax_dev;
@@ -491,12 +491,15 @@ static int pmem_attach_disk(struct device *dev,
fua = 0;
}

- if (!devm_request_mem_region(dev, res->start, resource_size(res),
- dev_name(&ndns->dev))) {
+ parent = devm_request_mem_region(dev, res->start, resource_size(res),
+ dev_name(&ndns->dev));
+ if (!res) {
dev_warn(dev, "could not reserve region %pR\n", res);
return -EBUSY;
}

+ pgmap_parent_resource(&pmem->pgmap, parent);
+
disk = blk_alloc_disk(nid);
if (!disk)
return -ENOMEM;
--
2.29.2