Skip to content

Commit 468ded0

Browse files
djbwtorvalds
authored andcommitted
libnvdimm, pmem: move request_queue allocation earlier in probe
Before the dynamically allocated struct pages from devm_memremap_pages() can be put to use outside the driver, we need a mechanism to track whether they are still in use at teardown. Towards that goal reorder the initialization sequence to allow the 'q_usage_counter' from the request_queue to be used by the devm_memremap_pages() implementation (in subsequent patches). Signed-off-by: Dan Williams <[email protected]> Cc: Ross Zwisler <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent f25748e commit 468ded0

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

drivers/nvdimm/pmem.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ static struct pmem_device *pmem_alloc(struct device *dev,
159159
struct resource *res, int id)
160160
{
161161
struct pmem_device *pmem;
162+
struct request_queue *q;
162163

163164
pmem = devm_kzalloc(dev, sizeof(*pmem), GFP_KERNEL);
164165
if (!pmem)
@@ -176,6 +177,10 @@ static struct pmem_device *pmem_alloc(struct device *dev,
176177
return ERR_PTR(-EBUSY);
177178
}
178179

180+
q = blk_alloc_queue_node(GFP_KERNEL, dev_to_node(dev));
181+
if (!q)
182+
return ERR_PTR(-ENOMEM);
183+
179184
pmem->pfn_flags = PFN_DEV;
180185
if (pmem_should_map_pages(dev)) {
181186
pmem->virt_addr = (void __pmem *) devm_memremap_pages(dev, res,
@@ -186,9 +191,12 @@ static struct pmem_device *pmem_alloc(struct device *dev,
186191
pmem->phys_addr, pmem->size,
187192
ARCH_MEMREMAP_PMEM);
188193

189-
if (IS_ERR(pmem->virt_addr))
194+
if (IS_ERR(pmem->virt_addr)) {
195+
blk_cleanup_queue(q);
190196
return (void __force *) pmem->virt_addr;
197+
}
191198

199+
pmem->pmem_queue = q;
192200
return pmem;
193201
}
194202

@@ -208,10 +216,6 @@ static int pmem_attach_disk(struct device *dev,
208216
int nid = dev_to_node(dev);
209217
struct gendisk *disk;
210218

211-
pmem->pmem_queue = blk_alloc_queue_node(GFP_KERNEL, nid);
212-
if (!pmem->pmem_queue)
213-
return -ENOMEM;
214-
215219
blk_queue_make_request(pmem->pmem_queue, pmem_make_request);
216220
blk_queue_physical_block_size(pmem->pmem_queue, PAGE_SIZE);
217221
blk_queue_max_hw_sectors(pmem->pmem_queue, UINT_MAX);
@@ -446,19 +450,22 @@ static int nd_pmem_probe(struct device *dev)
446450
return -ENOMEM;
447451
nvdimm_namespace_add_poison(ndns, &pmem->bb, 0);
448452

449-
if (is_nd_btt(dev))
453+
if (is_nd_btt(dev)) {
454+
/* btt allocates its own request_queue */
455+
blk_cleanup_queue(pmem->pmem_queue);
456+
pmem->pmem_queue = NULL;
450457
return nvdimm_namespace_attach_btt(ndns);
458+
}
451459

452460
if (is_nd_pfn(dev))
453461
return nvdimm_namespace_attach_pfn(ndns);
454462

455-
if (nd_btt_probe(ndns, pmem) == 0) {
456-
/* we'll come back as btt-pmem */
457-
return -ENXIO;
458-
}
459-
460-
if (nd_pfn_probe(ndns, pmem) == 0) {
461-
/* we'll come back as pfn-pmem */
463+
if (nd_btt_probe(ndns, pmem) == 0 || nd_pfn_probe(ndns, pmem) == 0) {
464+
/*
465+
* We'll come back as either btt-pmem, or pfn-pmem, so
466+
* drop the queue allocation for now.
467+
*/
468+
blk_cleanup_queue(pmem->pmem_queue);
462469
return -ENXIO;
463470
}
464471

0 commit comments

Comments
 (0)