Message ID | 4DBF3AE3.8060109@kernel.org (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
On Mon, 02 May 2011 16:14:43 -0700 Yinghai Lu <yinghai@kernel.org> wrote: > > After remove the device from /sys, we have to rescan all or > find out the bridge and access /sys../device/rescan there. > > this patch add /sys/.../pci_bus/.../rescan. So user can rescan more easy. > that is more clean and easy to understand. > > like after remove 0000:c4:00.0, you can rescan 0000:c4 directly. > > Signed-off-by: Yinghai Lu <yinghai@kernel.org> I like the idea, and agree that bus rescanning makes sense. Comments below. > =================================================================== > --- linux-2.6.orig/drivers/pci/bus.c > +++ linux-2.6/drivers/pci/bus.c > @@ -163,6 +163,12 @@ int pci_bus_add_child(struct pci_bus *bu > > bus->is_added = 1; > > +#ifdef CONFIG_HOTPLUG > + retval = device_create_file(&bus->dev, &dev_attr_rescan); > + if (retval) > + return retval; > +#endif > + > retval = device_create_file(&bus->dev, &dev_attr_cpuaffinity); > if (retval) > return retval; Can you make this a separate function with a !CONFIG_HOTPLUG version so we don't have an #ifdef inside this function? > Index: linux-2.6/drivers/pci/pci.h > =================================================================== > --- linux-2.6.orig/drivers/pci/pci.h > +++ linux-2.6/drivers/pci/pci.h > @@ -159,6 +159,7 @@ extern struct device_attribute pci_dev_a > extern struct device_attribute dev_attr_cpuaffinity; > extern struct device_attribute dev_attr_cpulistaffinity; > #ifdef CONFIG_HOTPLUG > +extern struct device_attribute dev_attr_rescan; > extern struct bus_attribute pci_bus_attrs[]; > #else > #define pci_bus_attrs NULL > Index: linux-2.6/drivers/pci/probe.c > =================================================================== > --- linux-2.6.orig/drivers/pci/probe.c > +++ linux-2.6/drivers/pci/probe.c > @@ -1471,6 +1471,11 @@ struct pci_bus * pci_create_bus(struct d > error = device_create_file(&b->dev, &dev_attr_cpuaffinity); > if (error) > goto dev_create_file_err; > +#ifdef CONFIG_HOTPLUG > + error = device_create_file(&b->dev, &dev_attr_rescan); > + if (error) > + goto dev_create_bus_rescan_err; > +#endif Same here. > > /* Create legacy_io and legacy_mem files for this bus */ > pci_create_legacy_files(b); > @@ -1481,6 +1486,10 @@ struct pci_bus * pci_create_bus(struct d > > return b; > > +#ifdef CONFIG_HOTPLUG > +dev_create_bus_rescan_err: > + device_remove_file(&b->dev, &dev_attr_cpuaffinity); > +#endif Without the ifdef above, this could be unconditional; it just won't be hit in the !CONFIG_HOTPLUG case. Thanks,
Index: linux-2.6/drivers/pci/pci-sysfs.c =================================================================== --- linux-2.6.orig/drivers/pci/pci-sysfs.c +++ linux-2.6/drivers/pci/pci-sysfs.c @@ -318,6 +318,27 @@ remove_store(struct device *dev, struct count = ret; return count; } + +static ssize_t +dev_bus_rescan_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long val; + struct pci_bus *bus = to_pci_bus(dev); + + if (strict_strtoul(buf, 0, &val) < 0) + return -EINVAL; + + if (val) { + mutex_lock(&pci_remove_rescan_mutex); + pci_rescan_bus(bus); + mutex_unlock(&pci_remove_rescan_mutex); + } + return count; +} + +DEVICE_ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, dev_bus_rescan_store); + #endif struct device_attribute pci_dev_attrs[] = { Index: linux-2.6/drivers/pci/bus.c =================================================================== --- linux-2.6.orig/drivers/pci/bus.c +++ linux-2.6/drivers/pci/bus.c @@ -163,6 +163,12 @@ int pci_bus_add_child(struct pci_bus *bu bus->is_added = 1; +#ifdef CONFIG_HOTPLUG + retval = device_create_file(&bus->dev, &dev_attr_rescan); + if (retval) + return retval; +#endif + retval = device_create_file(&bus->dev, &dev_attr_cpuaffinity); if (retval) return retval; Index: linux-2.6/drivers/pci/pci.h =================================================================== --- linux-2.6.orig/drivers/pci/pci.h +++ linux-2.6/drivers/pci/pci.h @@ -159,6 +159,7 @@ extern struct device_attribute pci_dev_a extern struct device_attribute dev_attr_cpuaffinity; extern struct device_attribute dev_attr_cpulistaffinity; #ifdef CONFIG_HOTPLUG +extern struct device_attribute dev_attr_rescan; extern struct bus_attribute pci_bus_attrs[]; #else #define pci_bus_attrs NULL Index: linux-2.6/drivers/pci/probe.c =================================================================== --- linux-2.6.orig/drivers/pci/probe.c +++ linux-2.6/drivers/pci/probe.c @@ -1471,6 +1471,11 @@ struct pci_bus * pci_create_bus(struct d error = device_create_file(&b->dev, &dev_attr_cpuaffinity); if (error) goto dev_create_file_err; +#ifdef CONFIG_HOTPLUG + error = device_create_file(&b->dev, &dev_attr_rescan); + if (error) + goto dev_create_bus_rescan_err; +#endif /* Create legacy_io and legacy_mem files for this bus */ pci_create_legacy_files(b); @@ -1481,6 +1486,10 @@ struct pci_bus * pci_create_bus(struct d return b; +#ifdef CONFIG_HOTPLUG +dev_create_bus_rescan_err: + device_remove_file(&b->dev, &dev_attr_cpuaffinity); +#endif dev_create_file_err: device_unregister(&b->dev); class_dev_reg_err: Index: linux-2.6/Documentation/ABI/testing/sysfs-bus-pci =================================================================== --- linux-2.6.orig/Documentation/ABI/testing/sysfs-bus-pci +++ linux-2.6/Documentation/ABI/testing/sysfs-bus-pci @@ -74,6 +74,15 @@ Description: hot-remove the PCI device and any of its children. Depends on CONFIG_HOTPLUG. +What: /sys/bus/pci/devices/.../pci_bus/.../rescan +Date: May 2011 +Contact: Linux PCI developers <linux-pci@vger.kernel.org> +Description: + Writing a non-zero value to this attribute will + force a rescan of the bus and all child buses, + and re-discover devices removed earlier from this + part of the device tree. Depends on CONFIG_HOTPLUG. + What: /sys/bus/pci/devices/.../rescan Date: January 2009 Contact: Linux PCI developers <linux-pci@vger.kernel.org>
After remove the device from /sys, we have to rescan all or find out the bridge and access /sys../device/rescan there. this patch add /sys/.../pci_bus/.../rescan. So user can rescan more easy. that is more clean and easy to understand. like after remove 0000:c4:00.0, you can rescan 0000:c4 directly. Signed-off-by: Yinghai Lu <yinghai@kernel.org> --- Documentation/ABI/testing/sysfs-bus-pci | 9 +++++++++ drivers/pci/bus.c | 6 ++++++ drivers/pci/pci-sysfs.c | 21 +++++++++++++++++++++ drivers/pci/pci.h | 1 + drivers/pci/probe.c | 9 +++++++++ 5 files changed, 46 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html