]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: remove duplicated code for allocating spice ports
authorPavel Hrdina <phrdina@redhat.com>
Fri, 27 Feb 2015 13:28:53 +0000 (14:28 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 3 Mar 2015 10:41:46 +0000 (11:41 +0100)
We have two different places that needs to be updated while touching
code for allocation spice ports.  Add a bool option to
'qemuProcessSPICEAllocatePorts' function to switch between true and fake
allocation so we can use this function also in qemu_driver to generate
native domain definition.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/qemu/qemu_driver.c
src/qemu/qemu_process.c
src/qemu/qemu_process.h

index da22f2bab7b6f1920cd44fd13e58af3a3f7f2f6c..84aa0994b242aef526faf0162848d0b774d9cb8a 100644 (file)
@@ -6590,49 +6590,8 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
             !graphics->data.vnc.socket && graphics->data.vnc.autoport) {
             graphics->data.vnc.port = 5900;
         } else if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
-            size_t j;
-            bool needTLSPort = false;
-            bool needPort = false;
-            int defaultMode = graphics->data.spice.defaultMode;
-
-            if (graphics->data.spice.autoport) {
-                /* check if tlsPort or port need allocation */
-                for (j = 0; j < VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_LAST; j++) {
-                    switch (graphics->data.spice.channels[j]) {
-                    case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_SECURE:
-                        needTLSPort = true;
-                        break;
-
-                    case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_INSECURE:
-                        needPort = true;
-                        break;
-
-                    case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_ANY:
-                        switch (defaultMode) {
-                        case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_SECURE:
-                            needTLSPort = true;
-                            break;
-
-                        case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_INSECURE:
-                            needPort = true;
-                            break;
-
-                        case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_ANY:
-                            if (cfg->spiceTLS)
-                                needTLSPort = true;
-                            needPort = true;
-                            break;
-                        }
-                        break;
-                    }
-                }
-            }
-
-            if (needPort || graphics->data.spice.port == -1)
-                graphics->data.spice.port = 5901;
-
-            if (needTLSPort || graphics->data.spice.tlsPort == -1)
-                graphics->data.spice.tlsPort = 5902;
+            if (qemuProcessSPICEAllocatePorts(driver, cfg, graphics, false) < 0)
+                goto cleanup;
         }
     }
 
index 7ce6115797b9f62373bd792c48dde794e0acffc2..432249794777a1e82c921a56905279681578cffd 100644 (file)
@@ -4019,10 +4019,11 @@ qemuProcessVNCAllocatePorts(virQEMUDriverPtr driver,
     return 0;
 }
 
-static int
+int
 qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
                               virQEMUDriverConfigPtr cfg,
-                              virDomainGraphicsDefPtr graphics)
+                              virDomainGraphicsDefPtr graphics,
+                              bool allocate)
 {
     unsigned short port = 0;
     unsigned short tlsPort;
@@ -4065,6 +4066,16 @@ qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
         }
     }
 
+    if (!allocate) {
+        if (needPort || graphics->data.spice.port == -1)
+            graphics->data.spice.port = 5901;
+
+        if (needTLSPort || graphics->data.spice.tlsPort == -1)
+            graphics->data.spice.tlsPort = 5902;
+
+        return 0;
+    }
+
     if (needPort || graphics->data.spice.port == -1) {
         if (virPortAllocatorAcquire(driver->remotePorts, &port) < 0)
             goto error;
@@ -4573,7 +4584,7 @@ int qemuProcessStart(virConnectPtr conn,
             if (qemuProcessVNCAllocatePorts(driver, graphics) < 0)
                 goto cleanup;
         } else if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
-            if (qemuProcessSPICEAllocatePorts(driver, cfg, graphics) < 0)
+            if (qemuProcessSPICEAllocatePorts(driver, cfg, graphics, true) < 0)
                 goto cleanup;
         }
 
index 2e1d3932197a21e0415f4af8072b6d0812504f84..5c708035139be0efb6388ddc9eb425d944cae845 100644 (file)
@@ -107,4 +107,9 @@ int qemuProcessReadLog(int fd, char *buf, int buflen, int off, bool skipchar);
 int qemuProcessSetSchedParams(int id, pid_t pid, size_t nsp,
                               virDomainThreadSchedParamPtr sp);
 
+int qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
+                                  virQEMUDriverConfigPtr cfg,
+                                  virDomainGraphicsDefPtr graphics,
+                                  bool allocate);
+
 #endif /* __QEMU_PROCESS_H__ */