Bug 914883 - RFE: domain: allow specifying USB devices by their host port
Summary: RFE: domain: allow specifying USB devices by their host port
Keywords:
Status: CLOSED DEFERRED
Alias: None
Product: Virtualization Tools
Classification: Community
Component: libvirt
Version: unspecified
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Libvirt Maintainers
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-02-23 06:55 UTC by Hedayat Vatankhah
Modified: 2020-11-03 16:39 UTC (History)
8 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2020-11-03 16:39:32 UTC
Embargoed:


Attachments (Terms of Use)
Patch to add optional serial id value to usb hostdev entry (12.37 KB, patch)
2013-06-13 15:08 UTC, David Waring
no flags Details | Diff

Description Hedayat Vatankhah 2013-02-23 06:55:29 UTC
Description of problem:
Currently, libvirt supports attaching usb devices using their vendor and produc ids. However, it can happen that several devices with the same vendor and product IDs are attached to the system. libvirt already supports specifying device address using bus and device addressing, however this is not very suitable because it can change if you re-plug the device. There might be workarounds, but the ability to specify the usb device using its serial number would be a much better solution. 

Thanks

Comment 1 David Waring 2013-06-13 15:08:18 UTC
Created attachment 760753 [details]
Patch to add optional serial id value to usb hostdev entry

I need this facility too (multiple USB DVB-T sticks with different aerial inputs, so the right one has to go to the right VM), so I've written a patch.

This patch adds the option to include a <serial id='serial-number'/> element in the hostdev/source element for a usb host device. If the element is present, then only usb devices with matching vendor id, product id _and_ serial number will match. If absent then any device matching vendor and product will match (as it is now).

The patch is a git patch against the current git head and I've tested it on Fedora 18.

Comment 2 Jiri Denemark 2013-06-14 12:19:40 UTC
David, would you mind sending the patch to libvirt-list? Instructions on how to do that easily from git can be found at http://www.libvirt.org/hacking.html

Comment 3 David Waring 2013-06-14 12:51:53 UTC
ok, done that (I think).

Comment 4 Daniel Veillard 2013-06-14 14:10:30 UTC
Indeed:

https://www.redhat.com/archives/libvir-list/2013-June/msg00624.html

thanks !

Daniel

Comment 5 Cole Robinson 2014-01-16 22:02:14 UTC
Doesn't look like this ever made it upstream, taking out of POST

Comment 6 josh 2014-08-20 01:23:39 UTC
It seems the proper way to do this is by using libvirt's existing address/bus/device facility when adding usb hardware. I don't see any reason not to make this default behavior, actually.

Comment 7 David Waring 2014-08-22 10:47:37 UTC
Josh,

The issue is that in normal operation you cannot guarentee the address/bus/device that a USB device will be assigned as the device number is assigned dynamically by the kernel. If you plug in a USB device, note its device number, unplug it and then plug it back into exactly the same USB port again, it'll have a different device number. This also happens when a USB device is reset, which unfortunately happens when the VM a USB device attached to is shutdown and started again.

So in normal operation simply shutting down a VM and then starting again will lose the USB device that was attached. The current work around is to use the device ID instead to find which address/bus/device a USB device has been given. Unfortunately if you have two identical devices libvirt will simply attach the first one it sees that is not already attached to a VM.

The proposed solution is to use the device ID and serial number to differentiate between two identical devices so that a particular one can be found.

Unfortunately the patch I gave was incomplete as far as unit tests and virt-manager integration was concerned and I have had no time to work on completing the patch to the maintainers satisfaction.

Comment 8 Ján Tomko 2014-08-22 11:41:40 UTC
I have reposted the patch back in June:
https://www.redhat.com/archives/libvir-list/2014-June/msg00304.html

It seems adding support for specifying the USB port in the address is the preferred way:
https://www.redhat.com/archives/libvir-list/2014-June/msg00339.html

But I haven't gotten around to doing that.

Comment 9 Jort Koopmans 2015-03-13 17:59:36 UTC
Today I encountered this limitation, it seems this patch has not made it to libvirt yet.
I have 2 devices which have the same Vendor and Product IDs, but different serials. I need to attach one to the VM.
The Device number is indeed variable and does not work consistently.
Therefore, a patch is highly anticipated and appreciated.

Comment 10 Cole Robinson 2016-04-09 22:38:40 UTC
Retitling to reflect danpb's suggested fix in the thread posted above

Comment 11 Cole Robinson 2016-09-08 20:21:31 UTC
There was a patch sent upstream recently for this:

http://www.redhat.com/archives/libvir-list/2016-July/msg00127.html

Comment 12 Daniel Berrangé 2020-11-03 16:39:32 UTC
Thank you for reporting this issue to the libvirt project. Unfortunately we have been unable to resolve this issue due to insufficient maintainer capacity and it will now be closed. This is not a reflection on the possible validity of the issue, merely the lack of resources to investigate and address it, for which we apologise. If you none the less feel the issue is still important, you may choose to report it again at the new project issue tracker https://gitlab.com/libvirt/libvirt/-/issues The project also welcomes contribution from anyone who believes they can provide a solution.


Note You need to log in before you can comment on or make changes to this bug.