usb-libvirt-hotplug
usb-libvirt-hotplug copied to clipboard
Attach device does not work on action "add" but "bind"
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...?
Same issue here on Fedora 29.
Same issue on Fedora 32.
Same on Gentoo
Yes, Bind is the way to go for my Keyboard and Mouse. Otherwise, they randomly fail to connect with the same error.
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.
Same issue on Debian buster using a USB flash drive. Worked for me if I changed add/remove to bind/unbind.