From: Kay Sievers <kay.sievers@vrfy.org>
To: linux-kernel@vger.kernel.org
Cc: Greg KH <greg@kroah.com>
Subject: [PATCH ] add "bus" symlink to class/block devices
Date: Tue, 15 Feb 2005 21:53:44 +0100 [thread overview]
Message-ID: <20050215205344.GA1207@vrfy.org> (raw)
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
Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
===== drivers/base/class.c 1.58 vs edited =====
--- 1.58/drivers/base/class.c 2005-02-05 19:35:12 +01:00
+++ edited/drivers/base/class.c 2005-02-15 21:31:06 +01:00
@@ -196,33 +196,33 @@ void class_device_remove_bin_file(struct
sysfs_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_device
class_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_devic
up_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 =====
--- 1.129/fs/partitions/check.c 2005-01-31 07:33:40 +01:00
+++ edited/fs/partitions/check.c 2005-02-15 21:14:43 +01:00
@@ -318,6 +318,8 @@ static void disk_sysfs_symlinks(struct g
struct 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);
}
next reply other threads:[~2005-02-15 20:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-15 20:53 Kay Sievers [this message]
2005-02-15 22:04 ` [PATCH] add "bus" symlink to class/block devices Kay Sievers
2005-02-15 22:25 ` Dmitry Torokhov
2005-02-15 23:44 ` Greg KH
2005-02-16 3:18 ` Dmitry Torokhov
2005-02-17 21:35 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050215205344.GA1207@vrfy.org \
--to=kay.sievers@vrfy.org \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.