2005-12-12 21:49:23

by Pete Zaitcev

[permalink] [raw]
Subject: "block" symlink in sysfs for a multifunction device

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


2005-12-12 21:53:10

by Russell King

[permalink] [raw]
Subject: Re: "block" symlink in sysfs for a multifunction device

On Mon, Dec 12, 2005 at 01:49:04PM -0800, Pete Zaitcev wrote:
> 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.

--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 Serial core

2005-12-14 05:50:38

by Greg KH

[permalink] [raw]
Subject: Re: "block" symlink in sysfs for a multifunction device

On Mon, Dec 12, 2005 at 01:49:04PM -0800, Pete Zaitcev wrote:
> 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

> 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
-----------------

>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.


Cc: Pete Zaitcev <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>

---
fs/partitions/check.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)

--- gregkh-2.6.orig/fs/partitions/check.c
+++ gregkh-2.6/fs/partitions/check.c
@@ -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));

2005-12-14 06:58:24

by Pete Zaitcev

[permalink] [raw]
Subject: Re: "block" symlink in sysfs for a multifunction device

On Tue, 13 Dec 2005 21:50:19 -0800, Greg KH <[email protected]> wrote:

> -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

2005-12-14 23:26:34

by Pete Zaitcev

[permalink] [raw]
Subject: Re: "block" symlink in sysfs for a multifunction device

On Tue, 13 Dec 2005 21:50:19 -0800, Greg KH <[email protected]> wrote:

> $ 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.

> 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

2005-12-14 23:43:20

by Greg KH

[permalink] [raw]
Subject: Re: "block" symlink in sysfs for a multifunction device

On Wed, Dec 14, 2005 at 03:26:15PM -0800, Pete Zaitcev wrote:
> On Tue, 13 Dec 2005 21:50:19 -0800, Greg KH <[email protected]> wrote:
>
> > $ 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.
>
> > 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

2005-12-15 00:10:40

by Pete Zaitcev

[permalink] [raw]
Subject: Re: "block" symlink in sysfs for a multifunction device

On Wed, 14 Dec 2005 15:42:55 -0800, Greg KH <[email protected]> wrote:

> 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

2005-12-15 00:45:11

by Greg KH

[permalink] [raw]
Subject: Re: "block" symlink in sysfs for a multifunction device

On Wed, Dec 14, 2005 at 04:10:18PM -0800, Pete Zaitcev wrote:
> On Wed, 14 Dec 2005 15:42:55 -0800, Greg KH <[email protected]> wrote:
>
> > 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.

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

2005-12-15 02:47:17

by Bill Nottingham

[permalink] [raw]
Subject: Re: "block" symlink in sysfs for a multifunction device

Greg KH ([email protected]) said:
> 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.

> 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

2005-12-15 04:47:41

by Jeremy Katz

[permalink] [raw]
Subject: Re: "block" symlink in sysfs for a multifunction device

On Wed, 2005-12-14 at 15:42 -0800, Greg KH wrote:
> On Wed, Dec 14, 2005 at 03:26:15PM -0800, Pete Zaitcev wrote:
> > On Tue, 13 Dec 2005 21:50:19 -0800, Greg KH <[email protected]> wrote:
> > > $ 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.
> >
> > > 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.

> 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

2005-12-15 16:54:27

by Greg KH

[permalink] [raw]
Subject: Re: "block" symlink in sysfs for a multifunction device

On Wed, Dec 14, 2005 at 11:47:35PM -0500, Jeremy Katz wrote:
> On Wed, 2005-12-14 at 15:42 -0800, Greg KH wrote:
> > On Wed, Dec 14, 2005 at 03:26:15PM -0800, Pete Zaitcev wrote:
> > > On Tue, 13 Dec 2005 21:50:19 -0800, Greg KH <[email protected]> wrote:
> > > > $ 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.
> > >
> > > > 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.
>
> > 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?

> 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