On 05/14/2011 07:35 AM, Greg KH wrote: > On Fri, May 13, 2011 at 07:03:48PM -0700, Yinghai Lu wrote: ... >> thought if it is with testing, we can remove it if need to. > > Unfortunatly, no, everything ends up under "testing". And as there are > tools that use this, how are you going to handle angry users that have > their systems suddenly broken? > how about only create rescan for pci bridges instead? like this [PATCH] PCI, sys: only create rescan under /sys/.../pci/devices/... for pci bridges Current code will create rescan for every pci device, that is not right. the device is already there, there is no reason to rescan it. So only have rescan for pci bridges. less confusing Need to add cond to be new member of device_attribute. device_add_attrs will check cond to see if need to create the attr. Also the rescan will rescan bridge's secondary bus instead of primary bus. Signed-off-by: Yinghai Lu <yinghai@xxxxxxxxxx> --- drivers/base/bus.c | 7 ++++++- drivers/pci/pci-sysfs.c | 16 ++++++++++++++-- include/linux/device.h | 1 + include/linux/sysfs.h | 7 +++++++ 4 files changed, 28 insertions(+), 3 deletions(-) Index: linux-2.6/drivers/base/bus.c =================================================================== --- linux-2.6.orig/drivers/base/bus.c +++ linux-2.6/drivers/base/bus.c @@ -419,7 +419,12 @@ static int device_add_attrs(struct bus_t return 0; for (i = 0; attr_name(bus->dev_attrs[i]); i++) { - error = device_create_file(dev, &bus->dev_attrs[i]); + struct device_attribute *attr; + + attr = &bus->dev_attrs[i]; + if (attr->cond && !attr->cond(dev, attr)) + continue; + error = device_create_file(dev, attr); if (error) { while (--i >= 0) device_remove_file(dev, &bus->dev_attrs[i]); 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 @@ -303,12 +303,23 @@ dev_rescan_store(struct device *dev, str if (val) { mutex_lock(&pci_remove_rescan_mutex); - pci_rescan_bus(pdev->bus); + pci_rescan_bus(pdev->subordinate); mutex_unlock(&pci_remove_rescan_mutex); } return count; } +static int +dev_rescan_cond(struct device *dev, struct device_attribute *attr) +{ + struct pci_dev *pdev = to_pci_dev(dev); + + if (pdev && pdev->subordinate) + return 1; + + return 0; +} + static void remove_callback(struct device *dev) { struct pci_dev *pdev = to_pci_dev(dev); @@ -380,7 +391,8 @@ struct device_attribute pci_dev_attrs[] __ATTR(msi_bus, 0644, msi_bus_show, msi_bus_store), #ifdef CONFIG_HOTPLUG __ATTR(remove, (S_IWUSR|S_IWGRP), NULL, remove_store), - __ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, dev_rescan_store), + __ATTR_COND(rescan, (S_IWUSR|S_IWGRP), NULL, dev_rescan_store, + dev_rescan_cond), #endif __ATTR_NULL, }; Index: linux-2.6/include/linux/device.h =================================================================== --- linux-2.6.orig/include/linux/device.h +++ linux-2.6/include/linux/device.h @@ -338,6 +338,7 @@ struct device_attribute { char *buf); ssize_t (*store)(struct device *dev, struct device_attribute *attr, const char *buf, size_t count); + int (*cond)(struct device *dev, struct device_attribute *attr); }; #define DEVICE_ATTR(_name, _mode, _show, _store) \ Index: linux-2.6/include/linux/sysfs.h =================================================================== --- linux-2.6.orig/include/linux/sysfs.h +++ linux-2.6/include/linux/sysfs.h @@ -73,6 +73,13 @@ struct attribute_group { .store = _store, \ } +#define __ATTR_COND(_name, _mode, _show, _store, _cond) { \ + .attr = {.name = __stringify(_name), .mode = _mode }, \ + .show = _show, \ + .store = _store, \ + .cond = _cond, \ +} + #define __ATTR_RO(_name) { \ .attr = { .name = __stringify(_name), .mode = 0444 }, \ .show = _name##_show, \ -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html