Skip to contentSkip to conversation

"block" symlink in sysfs for a multifunction device

DISCUSSION Pete Zaitcev 5 participants 11 messages Dec 12, 2005 – Dec 15, 2005

lore
Share & tools
lore
#0 lore raw

Hi, Greg,

When I plug a USB card reader with multiply LUNs, the following happens:

[zaitcev@niphredil ~]$ ls -l /sys/devices/pci0000:00/0000:00:07.2/usb1/1-2/1-2:1.0 total 0
-r--r--r-- 1 root root 4096 Dec 12 12:47 bAlternateSetting
-r--r--r-- 1 root root 4096 Dec 12 12:46 bInterfaceClass
-r--r--r-- 1 root root 4096 Dec 12 12:46 bInterfaceNumber
-r--r--r-- 1 root root 4096 Dec 12 12:46 bInterfaceProtocol -r--r--r-- 1 root root 4096 Dec 12 12:46 bInterfaceSubClass

lrwxrwxrwx 1 root root    0 Dec 12 12:47 block -> ../../../../../../block/ubd
lrwxrwxrwx 1 root root    0 Dec 12 12:47 block -> ../../../../../../block/ubd
lrwxrwxrwx 1 root root    0 Dec 12 12:47 block -> ../../../../../../block/ubd
lrwxrwxrwx 1 root root    0 Dec 12 12:47 block -> ../../../../../../block/ubd

-r--r--r-- 1 root root 4096 Dec 12 12:46 bNumEndpoints
lrwxrwxrwx 1 root root 0 Dec 12 12:46 bus -> ../../../../../../bus/usb
-r--r--r-- 1 root root 4096 Dec 12 12:47 diag
lrwxrwxrwx 1 root root 0 Dec 12 12:46 driver -> ../../../../../../bus/usb/drivers/ub
-r--r--r-- 1 root root 4096 Dec 12 12:46 modalias
drwxr-xr-x 2 root root 0 Dec 12 12:46 power
[zaitcev@niphredil ~]$ cat /proc/version
Linux version 2.6.14-nip (zaitcev@niphredil) (gcc version 4.0.2 20051109 (Red Hat 4.0.2-6)) #5 Tue Dec 6 23:10:53 PST 2005 [zaitcev@niphredil ~]$

The usb-storage produces this:

[root@niphredil linux-2.6.14-nip]# find /sys -name block
/sys/block
/sys/devices/pci0000:00/0000:00:07.2/usb1/1-2/1-2:1.0/host0/target0:0:0/0:0:0:3/block /sys/devices/pci0000:00/0000:00:07.2/usb1/1-2/1-2:1.0/host0/target0:0:0/0:0:0:2/block /sys/devices/pci0000:00/0000:00:07.2/usb1/1-2/1-2:1.0/host0/target0:0:0/0:0:0:1/block /sys/devices/pci0000:00/0000:00:07.2/usb1/1-2/1-2:1.0/host0/target0:0:0/0:0:0:0/block /sys/devices/pci0000:00/0000:00:07.1/ide0/0.0/block
[root@niphredil linux-2.6.14-nip]# ls -l /sys/devices/pci0000:00/0000:00:07.2/usb1/1-2/1-2:1.0/host0/target0:0:0/0:0:0:0/block lrwxrwxrwx 1 root root 0 Dec 12 13:44 /sys/devices/pci0000:00/0000:00:07.2/usb1/1-2/1-2:1.0/host0/target0:0:0/0:0:0:0/block -> ../../../../../../../../../block/sda [root@niphredil linux-2.6.14-nip]#

Each "block" is in its own subdirectory.

Do you have a suggestion about the fastest way to accomplish the same effect with ub?

Thank you,
-- Pete

#1 lore raw
Quoted 2 lines · Pete Zaitcev

Do you have a suggestion about the fastest way to accomplish the same effect with ub?

Note: same thing happens with floppy if you have two floppy drives connected to the controller. You end up with two "block" symlinks.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#2 lore raw
In reply to Pete Zaitcev
Quoted 22 lines · Pete Zaitcev

Hi, Greg,

When I plug a USB card reader with multiply LUNs, the following happens:

[zaitcev@niphredil ~]$ ls -l /sys/devices/pci0000:00/0000:00:07.2/usb1/1-2/1-2:1.0 total 0

