[libvirt] [PATCH 04/11] qemu: separate counting of legacy USB controllers

Ján Tomko jtomko at redhat.com
Wed Jan 16 07:56:09 UTC 2019


Count them in qemuBuildLegacyUSBControllerCommandLine to remove
yet another variable accessed from the loop in
qemuBuildControllerDevCommandLine.

Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 src/qemu/qemu_command.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index cce5520783..014bd031a8 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3039,6 +3039,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];
@@ -3049,6 +3050,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 &&
@@ -3109,7 +3120,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,
@@ -3169,13 +3179,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;
             }
 
-- 
2.20.1




More information about the libvir-list mailing list