lkml.org 
[lkml]   [2011]   [Oct]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH 8/8] 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@kernel.org>

---
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);
@@ -383,7 +394,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
@@ -427,6 +427,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, \

\
 
 \ /
  Last update: 2011-10-16 03:35    [from the cache]
©2003-2011 Jasper Spaans