From 658ce2c3d404d9faa06b82da56d3340f4bbdc6c3 Mon Sep 17 00:00:00 2001 From: Nikolay Shirokovskiy Date: Mon, 11 Apr 2022 15:02:42 +0300 Subject: [PATCH] qemu: cleanup code to release VNC port Code to release VNC port looks repetitive. The reason is there were originally 2 functions to release ports - for auto and non-auto cases. Also portReserved flag is not cleared on stop in case of reconnect with auto port (flags is set on reconnect in qemuProcessGraphicsReservePorts call). Yeah config is freed in the end of stopping domain but still. Let's use this flag whenever we reserve port (auto or not). This makes things clearer. Signed-off-by: Nikolay Shirokovskiy Reviewed-by: Martin Kletzander --- src/qemu/qemu_process.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 2e11d24be2..cae87cdeca 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3994,6 +3994,7 @@ qemuProcessVNCAllocatePorts(virQEMUDriver *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) { @@ -8261,9 +8262,7 @@ void qemuProcessStop(virQEMUDriver *driver, for (i = 0; i < vm->def->ngraphics; ++i) { virDomainGraphicsDef *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; }