Skip to contentSkip to conversation

udev no longer passes USB device remove events

DISCUSSION Anthony L. Awtrey 2 participants 5 messages Dec 26, 2007 – Dec 29, 2007

lore
Share & tools
lore
#0 lore raw

Hello the list,

I've got a puzzler that I hope someone can help me with. When I upgraded from Debian Etch to the Debian Lenny pre-release, I noticed that a simple system tray app to indicate when a device was plugged into my various USB ports stopped working. It would light up, but never go off.

I dug around and finally discovered that udev-114 no longer passed the 'remove' 'usb' events that udev-105 did without fail. I filed some additional details with the Debian BTS:

http://bugs.debian.org/cgi-bin/bugreport.cgi?bugE7616

Note that 'udevmonitor --kernel' shows the remove event coming in, but that 'udevmonitor --udev' never shows the remove event being passed. I also dialed up the logging and traced an insertion and removal of a USB drive. The interesting bit is in the removal section:

Dec 23 22:15:13 dhcp-141 udevd[2199]: udev_event_run: seq 2614 forked,
                                      pid [11386], 'remove' 'usb', 0
                                      seconds old
Dec 23 22:15:13 dhcp-141 udevd-event[11386]: udev_db_get_device: found a
                                             symlink as db file
Dec 23 22:15:13 dhcp-141 udevd-event[11386]: name_index: removing index:
                                             ... 8< long dev name >8 ...
Dec 23 22:15:13 dhcp-141 udevd-event[11386]: udev_event_run: seq 2614
                                             finished with -1
Dec 23 22:15:13 dhcp-141 udevd[2199]: udev_done: seq 2614, pid [11386]
                                      exit with 1, 0 seconds old

It looks, to my uneducated eye, that the udevd-event function fails. Note that this is the only time that particular function fails in all the activity associated with inserting and removing the USB device.

I tried out the latest udev-118 to see if it still has this issue and found that about 1 in 4 times I inserted/removed the device I would get a remove event, but the other times it would fail like it does under udev-114. I noted that the few times it worked, the event happened to complete last (e.g. there were no other events processed after it) and every time it failed there were some additional remove events still processing, particularly 'remove' 'block' events. I found that udev-105 worked very reliably when I tried it with Lenny.

Could this be some kind of timing issue? Does anyone with familiarity with the code see something that could help me? Thanks in advance.

Tony

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#1 lore raw

Hello again,

I fixed my problem, but not the right way. One thing that tripped me when I was investigating this issue was that when you issue a "udevcontrol log_priorityÞbug" you don't actually get dbg() messages in the syslog. Therefore my log dump looked like silent failure to me. Once I found the function I suspected to cause the trouble, I changed the dgb() functions to info() and could see this:

udev_node_remove: device node '/dev/bus/usb/004/007' not found

It looks like udev is failing to remove a non-existant device node and returning -1. Raw USB devices don't necessarily have device nodes to remove, so the perfectly reasonable "remove usb" events are failing for no good reason that I can tell.

I fixed my problem by allowing the function udev_node_remove() to return 0 on device node remove failures:

...
int udev_node_remove(struct udevice *udev)

{
        char filename[PATH_SIZE];
        char partitionname[PATH_SIZE];
        struct stat stats;
        int retval = 0;
        int num;

        strlcpy(filename, udev_root, sizeof(filename));
        strlcat(filename, "/", sizeof(filename));
        strlcat(filename, udev->name, sizeof(filename));
        if (stat(filename, &stats) != 0) {
                dbg("device node '%s' not found", filename);
                return 0; /* <--- LOOK */
        }

...

I don't know the other implications, but it appears to work and does not cause any other obvious problems in my limited testing. Can anyone suggest a more appropriate fix?

Tony

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
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 Anthony L. Awtrey
Quoted 6 lines · Anthony L. Awtrey

I fixed my problem, but not the right way. One thing that tripped me when I was investigating this issue was that when you issue a "udevcontrol log_priorityÞbug" you don't actually get dbg() messages in the syslog. Therefore my log dump looked like silent failure to me. Once I found the function I suspected to cause the trouble, I changed the dgb() functions to info() and could see this:

The dbg() macro is usually not compiled into the binaries, you have to enable this at compile-time.

Quoted 5 lines

udev_node_remove: device node '/dev/bus/usb/004/007' not found

It looks like udev is failing to remove a non-existant device node and returning -1. Raw USB devices don't necessarily have device nodes to remove,

No, every usb_device has a device node. And udev will only try to remove a node when the kernel passes a major/minor number. Seems there is something strange going on on your system.

Quoted 2 lines

so the perfectly reasonable "remove usb" events are failing for no good reason that I can tell.

Yeah, that should not prevent the RUN execution.

Quoted 6 lines

I fixed my problem by allowing the function udev_node_remove() to return 0 on device node remove failures:

I don't know the other implications, but it appears to work and does not cause any other obvious problems in my limited testing. Can anyone suggest a more appropriate fix?

Looks fine, we should not fail if it's already gone. I applied the patch:
http://git.kernel.org/?p=linux/hotplug/udev.git;a=commitdiff;h 092d28dbb2c1c75c2fac17303b703343f03a35

Thanks,
Kay

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
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 Anthony L. Awtrey
Quoted 3 lines · Kay Sievers

No, every usb_device has a device node. And udev will only try to remove a node when the kernel passes a major/minor number. Seems there is something strange going on on your system.

FYI, this behavior also occurs on stock Debian Lenny pre-release that I installed on 12-26-2007. I filed the appropriate Debian BTS report, so Mario should now be aware of it as well. I'll post an update alerting of your patch for the issue.

Thanks so much for the response, Kay!

Tony

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
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 Anthony L. Awtrey
Quoted 9 lines · Anthony L. Awtrey
Quoted 3 lines · Kay Sievers

No, every usb_device has a device node. And udev will only try to remove a node when the kernel passes a major/minor number. Seems there is something strange going on on your system.

FYI, this behavior also occurs on stock Debian Lenny pre-release that I installed on 12-26-2007. I filed the appropriate Debian BTS report, so Mario should now be aware of it as well. I'll post an update alerting of your patch for the issue.

I guess the kernel has the deprecated CONFIG_USB_DEVICE_CLASS set, and udev has rules for the new and the old devices to create the same device nodes. Without the fix, the node gets deleted by the other event.

Does commenting out the rule which starts with:
SUBSYSTEM="usb_device", ...
make the problem go away?

Kay

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel