usb-libvirt-hotplug icon indicating copy to clipboard operation
usb-libvirt-hotplug copied to clipboard

Attach device does not work on action "add" but "bind"

Open schlumpfit opened this issue 6 years ago • 6 comments

I tried to attach a USB Device with the script but i got the error: "error : qemuMonitorJSONCheckError:392 : internal error: unable to execute QEMU command 'device_add': failed to find host usb device 3:70" But lsusb showed the device and i was able to attach it manually. As workaround i now trigger the script on action "bind" for attaching and "remove" for detaching. For me i seemed that the script was called before the device was fully initialized...?

schlumpfit avatar Oct 15 '18 08:10 schlumpfit

Same issue here on Fedora 29.

raymanfx avatar Dec 05 '18 15:12 raymanfx

Same issue on Fedora 32.

MarekPikula avatar Jun 26 '20 16:06 MarekPikula

Same on Gentoo

diabelb avatar Jul 30 '20 19:07 diabelb

Yes, Bind is the way to go for my Keyboard and Mouse. Otherwise, they randomly fail to connect with the same error.

nick-kvmhv avatar Oct 08 '20 01:10 nick-kvmhv

You may want to add lines for bind/unbind as well as leaving the add/remove lines alone, in case you're dealing with multiple devices

if [ "${ACTION}" == 'add' ]; then
  COMMAND='attach-device'
elif [ "${ACTION}" == 'bind' ]; then
  #Some devices are not ready until after the "BIND" occurs
  COMMAND='attach-device'
elif [ "${ACTION}" == 'remove' ]; then
  COMMAND='detach-device'
elif [ "${ACTION}" == 'unbind' ]; then
  COMMAND='detach-device'
else
  echo "Invalid udev ACTION: ${ACTION}" >&2
  exit 1
fi

Also, be wary as attaching a device to the VM may actually cause unbind/remove events to fire against the host as it is detached from there and reattached to the guest. You can get around accidentally triggering the unbind/remove event by using a property that only exists on a full removal, i.e. ENV{BUSNUM} ,ENV{BUSNUM}=="?*",

These worked for attaching/detaching the serial device associated with a 3D printer from my VM.

phormix avatar Jan 27 '21 08:01 phormix

Same issue on Debian buster using a USB flash drive. Worked for me if I changed add/remove to bind/unbind.

solemnwarning avatar Dec 22 '21 12:12 solemnwarning