Originally port allocator have 2 functions to release ports: one
for for manually reserved ports and one for autoallocated ports. Thus
a bit complicated code of port releasing. Now we have only one releasing
function.
Let's use *reserved flag whenever we manually/automatically allocate
port so that we can use it later for releasing.
Actually we set *reserved flag on autoallocation already on reconnection,
which lead to uncleared flag on stop. So this step looks natural.
qemuProcessGraphicsReservePorts is called on reconnect. As a result
portReserved is set not only for manual ports but autoports too. Now
due to the way port releasing is written in qemuProcessStop portReserved
stays set for autoports after domain stop. Now imagine one redefine
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy(a)virtuozzo.com>
---
src/conf/domain_conf.h | 1 +
src/qemu/qemu_process.c | 48 ++++++++++++++++++++++--------------------------
2 files changed, 23 insertions(+), 26 deletions(-)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 41d2748..1da6b8f 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1610,6 +1610,7 @@ struct _virDomainGraphicsDef {
int port;
bool portReserved;
int websocket;
+ bool websocketReserved;
bool websocketGenerated;
bool autoport;
char *keymap;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index da5656d..de2e84b 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3628,12 +3628,14 @@ qemuProcessVNCAllocatePorts(virQEMUDriverPtr driver,
if (virPortAllocatorAcquire(driver->remotePorts, &port) < 0)
return -1;
graphics->data.vnc.port = port;
+ graphics->data.vnc.portReserved = true;
}
if (graphics->data.vnc.websocket == -1) {
if (virPortAllocatorAcquire(driver->webSocketPorts, &port) < 0)
return -1;
graphics->data.vnc.websocket = port;
+ graphics->data.vnc.websocketReserved = true;
graphics->data.vnc.websocketGenerated = true;
}
@@ -3705,9 +3707,7 @@ qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
goto cleanup;
graphics->data.spice.port = port;
-
- if (!graphics->data.spice.autoport)
- graphics->data.spice.portReserved = true;
+ graphics->data.spice.portReserved = true;
}
if (needTLSPort || graphics->data.spice.tlsPort == -1) {
@@ -3722,9 +3722,7 @@ qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
goto cleanup;
graphics->data.spice.tlsPort = tlsPort;
-
- if (!graphics->data.spice.autoport)
- graphics->data.spice.tlsPortReserved = true;
+ graphics->data.spice.tlsPortReserved = true;
}
ret = 0;
@@ -4328,9 +4326,11 @@ qemuProcessGraphicsReservePorts(virDomainGraphicsDefPtr graphics,
return -1;
graphics->data.vnc.portReserved = true;
}
- if (graphics->data.vnc.websocket > 0 &&
- virPortAllocatorSetUsed(graphics->data.vnc.websocket) < 0)
- return -1;
+ if (graphics->data.vnc.websocket > 0) {
+ if (virPortAllocatorSetUsed(graphics->data.vnc.websocket) < 0)
+ return -1;
+ graphics->data.vnc.websocketReserved = true;
+ }
break;
case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
@@ -6974,34 +6974,30 @@ void qemuProcessStop(virQEMUDriverPtr driver,
for (i = 0; i < vm->def->ngraphics; ++i) {
virDomainGraphicsDefPtr graphics = vm->def->graphics[i];
if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
- if (graphics->data.vnc.autoport) {
- virPortAllocatorRelease(graphics->data.vnc.port);
- } else if (graphics->data.vnc.portReserved) {
+ if (graphics->data.vnc.portReserved) {
virPortAllocatorRelease(graphics->data.vnc.port);
graphics->data.vnc.portReserved = false;
}
+
+ if (graphics->data.vnc.websocketReserved) {
+ virPortAllocatorRelease(graphics->data.vnc.websocket);
+ graphics->data.vnc.websocketReserved = false;
+ }
+
if (graphics->data.vnc.websocketGenerated) {
- virPortAllocatorRelease(graphics->data.vnc.websocket);
graphics->data.vnc.websocketGenerated = false;
graphics->data.vnc.websocket = -1;
- } else if (graphics->data.vnc.websocket) {
- virPortAllocatorRelease(graphics->data.vnc.websocket);
}
}
if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
- if (graphics->data.spice.autoport) {
+ if (graphics->data.spice.portReserved) {
virPortAllocatorRelease(graphics->data.spice.port);
+ graphics->data.spice.portReserved = false;
+ }
+
+ if (graphics->data.spice.tlsPortReserved) {
virPortAllocatorRelease(graphics->data.spice.tlsPort);
- } else {
- if (graphics->data.spice.portReserved) {
- virPortAllocatorRelease(graphics->data.spice.port);
- graphics->data.spice.portReserved = false;
- }
-
- if (graphics->data.spice.tlsPortReserved) {
- virPortAllocatorRelease(graphics->data.spice.tlsPort);
- graphics->data.spice.tlsPortReserved = false;
- }
+ graphics->data.spice.tlsPortReserved = false;
}
}
}
--
1.8.3.1