psct / usbip

systemd units for sharing usb devices by usb/ip
GNU General Public License v3.0
7 stars 2 forks source link

udev not detecting removal #2

Open KaiStarkk opened 1 month ago

KaiStarkk commented 1 month ago

Appears that udev isn't detecting removal. Suspect this is because the device gets unbound from the kernel and taken over by the usb module.

Here's an example of plug-unplug

KERNEL[1550.466276] add      /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4 (usb)
KERNEL[1550.476696] add      /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0 (usb)
KERNEL[1550.482847] add      /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0/ttyUSB0 (usb-serial)
KERNEL[1550.483329] add      /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0/ttyUSB0/tty/ttyUSB0 (tty)
KERNEL[1550.483686] bind     /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0/ttyUSB0 (usb-serial)
KERNEL[1550.484164] bind     /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0 (usb)
KERNEL[1550.484772] bind     /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4 (usb)
UDEV  [1551.544487] add      /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4 (usb)
UDEV  [1551.816866] add      /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0 (usb)
KERNEL[1551.836990] remove   /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0/ttyUSB0/tty/ttyUSB0 (tty)
KERNEL[1551.840431] unbind   /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0/ttyUSB0 (usb-serial)
KERNEL[1551.845881] remove   /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0/ttyUSB0 (usb-serial)
KERNEL[1551.853183] unbind   /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0 (usb)
KERNEL[1551.853745] remove   /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0 (usb)
KERNEL[1551.863523] unbind   /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4 (usb)
KERNEL[1551.871341] bind     /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4 (usb)
UDEV  [1551.968520] add      /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0/ttyUSB0 (usb-serial)
UDEV  [1552.056426] add      /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0/ttyUSB0/tty/ttyUSB0 (tty)
UDEV  [1552.220543] bind     /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0/ttyUSB0 (usb-serial)
UDEV  [1552.295971] bind     /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0 (usb)
UDEV  [1552.396499] bind     /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4 (usb)
UDEV  [1552.451450] remove   /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0/ttyUSB0/tty/ttyUSB0 (tty)
UDEV  [1552.527288] unbind   /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0/ttyUSB0 (usb-serial)
UDEV  [1552.548201] remove   /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0/ttyUSB0 (usb-serial)
UDEV  [1552.576451] unbind   /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0 (usb)
UDEV  [1552.599482] remove   /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0 (usb)
UDEV  [1552.647279] unbind   /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4 (usb)
UDEV  [1552.738097] bind     /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4 (usb)
KERNEL[1601.756409] unbind   /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4 (usb)
KERNEL[1601.759204] remove   /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4 (usb)
UDEV  [1602.279535] unbind   /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4 (usb)
UDEV  [1602.296272] remove   /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.4 (usb)

And the corresponding journalctl result:

Jul 14 22:06:05 HUSK systemd[1]: Started usbip@1-1.3.4.service - USB/IP share usb device on given usb port 1-1.3.4; called by device specific udev rule.
Jul 14 22:06:06 HUSK sh[798]: usbip: info: bind device on busid 1-1.3.4: complete
Jul 14 22:22:10 HUSK systemd[1]: Stopping usbip@1-1.3.4.service - USB/IP share usb device on given usb port 1-1.3.4; called by device specific udev rule...
Jul 14 22:22:10 HUSK sh[1073]: usbip: error: device is not bound to usbip-host driver
Jul 14 22:22:10 HUSK systemd[1]: usbip@1-1.3.4.service: Deactivated successfully.
Jul 14 22:22:10 HUSK systemd[1]: Stopped usbip@1-1.3.4.service - USB/IP share usb device on given usb port 1-1.3.4; called by device specific udev rule.
Jul 14 22:22:10 HUSK systemd[1]: Started usbip@1-1.3.4.service - USB/IP share usb device on given usb port 1-1.3.4; called by device specific udev rule.
Jul 14 22:22:10 HUSK sh[1075]: usbip: info: bind device on busid 1-1.3.4: complete
Jul 14 22:26:44 HUSK systemd[1]: Stopping usbip@1-1.3.4.service - USB/IP share usb device on given usb port 1-1.3.4; called by device specific udev rule...
Jul 14 22:26:44 HUSK sh[1113]: usbip: error: device is not bound to usbip-host driver
Jul 14 22:26:44 HUSK systemd[1]: usbip@1-1.3.4.service: Deactivated successfully.
Jul 14 22:26:44 HUSK systemd[1]: Stopped usbip@1-1.3.4.service - USB/IP share usb device on given usb port 1-1.3.4; called by device specific udev rule.
Jul 14 22:26:44 HUSK systemd[1]: Started usbip@1-1.3.4.service - USB/IP share usb device on given usb port 1-1.3.4; called by device specific udev rule.
Jul 14 22:26:44 HUSK sh[1117]: usbip: info: bind device on busid 1-1.3.4: complete
Jul 14 22:28:32 HUSK systemd[1]: Stopping usbip@1-1.3.4.service - USB/IP share usb device on given usb port 1-1.3.4; called by device specific udev rule...
Jul 14 22:28:32 HUSK sh[1147]: usbip: error: device with the specified bus ID does not exist
Jul 14 22:28:32 HUSK systemd[1]: usbip@1-1.3.4.service: Deactivated successfully.
Jul 14 22:28:32 HUSK systemd[1]: Stopped usbip@1-1.3.4.service - USB/IP share usb device on given usb port 1-1.3.4; called by device specific udev rule.
Jul 14 22:28:49 HUSK systemd[1]: Started usbip@1-1.3.4.service - USB/IP share usb device on given usb port 1-1.3.4; called by device specific udev rule.
Jul 14 22:28:49 HUSK sh[1156]: usbip: info: bind device on busid 1-1.3.4: complete
KaiStarkk commented 1 month ago

As a workaround I have the udev rule just restarting the service when it detects add

thomask77 commented 4 weeks ago

I also encountered this problem. But I think the problem is that somehow the TAG="usbip" doesn't match in the remove line.

It works fine when just writing: ACTION=="remove", RUN+="/usr/bin/systemctl --no-block stop usbip@%k.service"