Skip to contentSkip to conversation

patch sysfs-add-sys-dev-char-block-to-lookup-sysfs-path-by-major-minor.patch added to gregkh-2.6 tree

PATCH [email protected] 3 participants 3 messages Apr 28, 2008 – Apr 29, 2008 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

[email protected]

author Applied
#1 lore raw
In reply to a message not in the archive

This is a note to let you know that I've just added the patch titled

Subject: sysfs: add /sys/dev/{char,block} to lookup sysfs path by major:minor

to my gregkh-2.6 tree. Its filename is

sysfs-add-sys-dev-char-block-to-lookup-sysfs-path-by-major-minor.patch

This tree can be found at
http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/patches/

Quoted 1 line

From [email protected] Mon Apr 21 10:51:11 2008

From: Dan Williams <[email protected]>
Date: Mon, 21 Apr 2008 10:51:07 -0700
Subject: sysfs: add /sys/dev/{char,block} to lookup sysfs path by major:minor
To: Greg KH <[email protected]>, Andrew Morton <[email protected]>
Cc: linux-kernel <[email protected]>
Message-ID: <[email protected]>

From: Dan Williams <[email protected]>

Why?:
There are occasions where userspace would like to access sysfs attributes for a device but it may not know how sysfs has named the device or the path. For example what is the sysfs path for /dev/disk/by-id/ata-ST3160827AS_5MT004CK? With this change a call to stat(2) returns the major:minor then userspace can see that /sys/dev/block/8:32 links to /sys/block/sdc.

What are the alternatives?:
1/ Add an ioctl to return the path: Doable, but sysfs is meant to reduce
the need to proliferate ioctl interfaces into the kernel, so this seems counter productive.

2/ Use udev to create these symlinks: Also doable, but it adds a
udev dependency to utilities that might be running in a limited environment like an initramfs.

3/ Do a full-tree search of sysfs.

[[email protected]: fix duplicate registrations] [[email protected]: cleanup suggestions]

---
 Documentation/ABI/testing/sysfs-dev |   20 ++++++++
 Documentation/filesystems/sysfs.txt |    6 ++
 block/genhd.c                       |    5 +-
 drivers/base/class.c                |    4 +
 drivers/base/core.c                 |   83 +++++++++++++++++++++++++++++++++++-
 drivers/usb/core/devio.c            |    5 ++
 include/linux/device.h              |    3 +
 7 files changed, 124 insertions(+), 2 deletions(-)
