[libvirt] [PATCH 06/10] Support automatic port number allocation for SPICE

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

 



* src/qemu/qemu_driver.c: Allocate the TCP ports for SPICE
  before starting guest
---
 src/qemu/qemu_driver.c |   36 ++++++++++++++++++++++++------------
 1 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index df1d435..2aa39c1 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2594,10 +2594,10 @@ qemuInitPCIAddresses(struct qemud_driver *driver,
     return ret;
 }
 
-static int qemudNextFreeVNCPort(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
+static int qemudNextFreePort(int startPort) {
     int i;
 
-    for (i = 5900 ; i < 65535 ; i++) {
+    for (i = startPort ; i < 65535 ; i++) {
         int fd;
         int reuse = 1;
         struct sockaddr_in addr;
@@ -3200,17 +3200,29 @@ static int qemudStartVMDaemon(virConnectPtr conn,
     DEBUG0("Ensuring no historical cgroup is lying around");
     qemuRemoveCgroup(driver, vm, 1);
 
-    if ((vm->def->ngraphics == 1) &&
-        vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
-        vm->def->graphics[0]->data.vnc.autoport) {
-        DEBUG0("Determining VNC port");
-        int port = qemudNextFreeVNCPort(driver);
-        if (port < 0) {
-            qemuReportError(VIR_ERR_INTERNAL_ERROR,
-                            "%s", _("Unable to find an unused VNC port"));
-            goto cleanup;
+    if (vm->def->ngraphics == 1) {
+        if (vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
+            vm->def->graphics[0]->data.vnc.autoport) {
+            int port = qemudNextFreePort(5900);
+            if (port < 0) {
+                qemuReportError(VIR_ERR_INTERNAL_ERROR,
+                                "%s", _("Unable to find an unused VNC port"));
+                goto cleanup;
+            }
+            vm->def->graphics[0]->data.vnc.port = port;
+        } else if (vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE &&
+                   vm->def->graphics[0]->data.spice.autoport) {
+            int port = qemudNextFreePort(5900);
+            int tlsPort = port == -1 ? -1 : qemudNextFreePort(port + 1);
+            if (port < 0 || tlsPort < 0) {
+                qemuReportError(VIR_ERR_INTERNAL_ERROR,
+                                "%s", _("Unable to find an unused SPICE ports"));
+                goto cleanup;
+            }
+
+            vm->def->graphics[0]->data.spice.port = port;
+            vm->def->graphics[0]->data.spice.tlsPort = tlsPort;
         }
-        vm->def->graphics[0]->data.vnc.port = port;
     }
 
     if (virFileMakePath(driver->logDir) != 0) {
-- 
1.6.6.1

--
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]