Skip to contentSkip to conversation

usb + sysfs + udev problems once more

DISCUSSION Andreas Jellinghaus 3 participants 6 messages Jun 27, 2007

lore
Share & tools
lore
#0 lore raw

I thought to try the latest ubuntu beta version to see if kernel + usb + sysfs + udev work as expected, but they don't. the kernel is 2.6.22-rc, udev is 111-0ubuntu5.

I'm posting here, as I guess this is not distribution specific.

the problem I see is this: when I plugin my usb smart card reader, I see a number of events using "udevmonitor --kernel --environment". of these I'm interested in these two:

UEVENT[1182947366.505829] add /devices/pci0000:00/0000:00:1d.2/usb3/3-1
(usb)
ACTION­d
DEVPATH=/devices/pci0000:00/0000:00:1d.2/usb3/3-1
SUBSYSTEM=usb
SEQNUM%49
MAJOR9
MINOR%8
DEVTYPE=usb_device
PHYSDEVBUS=usb
DEVICE=/proc/bus/usb/003/003
PRODUCTŽ6/3438/100
TYPE=0/0/0
BUSNUM3
DEVNUM3

and

UEVENT[1182947366.505908]
add /devices/pci0000:00/0000:00:1d.2/usb3/3-1/3-1:1.0 (usb)
ACTION­d DEVPATH=/devices/pci0000:00/0000:00:1d.2/usb3/3-1/3-1:1.0 SUBSYSTEM=usb
SEQNUM%51
DEVTYPE=usb_interface
PHYSDEVBUS=usb
INTERFACE/0/0 MODALIAS=usb:v08E6p3438d0100dc00dsc00dp00ic0Bisc00ip00

the first is nice, as it has the DEVICE info. I need that one. however, only the second is matched by the udev rule:
SYSFS{bInterfaceClass}="0b", SYSFS{bInterfaceSubClass}="00", SYSFS{bInterfaceProtocol}="00" RUN+="/lib/udev/openct_usb"

so in the end my script is called only once, but without DEVICE.

how do I fix this?

or is this a kernel / sysfs problem that cannot be worked around?

and is there any chance udev will create events
for the /dev/bus/usb/ device files it creates?

thanks for your help.

Regards, Andreas

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#1 lore raw
Quoted 47 lines · Andreas Jellinghaus

I thought to try the latest ubuntu beta version to see if kernel + usb + sysfs + udev work as expected, but they don't. the kernel is 2.6.22-rc, udev is 111-0ubuntu5.

I'm posting here, as I guess this is not distribution specific.

the problem I see is this: when I plugin my usb smart card reader, I see a number of events using "udevmonitor --kernel --environment". of these I'm interested in these two:

UEVENT[1182947366.505829] add /devices/pci0000:00/0000:00:1d.2/usb3/3-1
(usb)
ACTION­d
DEVPATH=/devices/pci0000:00/0000:00:1d.2/usb3/3-1
SUBSYSTEM=usb
SEQNUM%49
MAJOR9
MINOR%8
DEVTYPE=usb_device
PHYSDEVBUS=usb
DEVICE=/proc/bus/usb/003/003
PRODUCTŽ6/3438/100
TYPE=0/0/0
BUSNUM3
DEVNUM3

and

UEVENT[1182947366.505908]
add /devices/pci0000:00/0000:00:1d.2/usb3/3-1/3-1:1.0 (usb)
ACTION­d DEVPATH=/devices/pci0000:00/0000:00:1d.2/usb3/3-1/3-1:1.0 SUBSYSTEM=usb
SEQNUM%51
DEVTYPE=usb_interface
PHYSDEVBUS=usb
INTERFACE/0/0 MODALIAS=usb:v08E6p3438d0100dc00dsc00dp00ic0Bisc00ip00

the first is nice, as it has the DEVICE info. I need that one. however, only the second is matched by the udev rule:
SYSFS{bInterfaceClass}="0b", SYSFS{bInterfaceSubClass}="00", SYSFS{bInterfaceProtocol}="00" RUN+="/lib/udev/openct_usb"

Quoted 8 lines

so in the end my script is called only once, but without DEVICE.

how do I fix this?

or is this a kernel / sysfs problem that cannot be worked around?

and is there any chance udev will create events
for the /dev/bus/usb/ device files it creates?

The usb-interfaces (2nd event) do not have a device node. Only the usb-device itself, but you match on interface properties. There is no sane way for udev to match on an interface property and get the device node name at the same time. You run into unsolvable timing problems, or need to use weird hacks.

