[libvirt] [PATCH 3/5] qemu_process: graphics: extract for loop out of qemuProcessGraphicsReservePorts

Pavel Hrdina phrdina at redhat.com
Mon Aug 15 11:28:36 UTC 2016


Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 src/qemu/qemu_process.c | 58 +++++++++++++++++++++++++------------------------
 1 file changed, 30 insertions(+), 28 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index f813bae..d61f704 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4007,37 +4007,32 @@ qemuProcessStartHook(virQEMUDriverPtr driver,
 
 static int
 qemuProcessGraphicsReservePorts(virQEMUDriverPtr driver,
-                                virDomainObjPtr vm)
+                                virDomainGraphicsDefPtr graphics)
 {
-    size_t i;
+    if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
+        !graphics->data.vnc.autoport) {
+        if (virPortAllocatorSetUsed(driver->remotePorts,
+                                    graphics->data.vnc.port,
+                                    true) < 0)
+            return -1;
+        graphics->data.vnc.portReserved = true;
 
-    for (i = 0; i < vm->def->ngraphics; ++i) {
-        virDomainGraphicsDefPtr graphics = vm->def->graphics[i];
-        if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
-            !graphics->data.vnc.autoport) {
+    } else if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE &&
+               !graphics->data.spice.autoport) {
+        if (graphics->data.spice.port > 0) {
             if (virPortAllocatorSetUsed(driver->remotePorts,
-                                        graphics->data.vnc.port,
+                                        graphics->data.spice.port,
                                         true) < 0)
                 return -1;
-            graphics->data.vnc.portReserved = true;
-
-        } else if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE &&
-                   !graphics->data.spice.autoport) {
-            if (graphics->data.spice.port > 0) {
-                if (virPortAllocatorSetUsed(driver->remotePorts,
-                                            graphics->data.spice.port,
-                                            true) < 0)
-                    return -1;
-                graphics->data.spice.portReserved = true;
-            }
+            graphics->data.spice.portReserved = true;
+        }
 
-            if (graphics->data.spice.tlsPort > 0) {
-                if (virPortAllocatorSetUsed(driver->remotePorts,
-                                            graphics->data.spice.tlsPort,
-                                            true) < 0)
-                    return -1;
-                graphics->data.spice.tlsPortReserved = true;
-            }
+        if (graphics->data.spice.tlsPort > 0) {
+            if (virPortAllocatorSetUsed(driver->remotePorts,
+                                        graphics->data.spice.tlsPort,
+                                        true) < 0)
+                return -1;
+            graphics->data.spice.tlsPortReserved = true;
         }
     }
 
@@ -4202,15 +4197,22 @@ qemuProcessSetupGraphics(virQEMUDriverPtr driver,
                          virDomainObjPtr vm,
                          unsigned int flags)
 {
+    virDomainGraphicsDefPtr graphics;
     bool allocate = !(flags & VIR_QEMU_PROCESS_START_PRETEND);
     size_t i;
     int ret = -1;
 
-    if (allocate && qemuProcessGraphicsReservePorts(driver, vm) < 0)
-        goto cleanup;
+    if (allocate) {
+        for (i = 0; i < vm->def->ngraphics; i++) {
+            graphics = vm->def->graphics[i];
+
+            if (qemuProcessGraphicsReservePorts(driver, graphics) < 0)
+                goto cleanup;
+        }
+    }
 
     for (i = 0; i < vm->def->ngraphics; ++i) {
-        virDomainGraphicsDefPtr graphics = vm->def->graphics[i];
+        graphics = vm->def->graphics[i];
 
         if (qemuProcessGraphicsAllocatePorts(driver, graphics, allocate) < 0)
             goto cleanup;
-- 
2.9.2




More information about the libvir-list mailing list