982648
From cb21f171f5b3e4b8579fa5344e533a8390c011f5 Mon Sep 17 00:00:00 2001
982648
Message-Id: <cb21f171f5b3e4b8579fa5344e533a8390c011f5@dist-git>
982648
From: Erik Skultety <eskultet@redhat.com>
982648
Date: Thu, 19 Jul 2018 15:03:49 +0200
982648
Subject: [PATCH] qemu: command: Move graphics iteration to its own function
982648
MIME-Version: 1.0
982648
Content-Type: text/plain; charset=UTF-8
982648
Content-Transfer-Encoding: 8bit
982648
982648
It should be the command line helper who takes care of the iteration
982648
rather than the caller.
982648
982648
Signed-off-by: Erik Skultety <eskultet@redhat.com>
982648
Reviewed-by: John Ferlan <jferlan@redhat.com>
982648
(cherry picked from commit afc107c20f6dc40529154a361222f9eca0cec94c)
982648
982648
https://bugzilla.redhat.com/show_bug.cgi?id=1475770
982648
Signed-off-by: Erik Skultety <eskultet@redhat.com>
982648
Reviewed-by: Ján Tomko <jtomko@redhat.com>
982648
---
982648
 src/qemu/qemu_command.c | 57 ++++++++++++++++++++++++++---------------
982648
 1 file changed, 36 insertions(+), 21 deletions(-)
982648
982648
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
982648
index f38ae668a7..8a8cbfd7f6 100644
982648
--- a/src/qemu/qemu_command.c
982648
+++ b/src/qemu/qemu_command.c
982648
@@ -8212,26 +8212,44 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
982648
 static int
982648
 qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr cfg,
982648
                              virCommandPtr cmd,
982648
-                             virQEMUCapsPtr qemuCaps,
982648
-                             virDomainGraphicsDefPtr graphics)
982648
+                             virDomainDefPtr def,
982648
+                             virQEMUCapsPtr qemuCaps)
982648
 {
982648
-    switch (graphics->type) {
982648
-    case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
982648
-        return qemuBuildGraphicsSDLCommandLine(cfg, cmd, qemuCaps, graphics);
982648
+    size_t i;
982648
 
982648
-    case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
982648
-        return qemuBuildGraphicsVNCCommandLine(cfg, cmd, qemuCaps, graphics);
982648
+    for (i = 0; i < def->ngraphics; i++) {
982648
+        virDomainGraphicsDefPtr graphics = def->graphics[i];
982648
 
982648
-    case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
982648
-        return qemuBuildGraphicsSPICECommandLine(cfg, cmd, qemuCaps, graphics);
982648
+        switch (graphics->type) {
982648
+        case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
982648
+            if (qemuBuildGraphicsSDLCommandLine(cfg, cmd,
982648
+                                                qemuCaps, graphics) < 0)
982648
+                return -1;
982648
 
982648
-    case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
982648
-    case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
982648
-    case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
982648
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
982648
-                       _("unsupported graphics type '%s'"),
982648
-                       virDomainGraphicsTypeToString(graphics->type));
982648
-        return -1;
982648
+            break;
982648
+        case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
982648
+            if (qemuBuildGraphicsVNCCommandLine(cfg, cmd,
982648
+                                                qemuCaps, graphics) < 0)
982648
+                return -1;
982648
+
982648
+            break;
982648
+        case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
982648
+            if (qemuBuildGraphicsSPICECommandLine(cfg, cmd,
982648
+                                                  qemuCaps, graphics) < 0)
982648
+                return -1;
982648
+
982648
+            break;
982648
+        case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
982648
+        case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
982648
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
982648
+                           _("unsupported graphics type '%s'"),
982648
+                           virDomainGraphicsTypeToString(graphics->type));
982648
+            return -1;
982648
+        case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
982648
+        default:
982648
+            virReportEnumRangeError(virDomainGraphicsType, graphics->type);
982648
+            return -1;
982648
+        }
982648
     }
982648
 
982648
     return 0;
982648
@@ -10382,11 +10400,8 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
982648
     if (qemuBuildInputCommandLine(cmd, def, qemuCaps) < 0)
982648
         goto error;
982648
 
982648
-    for (i = 0; i < def->ngraphics; ++i) {
982648
-        if (qemuBuildGraphicsCommandLine(cfg, cmd, qemuCaps,
982648
-                                         def->graphics[i]) < 0)
982648
-            goto error;
982648
-    }
982648
+    if (qemuBuildGraphicsCommandLine(cfg, cmd, def, qemuCaps) < 0)
982648
+        goto error;
982648
 
982648
     if (qemuBuildVideoCommandLine(cmd, def, qemuCaps) < 0)
982648
         goto error;
982648
-- 
982648
2.18.0
982648