Also, usbfs proc device-nodes are not available on modern systems (can not support ACL's). Udev creates /dev/bus/usb/*/* nodes and libusb picks up the nodes from there, if the directory exists.

The kernel exports the devices nodes by the usb-device itself (2.6.22) or (for older kernels) by usb_device-class devices. But also with that setup, there is no convenient way to get interface properties to match against, and device node access at the same time with simple udev rules. There is support for all that in HAL, but not in udev.

The only reliable way for udev rules would be with kernel 2.6.22, not using usb_device class devices and not using proc usbfs. With such a setup, you could hook your RUN into the interface-event and the program/script can query the device-node name from the parent device of the interface.

Kay

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#2 lore raw
In reply to Andreas Jellinghaus

Am Mittwoch, 27. Juni 2007 16:35 schrieb Kay Sievers:

Quoted 5 lines

The usb-interfaces (2nd event) do not have a device node. Only the usb-device itself, but you match on interface properties. There is no sane way for udev to match on an interface property and get the device node name at the same time. You run into unsolvable timing problems, or need to use weird hacks.

if I remember correcty, with linux and hotplug this was possible, right? so linux+sysfs+udev is a regression from linux+hotplug? an unfixable?

also with 2.6.21.2 plus udev 093 on ubuntu edgy it works for me. is this a udev regression or kernel regression? why is there "no sane way" if it works with older software? sorry, I'm puzzled.

Quoted 3 lines

Also, usbfs proc device-nodes are not available on modern systems (can not support ACL's). Udev creates /dev/bus/usb/*/* nodes and libusb picks up the nodes from there, if the directory exists.

fine with me, how do I get udev to call me when a smart card reader is plugged in and pass the device name in some variable? smart card reader these days pretty much means CCID device, i.e. a device with 0b interface. could be a combo device like a keyboard with an intergrated reader, I will have a look at pick the right endpoint.

my last information was that there are no proper events for /dev/bus/usb nodes, such they are a regression, while they offer some new features, they also miss some older features.

Quoted 5 lines

The kernel exports the devices nodes by the usb-device itself (2.6.22) or (for older kernels) by usb_device-class devices. But also with that setup, there is no convenient way to get interface properties to match against, and device node access at the same time with simple udev rules. There is support for all that in HAL, but not in udev.

I never found any useful information how to plug into hal.
is there anyone who can convert
https://www.opensc-project.org/openct/browser/trunk/etc/openct.udev
into a hal config file? not that I'm eager to move to a new software which had no useful documentation the last time I looked at it. but maybe that changed? still it would be an extra dependency some people don't want.

also I wonder: two years ago with linux + hotplug I was fine. when exactly began this change that results in my application being broken? I thought linux had very strict requirements not to change the kernel/userland interface without proper announcement, migration plans and all that. but for usb/udev/hotplug/sysfs I can't remember any announcement mentioning incompatible kernel/userland changes.

Quoted 5 lines

The only reliable way for udev rules would be with kernel 2.6.22, not using usb_device class devices and not using proc usbfs. With such a setup, you could hook your RUN into the interface-event and the program/script can query the device-node name from the parent device of the interface.

you mean like this?

ls -d /sys/$DEVPATH/../usb_device* |xargs basename | sed -e "s/usb_device:usbdev//g" |sed -e "s/\./ /g" |xargs printf /dev/bus/usb/%03d/%03d\\n

i.e. from the $DEVPATH ("interface"?) I go to .. then look for usb_device:usbdev* files, which should be only one, get that name, strip "usb_device:usbdev" and split the remainder (e.g. 3.8) first into two numbers (3 8) and then format them into /dev/bus/usb/%03d/%03d (e.g. /dev/bus/usb/003/008).

is this ok? will it work on older kernel and future kernels as well? will it work with different versions of udev? could you think of any hardware where this would't work?

thanks for your help.

Regards, Andreas

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#3 lore raw
In reply to Andreas Jellinghaus
Quoted 9 lines · Andreas Jellinghaus

Am Mittwoch, 27. Juni 2007 16:35 schrieb Kay Sievers:

Quoted 5 lines

The usb-interfaces (2nd event) do not have a device node. Only the usb-device itself, but you match on interface properties. There is no sane way for udev to match on an interface property and get the device node name at the same time. You run into unsolvable timing problems, or need to use weird hacks.

if I remember correcty, with linux and hotplug this was possible, right? so linux+sysfs+udev is a regression from linux+hotplug? an unfixable?

It was "possible" due to a lot of "sleep"s in hotplug scripts (aka "unsolvable timing problem", because sleeps are not a solution).

Signature · 11 lines
Alexander E. Patrakov

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
#4 lore raw
In reply to Andreas Jellinghaus

Am Mittwoch, 27. Juni 2007 18:02 schrieb Alexander E. Patrakov:

Quoted 2 lines

It was "possible" due to a lot of "sleep"s in hotplug scripts (aka "unsolvable timing problem", because sleeps are not a solution).

but that doesn't explain why udev 093 + kernel 2.6.21.2 work where new udev and new kernel don't?

Regards, Andreas

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#5 lore raw
In reply to Andreas Jellinghaus
Quoted 9 lines · Andreas Jellinghaus

Am Mittwoch, 27. Juni 2007 16:35 schrieb Kay Sievers:

Quoted 5 lines

The usb-interfaces (2nd event) do not have a device node. Only the usb-device itself, but you match on interface properties. There is no sane way for udev to match on an interface property and get the device node name at the same time. You run into unsolvable timing problems, or need to use weird hacks.

if I remember correcty, with linux and hotplug this was possible, right? so linux+sysfs+udev is a regression from linux+hotplug? an unfixable?

It worked sometimes. Just as you can make it work sometimes today.

Quoted 3 lines

also with 2.6.21.2 plus udev 093 on ubuntu edgy it works for me. is this a udev regression or kernel regression? why is there "no sane way" if it works with older software? sorry, I'm puzzled.

No regression, you are just lucky, that it worked for you. I have tons of bug reports, and that was the reason to export the node from the usb-device directly. This allows us to solve the problem the proper way.

Quoted 10 lines
Quoted 3 lines

Also, usbfs proc device-nodes are not available on modern systems (can not support ACL's). Udev creates /dev/bus/usb/*/* nodes and libusb picks up the nodes from there, if the directory exists.

fine with me, how do I get udev to call me when a smart card reader is plugged in and pass the device name in some variable? smart card reader these days pretty much means CCID device, i.e. a device with 0b interface. could be a combo device like a keyboard with an intergrated reader, I will have a look at pick the right endpoint.

Quoted 3 lines

my last information was that there are no proper events for /dev/bus/usb nodes, such they are a regression, while they offer some new features, they also miss some older features.

No. Nothing has changed, besides that you see a bug you haven't seen before. It is a very old problem, nothing new today.

Quoted 13 lines
Quoted 5 lines

The kernel exports the devices nodes by the usb-device itself (2.6.22) or (for older kernels) by usb_device-class devices. But also with that setup, there is no convenient way to get interface properties to match against, and device node access at the same time with simple udev rules. There is support for all that in HAL, but not in udev.

I never found any useful information how to plug into hal.
is there anyone who can convert
https://www.opensc-project.org/openct/browser/trunk/etc/openct.udev
into a hal config file? not that I'm eager to move to a new software which had no useful documentation the last time I looked at it. but maybe that changed? still it would be an extra dependency some people don't want.

Quoted 6 lines

also I wonder: two years ago with linux + hotplug I was fine. when exactly began this change that results in my application being broken? I thought linux had very strict requirements not to change the kernel/userland interface without proper announcement, migration plans and all that. but for usb/udev/hotplug/sysfs I can't remember any announcement mentioning incompatible kernel/userland changes.

Nothing has changed, it's just that you see a bug a lot of people already had long time ago. Todays faster/SMP systems are just much more likely to show these timing problems.
(Oh, and if you continue this attitude, I will not reply to any of your mails anymore. I'm just too annoyed by this kind of comments. Please, try to understand the problem before talking like the usual complainers that don't have any clue what they are talking about.)

Quoted 12 lines
Quoted 5 lines

The only reliable way for udev rules would be with kernel 2.6.22, not using usb_device class devices and not using proc usbfs. With such a setup, you could hook your RUN into the interface-event and the program/script can query the device-node name from the parent device of the interface.

you mean like this?

ls -d /sys/$DEVPATH/../usb_device* |xargs basename | sed -e "s/usb_device:usbdev//g" |sed -e "s/\./ /g" |xargs printf /dev/bus/usb/%03d/%03d\\n

Quoted 7 lines

i.e. from the $DEVPATH ("interface"?) I go to .. then look for usb_device:usbdev* files, which should be only one, get that name, strip "usb_device:usbdev" and split the remainder (e.g. 3.8) first into two numbers (3 8) and then format them into /dev/bus/usb/%03d/%03d (e.g. /dev/bus/usb/003/008).

is this ok?

No, that doesn't work. usb_device-class will not exist on new systems, it is replaced by the direct device nodes of the usb-device.

You need to find the parent device (strip the last part of the devpath), and call udevinfo with the devpath to get the device node. (Repeat that until you find the device with a node, as the kernel is always free to insert additional devices in the chain devpath.)

Quoted 1 line

will it work on older kernel and future kernels as well?

No, it wouldn't work with older kernels.

You have to lookup sysfs in a different way and work with optimistic sleeps here, and need to be lucky ...

Quoted 1 line

will it work with different versions of udev?

Yes, but as said, only with most recent kernels using the device nodes exported by the usb-devicve itself. Everything else is just "hope it works".

Quoted 2 lines

could you think of any
hardware where this would't work?

It will work with any usb device.

Kay

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel