[PATCH 2/5] qemu_process: graphics: extract port allocation into function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/qemu/qemu_process.c | 61 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 40 insertions(+), 21 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 26aef5e..f813bae 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4046,6 +4046,44 @@ qemuProcessGraphicsReservePorts(virQEMUDriverPtr driver,
 
 
 static int
+qemuProcessGraphicsAllocatePorts(virQEMUDriverPtr driver,
+                                 virDomainGraphicsDefPtr graphics,
+                                 bool allocate)
+{
+    virDomainGraphicsListenDefPtr glisten;
+
+    if (graphics->nListens <= 0)
+        return 0;
+
+    glisten = &graphics->listens[0];
+
+    if (glisten->type != VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS &&
+        glisten->type != VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK)
+        return 0;
+
+    switch (graphics->type) {
+    case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
+        if (qemuProcessVNCAllocatePorts(driver, graphics, allocate) < 0)
+            return -1;
+        break;
+
+    case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
+        if (qemuProcessSPICEAllocatePorts(driver, graphics, allocate) < 0)
+            return -1;
+        break;
+
+    case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
+    case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
+    case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
+    case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
+        break;
+    }
+
+    return 0;
+}
+
+
+static int
 qemuProcessGraphicsSetupNetworkAddress(virDomainGraphicsListenDefPtr glisten,
                                        const char *listenAddr)
 {
@@ -4174,27 +4212,8 @@ qemuProcessSetupGraphics(virQEMUDriverPtr driver,
     for (i = 0; i < vm->def->ngraphics; ++i) {
         virDomainGraphicsDefPtr graphics = vm->def->graphics[i];
 
-        if (graphics->nListens > 0 &&
-            (graphics->listens[0].type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS ||
-             graphics->listens[0].type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK)) {
-            switch (graphics->type) {
-            case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
-                if (qemuProcessVNCAllocatePorts(driver, graphics, allocate) < 0)
-                    goto cleanup;
-                break;
-
-            case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
-                if (qemuProcessSPICEAllocatePorts(driver, graphics, allocate) < 0)
-                    goto cleanup;
-                break;
-
-            case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
-            case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
-            case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
-            case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
-                break;
-            }
-        }
+        if (qemuProcessGraphicsAllocatePorts(driver, graphics, allocate) < 0)
+            goto cleanup;
 
         if (qemuProcessGraphicsSetupListen(driver, graphics, vm) < 0)
             goto cleanup;
-- 
2.9.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]