diff mbox

[-v2,1/3] pci: add rescan to /sys/.../pci_bus/.../

Message ID 4DC89BCE.9070604@kernel.org (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Yinghai Lu May 10, 2011, 1:58 a.m. UTC
On 05/09/2011 03:44 PM, Greg KH wrote:
> On Mon, May 09, 2011 at 03:34:25PM -0700, Yinghai Lu wrote:
>> [PATCH -v2 1/3] pci: add rescan to /sys/.../pci_bus/.../
>>
...
>> +DEVICE_ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, dev_bus_rescan_store);
>> +
>> +int pci_bus_create_rescan_file(struct pci_bus *bus)
>> +{
>> +	return device_create_file(&bus->dev, &dev_attr_rescan);
>> +}
>> +
>> +void pci_bus_remove_rescan_file(struct pci_bus *bus)
>> +{
>> +	device_remove_file(&bus->dev, &dev_attr_rescan);
>> +}
> 
> No, please make it part of the attribute for this device type, otherwise
> you will race with userspace trying to create the file after it has been
> announced that the device is present.
> 

Thanks please check.

[PATCH -v3 1/3] pci: add rescan to /sys/.../pci_bus/.../

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.

-v2: According to Jesse, use function instead of exposing attr, so could hide
	#ifdef in header file.
     also add code to remove rescan file in remove path.
-v3: GregKH pointed out that we should use dev_attrs to avoid racing.
     So add pcibus_attrs and make it to be member of pcibus_attrs.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 Documentation/ABI/testing/sysfs-bus-pci |    9 +++++++++
 drivers/pci/pci-sysfs.c                 |   26 ++++++++++++++++++++++++++
 drivers/pci/pci.h                       |    2 ++
 drivers/pci/probe.c                     |    1 +
 4 files changed, 38 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

Comments

Greg KH May 10, 2011, 5:06 p.m. UTC | #1
On Mon, May 09, 2011 at 06:58:38PM -0700, Yinghai Lu wrote:
> --- linux-2.6.orig/drivers/pci/pci.h
> +++ linux-2.6/drivers/pci/pci.h
> @@ -160,8 +160,10 @@ extern struct device_attribute dev_attr_
>  extern struct device_attribute dev_attr_cpulistaffinity;
>  #ifdef CONFIG_HOTPLUG
>  extern struct bus_attribute pci_bus_attrs[];
> +extern struct device_attribute pcibus_attrs[];
>  #else
>  #define pci_bus_attrs	NULL
> +#define pcibus_attrs	NULL

That's a horrible name, it's not obvious what the difference is between
those two variables, right?

Please pick something different for the new one, "pcibus_dev_attrs"
perhaps?

Other than that, yes, that is the correct idea.  Please also move the
existing sysfs files for this device to your attribute list as well.

thanks,

greg k-h
--
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
diff mbox

Patch

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>
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,25 @@  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;
+}
+
 #endif
 
 struct device_attribute pci_dev_attrs[] = {
@@ -346,6 +365,13 @@  struct device_attribute pci_dev_attrs[]
 #endif
 	__ATTR_NULL,
 };
+
+struct device_attribute pcibus_attrs[] = {
+#ifdef CONFIG_HOTPLUG
+	__ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, dev_bus_rescan_store),
+#endif
+	__ATTR_NULL,
+};
 
 static ssize_t
 boot_vga_show(struct device *dev, struct device_attribute *attr, char *buf)
Index: linux-2.6/drivers/pci/pci.h
===================================================================
--- linux-2.6.orig/drivers/pci/pci.h
+++ linux-2.6/drivers/pci/pci.h
@@ -160,8 +160,10 @@  extern struct device_attribute dev_attr_
 extern struct device_attribute dev_attr_cpulistaffinity;
 #ifdef CONFIG_HOTPLUG
 extern struct bus_attribute pci_bus_attrs[];
+extern struct device_attribute pcibus_attrs[];
 #else
 #define pci_bus_attrs	NULL
+#define pcibus_attrs	NULL
 #endif
 
 
Index: linux-2.6/drivers/pci/probe.c
===================================================================
--- linux-2.6.orig/drivers/pci/probe.c
+++ linux-2.6/drivers/pci/probe.c
@@ -95,6 +95,7 @@  static void release_pcibus_dev(struct de
 static struct class pcibus_class = {
 	.name		= "pci_bus",
 	.dev_release	= &release_pcibus_dev,
+	.dev_attrs	= pcibus_attrs,
 };
 
 static int __init pcibus_class_init(void)