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