mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 15:15:25 +00:00
vbox: cleanup vboxAttachUSB
This cleanup flattens deeply nested code. Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com>
This commit is contained in:
parent
55d1285ef4
commit
1868b4574e
@ -4852,28 +4852,35 @@ vboxAttachUSB(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
|
|||||||
* usual
|
* usual
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < def->nhostdevs; i++) {
|
for (i = 0; i < def->nhostdevs; i++) {
|
||||||
if (def->hostdevs[i]->mode ==
|
if (def->hostdevs[i]->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
|
||||||
VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
|
continue;
|
||||||
if (def->hostdevs[i]->source.subsys.type ==
|
|
||||||
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
|
if (def->hostdevs[i]->source.subsys.type !=
|
||||||
if (def->hostdevs[i]->source.subsys.u.usb.vendor ||
|
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
|
||||||
def->hostdevs[i]->source.subsys.u.usb.product) {
|
continue;
|
||||||
|
|
||||||
|
if (!def->hostdevs[i]->source.subsys.u.usb.vendor &&
|
||||||
|
!def->hostdevs[i]->source.subsys.u.usb.product)
|
||||||
|
continue;
|
||||||
|
|
||||||
VIR_DEBUG("USB Device detected, VendorId:0x%x, ProductId:0x%x",
|
VIR_DEBUG("USB Device detected, VendorId:0x%x, ProductId:0x%x",
|
||||||
def->hostdevs[i]->source.subsys.u.usb.vendor,
|
def->hostdevs[i]->source.subsys.u.usb.vendor,
|
||||||
def->hostdevs[i]->source.subsys.u.usb.product);
|
def->hostdevs[i]->source.subsys.u.usb.product);
|
||||||
isUSB = true;
|
isUSB = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isUSB) {
|
if (!isUSB)
|
||||||
|
return;
|
||||||
|
|
||||||
/* First Start the USB Controller and then loop
|
/* First Start the USB Controller and then loop
|
||||||
* to attach USB Devices to it
|
* to attach USB Devices to it
|
||||||
*/
|
*/
|
||||||
machine->vtbl->GetUSBController(machine, &USBController);
|
machine->vtbl->GetUSBController(machine, &USBController);
|
||||||
if (USBController) {
|
|
||||||
|
if (!USBController)
|
||||||
|
return;
|
||||||
|
|
||||||
USBController->vtbl->SetEnabled(USBController, 1);
|
USBController->vtbl->SetEnabled(USBController, 1);
|
||||||
#if VBOX_API_VERSION < 4002
|
#if VBOX_API_VERSION < 4002
|
||||||
USBController->vtbl->SetEnabledEhci(USBController, 1);
|
USBController->vtbl->SetEnabledEhci(USBController, 1);
|
||||||
@ -4882,14 +4889,20 @@ vboxAttachUSB(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (i = 0; i < def->nhostdevs; i++) {
|
for (i = 0; i < def->nhostdevs; i++) {
|
||||||
if (def->hostdevs[i]->mode ==
|
|
||||||
VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
|
|
||||||
if (def->hostdevs[i]->source.subsys.type ==
|
|
||||||
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
|
|
||||||
|
|
||||||
char *filtername = NULL;
|
char *filtername = NULL;
|
||||||
PRUnichar *filternameUtf16 = NULL;
|
PRUnichar *filternameUtf16 = NULL;
|
||||||
IUSBDeviceFilter *filter = NULL;
|
IUSBDeviceFilter *filter = NULL;
|
||||||
|
PRUnichar *vendorIdUtf16 = NULL;
|
||||||
|
char vendorId[40] = {0};
|
||||||
|
PRUnichar *productIdUtf16 = NULL;
|
||||||
|
char productId[40] = {0};
|
||||||
|
|
||||||
|
if (def->hostdevs[i]->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (def->hostdevs[i]->source.subsys.type !=
|
||||||
|
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
|
||||||
|
continue;
|
||||||
|
|
||||||
/* Zero pad for nice alignment when fewer than 9999
|
/* Zero pad for nice alignment when fewer than 9999
|
||||||
* devices.
|
* devices.
|
||||||
@ -4903,14 +4916,12 @@ vboxAttachUSB(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
|
|||||||
}
|
}
|
||||||
VBOX_UTF16_FREE(filternameUtf16);
|
VBOX_UTF16_FREE(filternameUtf16);
|
||||||
|
|
||||||
if (filter &&
|
if (!filter)
|
||||||
(def->hostdevs[i]->source.subsys.u.usb.vendor ||
|
continue;
|
||||||
def->hostdevs[i]->source.subsys.u.usb.product)) {
|
|
||||||
|
|
||||||
PRUnichar *vendorIdUtf16 = NULL;
|
if (!def->hostdevs[i]->source.subsys.u.usb.vendor &&
|
||||||
char vendorId[40] = {0};
|
!def->hostdevs[i]->source.subsys.u.usb.product)
|
||||||
PRUnichar *productIdUtf16 = NULL;
|
continue;
|
||||||
char productId[40] = {0};
|
|
||||||
|
|
||||||
if (def->hostdevs[i]->source.subsys.u.usb.vendor) {
|
if (def->hostdevs[i]->source.subsys.u.usb.vendor) {
|
||||||
snprintf(vendorId, sizeof(vendorId), "%x",
|
snprintf(vendorId, sizeof(vendorId), "%x",
|
||||||
@ -4933,13 +4944,7 @@ vboxAttachUSB(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
|
|||||||
filter);
|
filter);
|
||||||
VBOX_RELEASE(filter);
|
VBOX_RELEASE(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
VBOX_RELEASE(USBController);
|
VBOX_RELEASE(USBController);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user