]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Unify port-wise SPICE and VNC behavior
authorMartin Kletzander <mkletzan@redhat.com>
Mon, 18 Jun 2012 07:58:31 +0000 (09:58 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Tue, 21 Aug 2012 09:36:32 +0000 (11:36 +0200)
Port allocations for SPICE and VNC behave almost the same (with
default ports), but there is some mess in the code. This patch clears
these inconsistencies and makes sure the same behavior will be used
when ports for remote displays are changed.

Changes:
 - hard-coded number 5900 removed (handled elsewhere like with VNC)
 - reservedVNCPorts renamed to reservedRemotePorts (it's not just for
   VNC anymore)
 - QEMU_VNC_PORT_{MIN,MAX} renamed to QEMU_REMOTE_PORT_{MIN,MAX}
 - port allocation unified for VNC and SPICE

src/conf/domain_conf.c
src/qemu/qemu_command.h
src/qemu/qemu_conf.h
src/qemu/qemu_driver.c
src/qemu/qemu_process.c

index c9f5a3c0eaeb67523ac4fa8a8e1cbfa2e7fcb47d..2840482be58a363e2dc20e9fac64733c7f9913cd 100644 (file)
@@ -6277,7 +6277,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
             }
             VIR_FREE(port);
         } else {
-            def->data.spice.port = 5900;
+            def->data.spice.port = 0;
         }
 
         tlsPort = virXMLPropString(node, "tlsPort");
index e999bc79b68e8784334667a479d0710f004d351a..14afd9bbad742bc838351667cfd982ffee1610db 100644 (file)
@@ -37,8 +37,8 @@
 # define QEMU_VIRTIO_SERIAL_PREFIX "virtio-serial"
 # define QEMU_FSDEV_HOST_PREFIX "fsdev-"
 