(quoted diff) +0 -5
-r--r--r-- 1 root root 4096 Dec 12 12:47 bAlternateSetting
-r--r--r-- 1 root root 4096 Dec 12 12:46 bInterfaceClass
-r--r--r-- 1 root root 4096 Dec 12 12:46 bInterfaceNumber
-r--r--r-- 1 root root 4096 Dec 12 12:46 bInterfaceProtocol
-r--r--r-- 1 root root 4096 Dec 12 12:46 bInterfaceSubClass
lrwxrwxrwx 1 root root    0 Dec 12 12:47 block -> ../../../../../../block/ubd
lrwxrwxrwx 1 root root    0 Dec 12 12:47 block -> ../../../../../../block/ubd
lrwxrwxrwx 1 root root    0 Dec 12 12:47 block -> ../../../../../../block/ubd
lrwxrwxrwx 1 root root    0 Dec 12 12:47 block -> ../../../../../../block/ubd

-r--r--r-- 1 root root 4096 Dec 12 12:46 bNumEndpoints
lrwxrwxrwx 1 root root 0 Dec 12 12:46 bus -> ../../../../../../bus/usb
-r--r--r-- 1 root root 4096 Dec 12 12:47 diag
lrwxrwxrwx 1 root root 0 Dec 12 12:46 driver -> ../../../../../../bus/usb/drivers/ub
-r--r--r-- 1 root root 4096 Dec 12 12:46 modalias
drwxr-xr-x 2 root root 0 Dec 12 12:46 power

Quoted 2 lines

Do you have a suggestion about the fastest way to accomplish the same effect with ub?

Ick, you are right, sorry about this. We changed the class code to add the class device name to the symlink, because of this very problem. I forgot to convert the block code to do the same thing. Now, with the patch below my system looks like:

$ ls -l /sys/block/uba/device/
total 0
-r--r--r--  1 root root 4096 Dec 13 21:31 bAlternateSetting
-r--r--r--  1 root root 4096 Dec 13 21:31 bInterfaceClass
-r--r--r--  1 root root 4096 Dec 13 21:31 bInterfaceNumber
-r--r--r--  1 root root 4096 Dec 13 21:31 bInterfaceProtocol
-r--r--r--  1 root root 4096 Dec 13 21:31 bInterfaceSubClass
-r--r--r--  1 root root 4096 Dec 13 21:31 bNumEndpoints
lrwxrwxrwx  1 root root    0 Dec 13 21:31 block:uba -> ../../../../../../block/uba
lrwxrwxrwx  1 root root    0 Dec 13 21:31 block:ubb -> ../../../../../../block/ubb
lrwxrwxrwx  1 root root    0 Dec 13 21:31 block:ubc -> ../../../../../../block/ubc
lrwxrwxrwx  1 root root    0 Dec 13 21:31 block:ubd -> ../../../../../../block/ubd
lrwxrwxrwx  1 root root    0 Dec 13 13:28 bus -> ../../../../../../bus/usb
-r--r--r--  1 root root 4096 Dec 13 21:31 diag
lrwxrwxrwx  1 root root    0 Dec 13 21:31 driver -> ../../../../../../bus/usb/drivers/ub
drwxr-xr-x  2 root root    0 Dec 13 21:31 ep_02
drwxr-xr-x  2 root root    0 Dec 13 21:31 ep_82
-r--r--r--  1 root root 4096 Dec 13 21:31 modalias
drwxr-xr-x  2 root root    0 Dec 13 21:28 power
--w-------  1 root root 4096 Dec 13 21:28 uevent

This will also fix the problem for floppy devices, like Russell pointed out. Look good to you?

thanks,

greg k-h
-----------------

Quoted 1 line

From [email protected] Tue Dec 13 15:20:15 2005

Date: Tue, 13 Dec 2005 15:17:34 -0800
From: Greg Kroah-Hartman <[email protected]>
Subject: Driver core: Make block devices create the proper symlink name

Block devices need to add the block device name to the symlink they put in the device directory, otherwise multiple symlinks of the same name can be created. This matches the class system, which works the same way, we just forgot to convert block at the same time.

---
 fs/partitions/check.c |   27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
fs/partitions/check.c +25 -2
@@ -325,12 +325,31 @@ void add_partition(struct gendisk *disk,
 	disk->part[part-1] = p;
 }
 
