add "bus" symlink to class/block devices
PATCH 1/1 add "bus" symlink to class/block devices
Add a "bus" symlink to the class and block devices, just like the "driver" and "device" links. This may be a huge speed gain for e.g. udev to determine the bus value of a device, as we currently need to do a brute-force scan in /sys/bus/* to find this value.
/sys
|-- block | |-- fd0 | | |-- bus -> ../../bus/platform | | |-- dev | | |-- device -> ../../devices/platform/floppy0 | | |-- queue | | | |-- iosched
|-- class | |-- net | | |-- eth0 | | | |-- addr_len | | | |-- address | | | |-- broadcast | | | |-- bus -> ../../../bus/pci | | | |-- carrier ... | | |-- ttyS0 | | | |-- bus -> ../../../bus/pnp | | | |-- dev | | | |-- device -> ../../../devices/pnp0/00:09 | | | `-- driver -> ../../../bus/pnp/drivers/serial ... | |-- sound | | |-- controlC0 | | | |-- bus -> ../../../bus/pci | | | |-- dev | | | |-- device -> ../../../devices/pci0000:00/0000:00:1f.5 | | | `-- driver -> ../../../bus/pci/drivers/Intel ICH
===== drivers/base/class.c 1.58 vs edited =====
drivers/base/class.c +20 -22
@@ -196,33 +196,33 @@ void class_device_remove_bin_file(structsysfs_remove_bin_file (&class_dev->kobj, attr); } -static int class_device_dev_link (struct class_device * class_dev) +static void class_device_add_dev_symlinks (struct class_device *class_dev) { -if (class_dev->dev) -return sysfs_create_link (&class_dev->kobj, - &class_dev->dev->kobj,"device" ); -return 0 ; -} +if (!class_dev->dev) +return 0 ; -static void class_device_dev_unlink (struct class_device * class_dev) -{ -sysfs_remove_link (&class_dev->kobj,"device" ); -} +sysfs_create_link (&class_dev->kobj, &class_dev->dev->kobj,"device" ); -static int class_device_driver_link (struct class_device * class_dev) -{ -if ((class_dev->dev) && (class_dev->dev->driver)) -return sysfs_create_link (&class_dev->kobj, - &class_dev->dev->driver->kobj,"driver" ); -return 0 ; +if (class_dev->dev->driver) +sysfs_create_link (&class_dev->kobj, + &class_dev->dev->driver->kobj,"driver" ); + +if (class_dev->dev->bus) +sysfs_create_link (&class_dev->kobj, + &class_dev->dev->bus->subsys.kset.kobj, +"bus" ); } -static void class_device_driver_unlink (struct class_device * class_dev) +static void class_device_remove_dev_symlinks (struct class_device *class_dev) { +if (!class_dev->dev) +return 0 ; + +sysfs_remove_link (&class_dev->kobj,"device" );sysfs_remove_link (&class_dev->kobj,"driver" ); +sysfs_remove_link (&class_dev->kobj,"bus" ); } -static ssize_t class_device_attr_show (struct kobject * kobj,struct attribute * attr,char * buf)
@@ -452,8 +452,7 @@ int class_device_add(struct class_deviceclass_device_create_file (class_dev, &class_device_attr_dev);class_device_add_attrs (class_dev); -class_device_dev_link (class_dev); -class_device_driver_link (class_dev); +class_device_add_dev_symlinks (class_dev); register_done:if (error && parent)
@@ -482,8 +481,7 @@ void class_device_del(struct class_devicup_write (&parent->subsys.rwsem); } -class_device_dev_unlink (class_dev); -class_device_driver_unlink (class_dev); +class_device_remove_dev_symlinks (class_dev);class_device_remove_attrs (class_dev);kobject_del (&class_dev->kobj);
===== fs/partitions/check.c 1.129 vs edited =====
fs/partitions/check.c +3 -0
@@ -318,6 +318,8 @@ static void disk_sysfs_symlinks(struct gstruct device *target =get_device (disk->driverfs_dev);if (target) {sysfs_create_link (&disk->kobj,&target->kobj,"device" ); +if (target->bus) +sysfs_create_link (&disk->kobj,&target->bus->subsys.kset.kobj,"bus" );sysfs_create_link (&target->kobj,&disk->kobj,"block" ); } }
@@ -438,6 +440,7 @@ void del_gendisk(struct gendisk *disk)if (disk->driverfs_dev) {sysfs_remove_link (&disk->kobj,"device" ); +sysfs_remove_link (&disk->kobj,"bus" );sysfs_remove_link (&disk->driverfs_dev->kobj,"block" );put_device (disk->driverfs_dev); }
Quoted 4 lines · Kay Sievers
Add a "bus" symlink to the class and block devices, just like the "driver" and "device" links. This may be a huge speed gain for e.g. udev to determine the bus value of a device, as we currently need to do a brute-force scan in
/sys/bus/*to find this value.
Hmm, while playing around with it, I think we should create the "bus" link on the physical device on not on the class device.
Also the current "driver" link at the class device should be removed, cause class devices don't have a driver. Block devices never had this misleading symlink.
Quoted 1 line
From the class device we point with the "device" link to the physical
device, and only the physical device should have the "driver" and the "bus" link, as it represents the real relationship.
+++ edited/drivers/base/bus.c 2005-02-15 22:33:37 +01:00
@@ -465,6 +465,7 @@ int bus_add_device(struct device * dev)
up_write(&dev->bus->subsys.rwsem); device_add_attrs(bus, dev); sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id);
+ sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "bus");
}
return error;
}
@@ -481,6 +482,7 @@ int bus_add_device(struct device * dev)
void bus_remove_device(struct device * dev)
{
if (dev->bus) {
+ sysfs_remove_link(&dev->kobj, "bus");
sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id); device_remove_attrs(dev->bus, dev); down_write(&dev->bus->subsys.rwsem);
===== drivers/base/class.c 1.58 vs edited =====
drivers/base/class.c +5 -31
@@ -196,33 +196,6 @@ void class_device_remove_bin_file(structsysfs_remove_bin_file (&class_dev->kobj, attr); } -static int class_device_dev_link (struct class_device * class_dev) -{ -if (class_dev->dev) -return sysfs_create_link (&class_dev->kobj, - &class_dev->dev->kobj,"device" ); -return 0 ; -} - -static void class_device_dev_unlink (struct class_device * class_dev) -{ -sysfs_remove_link (&class_dev->kobj,"device" ); -} - -static int class_device_driver_link (struct class_device * class_dev) -{ -if ((class_dev->dev) && (class_dev->dev->driver)) -return sysfs_create_link (&class_dev->kobj, - &class_dev->dev->driver->kobj,"driver" ); -return 0 ; -} - -static void class_device_driver_unlink (struct class_device * class_dev) -{ -sysfs_remove_link (&class_dev->kobj,"driver" ); -} - -static ssize_t class_device_attr_show (struct kobject * kobj,struct attribute * attr,char * buf)
@@ -452,8 +425,9 @@ int class_device_add(struct class_deviceclass_device_create_file (class_dev, &class_device_attr_dev);class_device_add_attrs (class_dev); -class_device_dev_link (class_dev); -class_device_driver_link (class_dev); +if (class_dev->dev) +sysfs_create_link (&class_dev->kobj, + &class_dev->dev->kobj,"device" ); register_done:if (error && parent)
@@ -482,8 +456,8 @@ void class_device_del(struct class_devicup_write (&parent->subsys.rwsem); } -class_device_dev_unlink (class_dev); -class_device_driver_unlink (class_dev); +if (class_dev->dev) +sysfs_remove_link (&class_dev->kobj,"device" );class_device_remove_attrs (class_dev);kobject_del (&class_dev->kobj);
Quoted 4 lines · Kay Sievers
drivers/base/class.c +0
-3-static int class_device_dev_link (struct class_device * class_dev) -{ -if (class_dev->dev)
drivers/base/class.c void class_device_remove_bin_file(struct · line 211
Quoted 10 lines
drivers/base/class.c +0
-10-return sysfs_create_link (&class_dev->kobj, - &class_dev->dev->kobj,"device" ); -return 0 ; -} - -static void class_device_dev_unlink (struct class_device * class_dev) -{ -sysfs_remove_link (&class_dev->kobj,"device" ); -} -
Hi,
I can agree on dropping driver link but I think that the link to underlying real device is still needed.
Signature · 1 line
Dmitry
Quoted 18 lines · Dmitry Torokhov
Quoted 4 lines · Kay Sievers
drivers/base/class.c +0
-3-static int class_device_dev_link (struct class_device * class_dev) -{ -if (class_dev->dev)drivers/base/class.c void class_device_remove_bin_file(struct · line 211
Quoted 10 lines
drivers/base/class.c +0
-10-return sysfs_create_link (&class_dev->kobj, - &class_dev->dev->kobj,"device" ); -return 0 ; -} - -static void class_device_dev_unlink (struct class_device * class_dev) -{ -sysfs_remove_link (&class_dev->kobj,"device" ); -} -Hi,
Quoted 2 lines
I can agree on dropping driver link but I think that the link to underlying real device is still needed.
It's still there, read the patch :)
thanks,
greg k-h
Quoted 19 lines · Greg KH
Quoted 18 lines · Dmitry Torokhov
Quoted 4 lines · Kay Sievers
drivers/base/class.c +0
-3-static int class_device_dev_link (struct class_device * class_dev) -{ -if (class_dev->dev)drivers/base/class.c void class_device_remove_bin_file(struct · line 211
Quoted 10 lines
drivers/base/class.c +0
-10-return sysfs_create_link (&class_dev->kobj, - &class_dev->dev->kobj,"device" ); -return 0 ; -} - -static void class_device_dev_unlink (struct class_device * class_dev) -{ -sysfs_remove_link (&class_dev->kobj,"device" ); -} -Hi,
Quoted 5 lines
Quoted 2 lines
I can agree on dropping driver link but I think that the link to underlying real device is still needed.
It's still there, read the patch :)
Oops, missed that. Sorry.
Signature · 1 line
Dmitry
Greg KH
AppliedQuoted 9 lines · Kay Sievers
Quoted 4 lines · Kay Sievers
Add a "bus" symlink to the class and block devices, just like the "driver" and "device" links. This may be a huge speed gain for e.g. udev to determine the bus value of a device, as we currently need to do a brute-force scan in
/sys/bus/*to find this value.Hmm, while playing around with it, I think we should create the "bus" link on the physical device on not on the class device.
Quoted 7 lines
Also the current "driver" link at the class device should be removed, cause class devices don't have a driver. Block devices never had this misleading symlink.
Quoted 1 line
From the class device we point with the "device" link to the physical
device, and only the physical device should have the "driver" and the "bus" link, as it represents the real relationship.
Applied, thanks,
greg k-h