]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: separate counting of legacy USB controllers
authorJán Tomko <jtomko@redhat.com>
Tue, 15 Jan 2019 15:15:39 +0000 (16:15 +0100)
committerJán Tomko <jtomko@redhat.com>
Fri, 25 Jan 2019 13:54:51 +0000 (14:54 +0100)
Count them in qemuBuildLegacyUSBControllerCommandLine to remove
yet another variable accessed from 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 82c2a47f5e2e2430eab386b31c9859745f78725d..04b64c4f1c413b34da753f96f6ba64b279b1257c 100644 (file)
@@ -3067,6 +3067,7 @@ qemuBuildLegacyUSBControllerCommandLine(virCommandPtr cmd,
                                         int usbcontroller)
 {
     size_t i;
+    size_t nlegacy = 0;
 
     for (i = 0; i < def->ncontrollers; i++) {
         virDomainControllerDefPtr cont = def->controllers[i];
@@ -3077,6 +3078,16 @@ qemuBuildLegacyUSBControllerCommandLine(virCommandPtr cmd,
         /* If we have mode='none', there are no other USB controllers */
         if (cont->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE)
             return 0;
+
+        if (cont->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_DEFAULT)
+            nlegacy++;
+    }
+
+    if (nlegacy > 1) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Multiple legacy USB controllers are "
+                         "not supported"));
+        return -1;
     }
 
     if (usbcontroller == 0 &&
@@ -3137,7 +3148,6 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd,
 {
     size_t i, j;
     int usbcontroller = 0;
-    bool usblegacy = false;
     int contOrder[] = {
         /*
          * List of controller types that we add commandline args for,
@@ -3197,13 +3207,6 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd,
                  * (see 548ba43028 for the full story), so we skip
                  * qemuBuildControllerDevStr() but we don't ultimately end
                  * up adding the legacy USB controller */
-                if (usblegacy) {
-                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                                   _("Multiple legacy USB controllers are "
-                                     "not supported"));
-                    goto cleanup;
-                }
-                usblegacy = true;
                 continue;
             }