提交 a14b4aea 编写于 作者: M Martin Kletzander

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
上级 ba9c38b4
......@@ -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");
......
......@@ -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,
......
......@@ -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;
......
......@@ -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,
......
......@@ -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;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册