+static char *make_block_name(struct gendisk *disk)
+{
+	char *name;
+	static char *block_str = "block:";
+	int size;
+
+	size = strlen(block_str) + strlen(disk->disk_name) + 1;
+	name = kmalloc(size, GFP_KERNEL);
+	if (!name)
+		return NULL;
+	strcpy(name, block_str);
+	strcat(name, disk->disk_name);
+	return name;
+}
+
 static void disk_sysfs_symlinks(struct gendisk *disk)
 {
 	struct device *target = get_device(disk->driverfs_dev);
 	if (target) {
+		char *disk_name = make_block_name(disk);
 		sysfs_create_link(&disk->kobj,&target->kobj,"device");
-		sysfs_create_link(&target->kobj,&disk->kobj,"block");
+		if (disk_name) {
+			sysfs_create_link(&target->kobj,&disk->kobj,disk_name);
+			kfree(disk_name);
+		}
 	}
 }
 
@@ -444,8 +463,12 @@ void del_gendisk(struct gendisk *disk)
 	disk->stamp = 0;
 
 	if (disk->driverfs_dev) {
+		char *disk_name = make_block_name(disk);
 		sysfs_remove_link(&disk->kobj, "device");
-		sysfs_remove_link(&disk->driverfs_dev->kobj, "block");
+		if (disk_name) {
+			sysfs_remove_link(&disk->driverfs_dev->kobj, disk_name);
+			kfree(disk_name);
+		}
 		put_device(disk->driverfs_dev);
 	}
 	ndevfs_remove(kobject_name(&disk->kobj));
#3 lore raw
Quoted 5 lines · Greg KH

-r--r--r-- 1 root root 4096 Dec 13 21:31 bNumEndpoints
lrwxrwxrwx 1 root root 0 Dec 13 21:31 block:uba -> ../../../../../../block/uba

This will also fix the problem for floppy devices, like Russell pointed out. Look good to you?

Poking installer people for an opinion now (they filed the bug).

-- Pete

#4 lore raw
In reply to Greg KH
Quoted 6 lines · Greg KH
$ ls -l /sys/block/uba/device/
-r--r--r--  1 root root 4096 Dec 13 21:31 bNumEndpoints
lrwxrwxrwx  1 root root    0 Dec 13 21:31 block:uba -> ../../../../../../block/uba
lrwxrwxrwx  1 root root    0 Dec 13 21:31 block:ubb -> ../../../../../../block/ubb
lrwxrwxrwx  1 root root    0 Dec 13 21:31 block:ubc -> ../../../../../../block/ubc
lrwxrwxrwx  1 root root    0 Dec 13 21:31 block:ubd -> ../../../../../../block/ubd

Greg, Jeremy is not happy about this.

Quoted 4 lines

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=175563
------- Additional Comments From [email protected] 2005-12-14 18:05 EST ------- Actually, this is problematic. It makes it so that the single device directory corresponds to more than one device which we can't handle with kudzu :-(

Sorry,
-- Pete

#5 lore raw
Quoted 15 lines · Pete Zaitcev
Quoted 6 lines · Greg KH
$ ls -l /sys/block/uba/device/
-r--r--r--  1 root root 4096 Dec 13 21:31 bNumEndpoints
lrwxrwxrwx  1 root root    0 Dec 13 21:31 block:uba -> ../../../../../../block/uba
lrwxrwxrwx  1 root root    0 Dec 13 21:31 block:ubb -> ../../../../../../block/ubb
lrwxrwxrwx  1 root root    0 Dec 13 21:31 block:ubc -> ../../../../../../block/ubc
lrwxrwxrwx  1 root root    0 Dec 13 21:31 block:ubd -> ../../../../../../block/ubd

Greg, Jeremy is not happy about this.

Quoted 4 lines

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=175563
------- Additional Comments From [email protected] 2005-12-14 18:05 EST ------- Actually, this is problematic. It makes it so that the single device directory corresponds to more than one device which we can't handle with kudzu :-(

Well, how do you handle it for class devices then?

And if this isn't acceptable, what would be?

Just because kudzu is messed up... :)

thanks,

greg k-h

#6 lore raw
Quoted 3 lines · Greg KH

And if this isn't acceptable, what would be?

Just because kudzu is messed up... :)

I thought maybe creating some struct kobject by hand for every LUN. This is undesirable mainly because I do not trust myself with handling struct kobject at all (currently I only use block device API and so I blame Jens every time there's a problem :-)). But if Jeremy cannot work around it, I would have to think about it - maybe as a Fedora-specific patch.

-- Pete

#7 lore raw
Quoted 4 lines · Pete Zaitcev
Quoted 2 lines · Greg KH

And if this isn't acceptable, what would be?

Quoted 8 lines
Quoted 1 line

Just because kudzu is messed up... :)

