From a14b4aea512d6c3a42af56207a65ef10ac4a12a1 Mon Sep 17 00:00:00 2001 From: Martin Kletzander Date: Mon, 18 Jun 2012 09:58:31 +0200 Subject: [PATCH] qemu: Unify port-wise SPICE and VNC behavior 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 | 2 +- src/qemu/qemu_command.h | 4 ++-- src/qemu/qemu_conf.h | 2 +- src/qemu/qemu_driver.c | 11 +++-------- src/qemu/qemu_process.c | 27 +++++++++++++-------------- 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c9f5a3c0ea..2840482be5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -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"); diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index e999bc79b6..14afd9bbad 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -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, diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 8a51471983..cfebe35a69 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -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; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 109d18dbbb..00eb444766 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -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, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 8a9f995918..4a13f6664f 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -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; } }