]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: separate counting of USB controllers
authorJán Tomko <jtomko@redhat.com>
Tue, 15 Jan 2019 15:28:55 +0000 (16:28 +0100)
committerJán Tomko <jtomko@redhat.com>
Fri, 25 Jan 2019 13:54:51 +0000 (14:54 +0100)
qemuBuildLegacyUSBControllerCommandLine is the only place where
we need to count the USB controllers.

Count them again instead of keeping track in a variable passed to
qemuBuildControllerDevStr.

This removes the need for another variable in the loop in
qemuBuildControllerDevCommandLine.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
src/qemu/qemu_command.c

index 04b64c4f1c413b34da753f96f6ba64b279b1257c..df6a331d14783148482fe0bde46be0864a2701c7 100644 (file)
@@ -3063,11 +3063,11 @@ qemuBuildDomainForbidLegacyUSBController(const virDomainDef *def)
 
 static int
 qemuBuildLegacyUSBControllerCommandLine(virCommandPtr cmd,
-                                        const virDomainDef *def,
-                                        int usbcontroller)
+                                        const virDomainDef *def)
 {
     size_t i;
     size_t nlegacy = 0;
+    size_t nusb = 0;
 
     for (i = 0; i < def->ncontrollers; i++) {
         virDomainControllerDefPtr cont = def->controllers[i];
@@ -3081,6 +3081,8 @@ qemuBuildLegacyUSBControllerCommandLine(virCommandPtr cmd,
 
         if (cont->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_DEFAULT)
             nlegacy++;
+        else
+            nusb++;
     }
 
     if (nlegacy > 1) {
@@ -3090,7 +3092,7 @@ qemuBuildLegacyUSBControllerCommandLine(virCommandPtr cmd,
         return -1;
     }
 
-    if (usbcontroller == 0 &&
+    if (nusb == 0 &&
         !qemuBuildDomainForbidLegacyUSBController(def) &&
         !ARCH_IS_S390(def->os.arch)) {
         /* We haven't added any USB controller yet, but we haven't been asked
@@ -3227,7 +3229,7 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd,
         }
     }
 
-    if (qemuBuildLegacyUSBControllerCommandLine(cmd, def, usbcontroller) < 0)
+    if (qemuBuildLegacyUSBControllerCommandLine(cmd, def) < 0)
         goto cleanup;
 
     ret = 0;