I thought maybe creating some struct kobject by hand for every LUN. This is undesirable mainly because I do not trust myself with handling struct kobject at all (currently I only use block device API and so I blame Jens every time there's a problem :-)). But if Jeremy cannot work around it, I would have to think about it - maybe as a Fedora-specific patch.

I don't understand, what exactly would you like to see in the block device's device directory? With this patch, we correctly point back to all of the different block devices controlled by this device.

I'm curious as to why kudzu even cares about this?

And, how does it handle things like mult-port serial devices, which have all of the multiple class device symlinks in one single device directory, just like this.

thanks,

greg k-h

#8 lore raw
Quoted 5 lines · Greg KH

I don't understand, what exactly would you like to see in the block device's device directory? With this patch, we correctly point back to all of the different block devices controlled by this device.

I'm curious as to why kudzu even cares about this?

Actually, it shouldn't be a problem.

Quoted 3 lines

And, how does it handle things like mult-port serial devices, which have all of the multiple class device symlinks in one single device directory, just like this.

Ignores them entirely, of course. (kudzu at this point is used solely in the installer.)

Bill

#9 lore raw
In reply to Greg KH
Quoted 9 lines · Greg KH
Quoted 8 lines · Pete Zaitcev
Quoted 6 lines · Greg KH
$ ls -l /sys/block/uba/device/
-r--r--r--  1 root root 4096 Dec 13 21:31 bNumEndpoints
lrwxrwxrwx  1 root root    0 Dec 13 21:31 block:uba -> ../../../../../../block/uba
lrwxrwxrwx  1 root root    0 Dec 13 21:31 block:ubb -> ../../../../../../block/ubb
lrwxrwxrwx  1 root root    0 Dec 13 21:31 block:ubc -> ../../../../../../block/ubc
lrwxrwxrwx  1 root root    0 Dec 13 21:31 block:ubd -> ../../../../../../block/ubd
Quoted 8 lines
Quoted 6 lines

Greg, Jeremy is not happy about this.

Quoted 4 lines

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=175563
------- Additional Comments From [email protected] 2005-12-14 18:05 EST ------- Actually, this is problematic. It makes it so that the single device directory corresponds to more than one device which we can't handle with kudzu :-(

Well, how do you handle it for class devices then?

We don't have any where we need to handle it at present.

Quoted 1 line

And if this isn't acceptable, what would be?

By going this route, it really feels like you're hacking around your own rule of a single value per file :-) Except that instead of having a file that I read five values from, it's five files with naming heuristics to get five values. Which is, in a lot of ways, worse.

I'd much rather see the fact that there are multiple devices be handled by having each device with its own unique directory. This then keeps all of the abstractions which currently exist.

Jeremy

#10 lore raw
Quoted 19 lines · Jeremy Katz
Quoted 9 lines · Greg KH
Quoted 8 lines · Pete Zaitcev
Quoted 6 lines · Greg KH
$ ls -l /sys/block/uba/device/
-r--r--r--  1 root root 4096 Dec 13 21:31 bNumEndpoints
lrwxrwxrwx  1 root root    0 Dec 13 21:31 block:uba -> ../../../../../../block/uba
lrwxrwxrwx  1 root root    0 Dec 13 21:31 block:ubb -> ../../../../../../block/ubb
lrwxrwxrwx  1 root root    0 Dec 13 21:31 block:ubc -> ../../../../../../block/ubc
lrwxrwxrwx  1 root root    0 Dec 13 21:31 block:ubd -> ../../../../../../block/ubd
Quoted 8 lines
Quoted 6 lines

Greg, Jeremy is not happy about this.

Quoted 4 lines

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=175563
------- Additional Comments From [email protected] 2005-12-14 18:05 EST ------- Actually, this is problematic. It makes it so that the single device directory corresponds to more than one device which we can't handle with kudzu :-(

Well, how do you handle it for class devices then?

Quoted 8 lines

We don't have any where we need to handle it at present.

Quoted 1 line

And if this isn't acceptable, what would be?

By going this route, it really feels like you're hacking around your own rule of a single value per file :-) Except that instead of having a file that I read five values from, it's five files with naming heuristics to get five values. Which is, in a lot of ways, worse.

What? These are symlinks, not files. Why would you want to read the name of the block device from a file and then go have to look that location up, instead of just following the symlink?

Quoted 3 lines

I'd much rather see the fact that there are multiple devices be handled by having each device with its own unique directory. This then keeps all of the abstractions which currently exist.

Those devices do have their own unique directory. Look at the pointer above :)

The point here is that multiple class devices and block devices can bind to a single "real device" in the system, and we need to handle that representation properly. We have had the symlink for a while now, and I just forgot to put the proper name on the block device one, to match up with the class device naming.

thanks,

greg k-h