On 7/18/09, Ben Beuchler <insyte@xxxxxxxxx> wrote: > I'm trying to write a rule that detects the unplugging of a particular > USB device and unloads the kernel module when that happens. The > reason is that the module appears to be buggy in that if the device is > reconnected without first unloading the module, the module hangs and > the device is not activated. At this point even forcibly unloading > the module makes no difference. > > The device is a MultiTech GSM modem. The udevinfo used to build the > rule is pasted below. Here is the rule I've created (and installed in > /etc/udev/rules.d/85-mts_gsm_3410_remove.rules): > > SUBSYSTEMS=="usb", ACTION=="remove", ATTRS{idVendor}=="06e0", > ATTRS{idProduct}=="f111", RUN+="modprobe -r ti_usb_3410_5052" > > For testing purposes, I changed the modprobe to "echo hello from > ti_usb_remove >> /tmp/udev.works" > > udevtest seems to indicate that the rule works: > > # udevtest --action=remove > /devices/pci0000:00/0000:00:1d.3/usb4/4-1/4-1:2.0/ttyUSB0 | grep -v > ^parse_file > [:snipped udevtest explanation:] > import_uevent_var: import into environment: 'DRIVER=ti_usb_3410_5052_1' > udevtest: looking at device > '/devices/pci0000:00/0000:00:1d.3/usb4/4-1/4-1:2.0/ttyUSB0' from > subsystem 'usb-serial' > udevtest: run: '/bin/sh -c 'echo 2 > > /sys/devices/pci0000:00/0000:00:1d.3/usb4/4-1/4-1:2.0/ttyUSB0/device/bConfigurationValue'' > udevtest: run: 'echo hello from ti_usb_remove >> /tmp/udev.works' > udevtest: run: 'socket:/org/kernel/udev/monitor' > > However if I actually unplug the device, /tmp/udev.works doesn't show > up. On the off chance that my kernel doesn't support inotify, I also > tried running "udevcontrol reload_rules". Still failed. The output > of udevmonitor, captured while unplugging the device, is pasted below. > For giggles, I also tried running a "logger hello" command instead of > the echo. Does not appear to run. > > Any idea what I'm doing wrong? ATTR won't work on a real remove, because the sysfs files are removed before udev processes the event. Apparently you can change the match to ACTION=="add" and set ENV{REMOVE_CMD}=="modprobe -r ti_usb_3410_5052" instead. This feature was recently mentioned here <http://article.gmane.org/gmane.linux.hotplug.devel/14221>. I don't know when REMOVE_CMD was added to the rules. If your rules are too old, you should be able implement it yourself. It is a really simple idea, you just need another rule to run the command on remove. ACTION=="remove", ENV{REMOVE_CMD}=="?*", RUN+="$env{REMOVE_CMD}" Oh, and this is a pretty major bug in the module, please make sure it has been reported to the appropriate people :-). Alan -- To unsubscribe from this list: send the line "unsubscribe linux-hotplug" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html