block/genhd.c +4 -1
@@ -360,7 +360,10 @@ static struct kobject *base_probe(dev_t 
 
 static int __init genhd_device_init(void)
 {
-	int error = class_register(&block_class);
+	int error;
+
+	block_class.dev_kobj = sysfs_dev_block_kobj;
+	error = class_register(&block_class);
 	if (unlikely(error))
 		return error;
 	bdev_map = kobj_map_init(base_probe, &block_class_lock);
Documentation/ABI/testing/sysfs-dev new file +20 -0
@@ -0,0 +1,20 @@
+What:		/sys/dev
+Date:		April 2008
+KernelVersion:	2.6.26
+Contact:	Dan Williams <[email protected]>
+Description:	The /sys/dev tree provides a method to look up the sysfs
+		path for a device using the information returned from
+		stat(2).  There are two directories, 'block' and 'char',
+		beneath /sys/dev containing symbolic links with names of
+		the form "<major>:<minor>".  These links point to the
+		corresponding sysfs path for the given device.
+
+		Example:
+		$ readlink /sys/dev/block/8:32
+		../../block/sdc
+
+		Entries in /sys/dev/char and /sys/dev/block will be
+		dynamically created and destroyed as devices enter and
+		leave the system.
+
+Users:		mdadm <[email protected]>
Documentation/filesystems/sysfs.txt +6 -0
@@ -248,6 +248,7 @@ The top level sysfs directory looks like
 block/
 bus/
 class/
+dev/
 devices/
 firmware/
 net/
@@ -274,6 +275,11 @@ fs/ contains a directory for some filesy
 filesystem wanting to export attributes must create its own hierarchy
 below fs/ (see ./fuse.txt for an example).
 
+dev/ contains two directories char/ and block/. Inside these two
+directories there are symlinks named <major>:<minor>.  These symlinks
+point to the sysfs directory for the given device.  /sys/dev provides a
+quick way to lookup the sysfs interface for a device from the result of
+a stat(2) operation.
 
 More information can driver-model specific features can be found in
 Documentation/driver-model/. 
drivers/base/class.c +4 -0
@@ -149,6 +149,10 @@ int class_register(struct class *cls)
 	if (error)
 		return error;
 
+	/* set the default /sys/dev directory for devices of this class */
+	if (!cls->dev_kobj)
+		cls->dev_kobj = sysfs_dev_char_kobj;
+
 #if defined(CONFIG_SYSFS_DEPRECATED) && defined(CONFIG_BLOCK)
 	/* let the block class directory show up in the root of sysfs */
 	if (cls != &block_class)
drivers/base/core.c +82 -1

125 lines not on this page · raw message

drivers/usb/core/devio.c +5 -0
@@ -1748,6 +1748,11 @@ int __init usb_devio_init(void)
 		usb_classdev_class = NULL;
 		goto out;
 	}
+	/* devices of this class shadow the major:minor of their parent
+	 * device, so clear ->dev_kobj to prevent adding duplicate entries
+	 * to /sys/dev
+	 */
+	usb_classdev_class->dev_kobj = NULL;
 
 	usb_register_notify(&usbdev_nb);
 #endif
include/linux/device.h +3 -0
@@ -194,6 +194,7 @@ struct class {
 	struct semaphore	sem; /* locks children, devices, interfaces */
 	struct class_attribute		*class_attrs;
 	struct device_attribute		*dev_attrs;
+	struct kobject			*dev_kobj;
 
 	int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);
 
@@ -206,6 +207,8 @@ struct class {
 	struct pm_ops *pm;
 };
 
+extern struct kobject *sysfs_dev_block_kobj;
+extern struct kobject *sysfs_dev_char_kobj;
 extern int __must_check class_register(struct class *class);
 extern void class_unregister(struct class *class);
 extern int class_for_each_device(struct class *class, void *data,

Patches currently in gregkh-2.6 which might be from [email protected] are

driver-core/sysfs-add-sys-dev-char-block-to-lookup-sysfs-path-by-major-minor.patch

Reviewed-by
#2 lore raw
Quoted 5 lines · On 4/28/08, [email protected] <[email protected]> wrote:

This is a note to let you know that I've just added the patch titled

Subject: sysfs: add /sys/dev/{char,block} to lookup sysfs path by major:minor

Quoted 8 lines

to my gregkh-2.6 tree. Its filename is

sysfs-add-sys-dev-char-block-to-lookup-sysfs-path-by-major-minor.patch

+ char devt_str[15];
+
+ if (kobj) {
+ format_dev_t(devt_str, dev->devt);

This part is ugly, but is not the fault of the patch. The ill- considered interface for `format_dev_t' is something that probably noone wants to fix.

Otherwise, still OK with me.

(Is Reviewed-by not sticky?)

-sb

#3 lore raw

Re: patch sysfs-add-sys-dev-char-block-to-lookup-sysfs-path-by-major-minor.pat ch added to gregkh-2.6 tree

Quoted 10 lines · SL Baur
Quoted 8 lines · On 4/28/08, [email protected] <[email protected]> wrote:

This is a note to let you know that I've just added the patch titled

Subject: sysfs: add /sys/dev/{char,block} to lookup sysfs path by major:minor

to my gregkh-2.6 tree. Its filename is

sysfs-add-sys-dev-char-block-to-lookup-sysfs-path-by-major-minor.patch

Quoted 8 lines
Quoted 4 lines

+ char devt_str[15];
+
+ if (kobj) {
+ format_dev_t(devt_str, dev->devt);

This part is ugly, but is not the fault of the patch. The ill- considered interface for `format_dev_t' is something that probably noone wants to fix.

Why not? Patches are always welcome, it's not like that function is used in that many different places, should be a simple change...

Quoted 5 lines

Otherwise, still OK with me.

(Is Reviewed-by not sticky?)

Yes, it is, I'll add it to my version of the patch.

thanks,

greg k-h