Merge branch 'for-4.5/drivers' of git://git.kernel.dk/linux-block
[deliverable/linux.git] / drivers / nvdimm / pmem.c
index 03d86687f97b55b4c0084e2730e43381b17ecde7..7edf31671dabed8f8d193806f54f3d1b30401e7c 100644 (file)
@@ -159,6 +159,7 @@ static struct pmem_device *pmem_alloc(struct device *dev,
                struct resource *res, int id)
 {
        struct pmem_device *pmem;
+       struct request_queue *q;
 
        pmem = devm_kzalloc(dev, sizeof(*pmem), GFP_KERNEL);
        if (!pmem)
@@ -176,19 +177,26 @@ static struct pmem_device *pmem_alloc(struct device *dev,
                return ERR_PTR(-EBUSY);
        }
 
+       q = blk_alloc_queue_node(GFP_KERNEL, dev_to_node(dev));
+       if (!q)
+               return ERR_PTR(-ENOMEM);
+
        pmem->pfn_flags = PFN_DEV;
        if (pmem_should_map_pages(dev)) {
                pmem->virt_addr = (void __pmem *) devm_memremap_pages(dev, res,
-                               NULL);
+                               &q->q_usage_counter, NULL);
                pmem->pfn_flags |= PFN_MAP;
        } else
                pmem->virt_addr = (void __pmem *) devm_memremap(dev,
                                pmem->phys_addr, pmem->size,
                                ARCH_MEMREMAP_PMEM);
 
-       if (IS_ERR(pmem->virt_addr))
+       if (IS_ERR(pmem->virt_addr)) {
+               blk_cleanup_queue(q);
                return (void __force *) pmem->virt_addr;
+       }
 
+       pmem->pmem_queue = q;
        return pmem;
 }
 
@@ -208,10 +216,6 @@ static int pmem_attach_disk(struct device *dev,
        int nid = dev_to_node(dev);
        struct gendisk *disk;
 
-       pmem->pmem_queue = blk_alloc_queue_node(GFP_KERNEL, nid);
-       if (!pmem->pmem_queue)
-               return -ENOMEM;
-
        blk_queue_make_request(pmem->pmem_queue, pmem_make_request);
        blk_queue_physical_block_size(pmem->pmem_queue, PAGE_SIZE);
        blk_queue_max_hw_sectors(pmem->pmem_queue, UINT_MAX);
@@ -361,6 +365,7 @@ static int nvdimm_namespace_attach_pfn(struct nd_namespace_common *ndns)
        struct vmem_altmap *altmap;
        struct nd_pfn_sb *pfn_sb;
        struct pmem_device *pmem;
+       struct request_queue *q;
        phys_addr_t offset;
        int rc;
        struct vmem_altmap __altmap = {
@@ -402,9 +407,10 @@ static int nvdimm_namespace_attach_pfn(struct nd_namespace_common *ndns)
 
        /* establish pfn range for lookup, and switch to direct map */
        pmem = dev_get_drvdata(dev);
+       q = pmem->pmem_queue;
        devm_memunmap(dev, (void __force *) pmem->virt_addr);
        pmem->virt_addr = (void __pmem *) devm_memremap_pages(dev, &nsio->res,
-                       altmap);
+                       &q->q_usage_counter, altmap);
        pmem->pfn_flags |= PFN_MAP;
        if (IS_ERR(pmem->virt_addr)) {
                rc = PTR_ERR(pmem->virt_addr);
@@ -446,19 +452,22 @@ static int nd_pmem_probe(struct device *dev)
                return -ENOMEM;
        nvdimm_namespace_add_poison(ndns, &pmem->bb, 0);
 
-       if (is_nd_btt(dev))
+       if (is_nd_btt(dev)) {
+               /* btt allocates its own request_queue */
+               blk_cleanup_queue(pmem->pmem_queue);
+               pmem->pmem_queue = NULL;
                return nvdimm_namespace_attach_btt(ndns);
+       }
 
        if (is_nd_pfn(dev))
                return nvdimm_namespace_attach_pfn(ndns);
 
-       if (nd_btt_probe(ndns, pmem) == 0) {
-               /* we'll come back as btt-pmem */
-               return -ENXIO;
-       }
-
-       if (nd_pfn_probe(ndns, pmem) == 0) {
-               /* we'll come back as pfn-pmem */
+       if (nd_btt_probe(ndns, pmem) == 0 || nd_pfn_probe(ndns, pmem) == 0) {
+               /*
+                * We'll come back as either btt-pmem, or pfn-pmem, so
+                * drop the queue allocation for now.
+                */
+               blk_cleanup_queue(pmem->pmem_queue);
                return -ENXIO;
        }
 
This page took 0.034749 seconds and 5 git commands to generate.