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