aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2017-07-18 20:49:14 -0400
committerDan Williams <dan.j.williams@intel.com>2017-07-18 20:49:14 -0400
commitbbb3be170ac2891526ad07b18af7db226879a8e7 (patch)
tree2f946ec4b9af0380e9949f57f41ccf347e31f782
parent23b9babb50ff5ac8eb9208b978b2a630e99bf90b (diff)
device-dax: fix sysfs duplicate warnings
Fix warnings of the form... WARNING: CPU: 10 PID: 4983 at fs/sysfs/dir.c:31 sysfs_warn_dup+0x62/0x80 sysfs: cannot create duplicate filename '/class/dax/dax12.0' Call Trace: dump_stack+0x63/0x86 __warn+0xcb/0xf0 warn_slowpath_fmt+0x5a/0x80 ? kernfs_path_from_node+0x4f/0x60 sysfs_warn_dup+0x62/0x80 sysfs_do_create_link_sd.isra.2+0x97/0xb0 sysfs_create_link+0x25/0x40 device_add+0x266/0x630 devm_create_dax_dev+0x2cf/0x340 [dax] dax_pmem_probe+0x1f5/0x26e [dax_pmem] nvdimm_bus_probe+0x71/0x120 ...by reusing the namespace id for the device-dax instance name. Now that we have decided that there will never by more than one device-dax instance per libnvdimm-namespace parent device [1], we can directly reuse the namepace ids. There are some possible follow-on cleanups, but those are saved for a later patch to simplify the -stable backport. [1]: https://lists.01.org/pipermail/linux-nvdimm/2016-December/008266.html Fixes: 98a29c39dc68 ("libnvdimm, namespace: allow creation of multiple pmem...") Cc: Jeff Moyer <jmoyer@redhat.com> Cc: <stable@vger.kernel.org> Reported-by: Dariusz Dokupil <dariusz.dokupil@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
-rw-r--r--drivers/dax/device-dax.h2
-rw-r--r--drivers/dax/device.c24
-rw-r--r--drivers/dax/pmem.c12
3 files changed, 24 insertions, 14 deletions
diff --git a/drivers/dax/device-dax.h b/drivers/dax/device-dax.h
index fdcd9769ffde..688b051750bd 100644
--- a/drivers/dax/device-dax.h
+++ b/drivers/dax/device-dax.h
@@ -21,5 +21,5 @@ struct dax_region *alloc_dax_region(struct device *parent,
21 int region_id, struct resource *res, unsigned int align, 21 int region_id, struct resource *res, unsigned int align,
22 void *addr, unsigned long flags); 22 void *addr, unsigned long flags);
23struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region, 23struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region,
24 struct resource *res, int count); 24 int id, struct resource *res, int count);
25#endif /* __DEVICE_DAX_H__ */ 25#endif /* __DEVICE_DAX_H__ */
diff --git a/drivers/dax/device.c b/drivers/dax/device.c
index 44d72e5e64cc..e9f3b3e4bbf4 100644
--- a/drivers/dax/device.c
+++ b/drivers/dax/device.c
@@ -529,7 +529,8 @@ static void dev_dax_release(struct device *dev)
529 struct dax_region *dax_region = dev_dax->region; 529 struct dax_region *dax_region = dev_dax->region;
530 struct dax_device *dax_dev = dev_dax->dax_dev; 530 struct dax_device *dax_dev = dev_dax->dax_dev;
531 531
532 ida_simple_remove(&dax_region->ida, dev_dax->id); 532 if (dev_dax->id >= 0)
533 ida_simple_remove(&dax_region->ida, dev_dax->id);
533 dax_region_put(dax_region); 534 dax_region_put(dax_region);
534 put_dax(dax_dev); 535 put_dax(dax_dev);
535 kfree(dev_dax); 536 kfree(dev_dax);
@@ -559,7 +560,7 @@ static void unregister_dev_dax(void *dev)
559} 560}
560 561
561struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region, 562struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region,
562 struct resource *res, int count) 563 int id, struct resource *res, int count)
563{ 564{
564 struct device *parent = dax_region->dev; 565 struct device *parent = dax_region->dev;
565 struct dax_device *dax_dev; 566 struct dax_device *dax_dev;
@@ -590,10 +591,16 @@ struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region,
590 if (i < count) 591 if (i < count)
591 goto err_id; 592 goto err_id;
592 593
593 dev_dax->id = ida_simple_get(&dax_region->ida, 0, 0, GFP_KERNEL); 594 if (id < 0) {
594 if (dev_dax->id < 0) { 595 id = ida_simple_get(&dax_region->ida, 0, 0, GFP_KERNEL);
595 rc = dev_dax->id; 596 dev_dax->id = id;
596 goto err_id; 597 if (id < 0) {
598 rc = id;
599 goto err_id;
600 }
601 } else {
602 /* region provider owns @id lifetime */
603 dev_dax->id = -1;
597 } 604 }
598 605
599 /* 606 /*
@@ -625,7 +632,7 @@ struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region,
625 dev->parent = parent; 632 dev->parent = parent;
626 dev->groups = dax_attribute_groups; 633 dev->groups = dax_attribute_groups;
627 dev->release = dev_dax_release; 634 dev->release = dev_dax_release;
628 dev_set_name(dev, "dax%d.%d", dax_region->id, dev_dax->id); 635 dev_set_name(dev, "dax%d.%d", dax_region->id, id);
629 636
630 rc = cdev_device_add(cdev, dev); 637 rc = cdev_device_add(cdev, dev);
631 if (rc) { 638 if (rc) {
@@ -641,7 +648,8 @@ struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region,
641 return dev_dax; 648 return dev_dax;
642 649
643 err_dax: 650 err_dax:
644 ida_simple_remove(&dax_region->ida, dev_dax->id); 651 if (dev_dax->id >= 0)
652 ida_simple_remove(&dax_region->ida, dev_dax->id);
645 err_id: 653 err_id:
646 kfree(dev_dax); 654 kfree(dev_dax);
647 655
diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c
index 9f2a0b4fd801..8d8c852ba8f2 100644
--- a/drivers/dax/pmem.c
+++ b/drivers/dax/pmem.c
@@ -58,13 +58,12 @@ static void dax_pmem_percpu_kill(void *data)
58 58
59static int dax_pmem_probe(struct device *dev) 59static int dax_pmem_probe(struct device *dev)
60{ 60{
61 int rc;
62 void *addr; 61 void *addr;
63 struct resource res; 62 struct resource res;
63 int rc, id, region_id;
64 struct nd_pfn_sb *pfn_sb; 64 struct nd_pfn_sb *pfn_sb;
65 struct dev_dax *dev_dax; 65 struct dev_dax *dev_dax;
66 struct dax_pmem *dax_pmem; 66 struct dax_pmem *dax_pmem;
67 struct nd_region *nd_region;
68 struct nd_namespace_io *nsio; 67 struct nd_namespace_io *nsio;
69 struct dax_region *dax_region; 68 struct dax_region *dax_region;
70 struct nd_namespace_common *ndns; 69 struct nd_namespace_common *ndns;
@@ -123,14 +122,17 @@ static int dax_pmem_probe(struct device *dev)
123 /* adjust the dax_region resource to the start of data */ 122 /* adjust the dax_region resource to the start of data */
124 res.start += le64_to_cpu(pfn_sb->dataoff); 123 res.start += le64_to_cpu(pfn_sb->dataoff);
125 124
126 nd_region = to_nd_region(dev->parent); 125 rc = sscanf(dev_name(&ndns->dev), "namespace%d.%d", &region_id, &id);
127 dax_region = alloc_dax_region(dev, nd_region->id, &res, 126 if (rc != 2)
127 return -EINVAL;
128
129 dax_region = alloc_dax_region(dev, region_id, &res,
128 le32_to_cpu(pfn_sb->align), addr, PFN_DEV|PFN_MAP); 130 le32_to_cpu(pfn_sb->align), addr, PFN_DEV|PFN_MAP);
129 if (!dax_region) 131 if (!dax_region)
130 return -ENOMEM; 132 return -ENOMEM;
131 133
132 /* TODO: support for subdividing a dax region... */ 134 /* TODO: support for subdividing a dax region... */
133 dev_dax = devm_create_dev_dax(dax_region, &res, 1); 135 dev_dax = devm_create_dev_dax(dax_region, id, &res, 1);
134 136
135 /* child dev_dax instances now own the lifetime of the dax_region */ 137 /* child dev_dax instances now own the lifetime of the dax_region */
136 dax_region_put(dax_region); 138 dax_region_put(dax_region);