-# define QEMU_VNC_PORT_MIN  5900
-# define QEMU_VNC_PORT_MAX  65535
+# define QEMU_REMOTE_PORT_MIN  5900
+# define QEMU_REMOTE_PORT_MAX  65535
 
 
 virCommandPtr qemuBuildCommandLine(virConnectPtr conn,
index 8a5147198392504a2277c50147c17dd2b1f04f89..cfebe35a69902f241c8ba560be3df6a600500f9a 100644 (file)
@@ -135,7 +135,7 @@ struct qemud_driver {
     /* The devices which is are not in use by the host or any guest. */
     pciDeviceList *inactivePciHostdevs;
 
-    virBitmapPtr reservedVNCPorts;
+    virBitmapPtr reservedRemotePorts;
 
     virSysinfoDefPtr hostsysinfo;
 
index 109d18dbbbe5cf94192d0e3f29a1434e9f9d9aea..00eb4447664eaf36a954e93775e3844e5f703615 100644 (file)
@@ -591,8 +591,8 @@ qemudStartup(int privileged) {
         goto error;
 
     /* Allocate bitmap for vnc port reservation */
-    if ((qemu_driver->reservedVNCPorts =
-         virBitmapAlloc(QEMU_VNC_PORT_MAX - QEMU_VNC_PORT_MIN)) == NULL)
+    if ((qemu_driver->reservedRemotePorts =
+         virBitmapAlloc(QEMU_REMOTE_PORT_MAX - QEMU_REMOTE_PORT_MIN)) == NULL)
         goto out_of_memory;
 
     /* read the host sysinfo */
@@ -950,7 +950,7 @@ qemudShutdown(void) {
     virCapabilitiesFree(qemu_driver->caps);
 
     virDomainObjListDeinit(&qemu_driver->domains);
-    virBitmapFree(qemu_driver->reservedVNCPorts);
+    virBitmapFree(qemu_driver->reservedRemotePorts);
 
     virSysinfoDefFree(qemu_driver->hostsysinfo);
 
@@ -4927,11 +4927,6 @@ static char *qemuDomainXMLToNative(virConnectPtr conn,
         VIR_FREE(net->virtPortProfile);
         net->info.bootIndex = bootIndex;
     }
-    for (i = 0 ; i < def->ngraphics ; i++) {
-        if (def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
-            def->graphics[i]->data.vnc.autoport)
-            def->graphics[i]->data.vnc.port = QEMU_VNC_PORT_MIN;
-    }
 
     if (qemuCapsExtractVersionInfo(def->emulator, def->os.arch,
                                    false,
index 8a9f995918ccedafc106c8d17ab84be9aeefc7f2..4a13f6664f1b8ce0d437b948b0bda10073bfcf92 100644 (file)
@@ -2454,15 +2454,15 @@ static int qemuProcessNextFreePort(struct qemud_driver *driver,
 {
     int i;
 
-    for (i = startPort ; i < QEMU_VNC_PORT_MAX; i++) {
+    for (i = startPort ; i < QEMU_REMOTE_PORT_MAX; i++) {
         int fd;
         int reuse = 1;
         struct sockaddr_in addr;
         bool used = false;
 
-        if (virBitmapGetBit(driver->reservedVNCPorts,
-                            i - QEMU_VNC_PORT_MIN, &used) < 0)
-            VIR_DEBUG("virBitmapGetBit failed on bit %d", i - QEMU_VNC_PORT_MIN);
+        if (virBitmapGetBit(driver->reservedRemotePorts,
+                            i - QEMU_REMOTE_PORT_MIN, &used) < 0)
+            VIR_DEBUG("virBitmapGetBit failed on bit %d", i - QEMU_REMOTE_PORT_MIN);
 
         if (used)
             continue;
@@ -2483,10 +2483,10 @@ static int qemuProcessNextFreePort(struct qemud_driver *driver,
             /* Not in use, lets grab it */
             VIR_FORCE_CLOSE(fd);
             /* Add port to bitmap of reserved ports */
-            if (virBitmapSetBit(driver->reservedVNCPorts,
-                                i - QEMU_VNC_PORT_MIN) < 0) {
+            if (virBitmapSetBit(driver->reservedRemotePorts,
+                                i - QEMU_REMOTE_PORT_MIN) < 0) {
                 VIR_DEBUG("virBitmapSetBit failed on bit %d",
-                          i - QEMU_VNC_PORT_MIN);
+                          i - QEMU_REMOTE_PORT_MIN);
             }
             return i;
         }
@@ -2507,11 +2507,11 @@ static void
 qemuProcessReturnPort(struct qemud_driver *driver,
                       int port)
 {
-    if (port < QEMU_VNC_PORT_MIN)
+    if (port < QEMU_REMOTE_PORT_MIN)
         return;
 
-    if (virBitmapClearBit(driver->reservedVNCPorts,
-                          port - QEMU_VNC_PORT_MIN) < 0)
+    if (virBitmapClearBit(driver->reservedRemotePorts,
+                          port - QEMU_REMOTE_PORT_MIN) < 0)
         VIR_DEBUG("Could not mark port %d as unused", port);
 }
 
@@ -3417,7 +3417,7 @@ int qemuProcessStart(virConnectPtr conn,
         if (vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
             !vm->def->graphics[0]->data.vnc.socket &&
             vm->def->graphics[0]->data.vnc.autoport) {
-            int port = qemuProcessNextFreePort(driver, QEMU_VNC_PORT_MIN);
+            int port = qemuProcessNextFreePort(driver, QEMU_REMOTE_PORT_MIN);
             if (port < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                "%s", _("Unable to find an unused VNC port"));
@@ -3428,7 +3428,7 @@ int qemuProcessStart(virConnectPtr conn,
             int port = -1;
             if (vm->def->graphics[0]->data.spice.autoport ||
                 vm->def->graphics[0]->data.spice.port == -1) {
-                port = qemuProcessNextFreePort(driver, QEMU_VNC_PORT_MIN);
+                port = qemuProcessNextFreePort(driver, QEMU_REMOTE_PORT_MIN);
 
                 if (port < 0) {
                     virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -3438,7 +3438,6 @@ int qemuProcessStart(virConnectPtr conn,
 
                 vm->def->graphics[0]->data.spice.port = port;
             }
-
             if (driver->spiceTLS &&
                 (vm->def->graphics[0]->data.spice.autoport ||
                  vm->def->graphics[0]->data.spice.tlsPort == -1)) {
@@ -3451,7 +3450,7 @@ int qemuProcessStart(virConnectPtr conn,
                     goto cleanup;
                 }
 
-                vm->def->graphics[0]->data.spice.tlsPort = tlsPort;
+                vm->def->graphics[0]->data.spice.tlsPort = port;
             }
         }