mirror of
https://github.com/libvirt/libvirt.git
synced 2026-09-03 20:53:04 -05:00
libxl: allow vendor/product addressing for USB hostdevs
libxl only has API to address the host USB devices by bus/device. Find the bus/device if the user only provided the vendor/product of the USB device. Signed-off-by: Jim Fehlig <jfehlig@suse.com>
This commit is contained in:
+23
-10
@@ -1559,23 +1559,36 @@ int
|
|||||||
libxlMakeUSB(virDomainHostdevDefPtr hostdev, libxl_device_usbdev *usbdev)
|
libxlMakeUSB(virDomainHostdevDefPtr hostdev, libxl_device_usbdev *usbdev)
|
||||||
{
|
{
|
||||||
virDomainHostdevSubsysUSBPtr usbsrc = &hostdev->source.subsys.u.usb;
|
virDomainHostdevSubsysUSBPtr usbsrc = &hostdev->source.subsys.u.usb;
|
||||||
|
virUSBDevicePtr usb = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
|
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
|
||||||
return -1;
|
return ret;
|
||||||
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
|
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
|
||||||
return -1;
|
return ret;
|
||||||
|
|
||||||
if (usbsrc->bus <= 0 || usbsrc->device <= 0) {
|
if (usbsrc->bus > 0 && usbsrc->device > 0) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
usbdev->u.hostdev.hostbus = usbsrc->bus;
|
||||||
_("libxenlight supports only USB device "
|
usbdev->u.hostdev.hostaddr = usbsrc->device;
|
||||||
"specified by busnum:devnum"));
|
} else {
|
||||||
return -1;
|
if (virHostdevFindUSBDevice(hostdev, true, &usb) < 0) {
|
||||||
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||||
|
_("failed to find USB device busnum:devnum "
|
||||||
|
"for %x:%x"),
|
||||||
|
usbsrc->vendor, usbsrc->product);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
usbdev->u.hostdev.hostbus = virUSBDeviceGetBus(usb);
|
||||||
|
usbdev->u.hostdev.hostaddr = virUSBDeviceGetDevno(usb);
|
||||||
}
|
}
|
||||||
|
|
||||||
usbdev->u.hostdev.hostbus = usbsrc->bus;
|
ret = 0;
|
||||||
usbdev->u.hostdev.hostaddr = usbsrc->device;
|
|
||||||
|
|
||||||
return 0;
|
cleanup:
|
||||||
|
virUSBDeviceFree(usb);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|||||||
Reference in New Issue
Block a user