lkml.org 
[lkml]   [2005]   [Dec]   [14]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
DateTue, 13 Dec 2005 21:50:19 -0800
FromGreg KH <>
SubjectRe: "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 foo@baz.org Tue Dec 13 15:20:15 2005
Date: Tue, 13 Dec 2005 15:17:34 -0800
From: Greg Kroah-Hartman <gregkh@suse.de>
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 <zaitcev@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
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));
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-12-14 06:53    [from the cache]
©2003-2009