qemu: fix releasing VNC websocket port domain does not own

Scenario is with two domains with same VNC websocket port.

- start first domain
- start second, it will fail as port is occupied

As a result port will be released which breaks port reservation logic.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@openvz.org>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Nikolay Shirokovskiy 2022-04-11 15:25:25 +03:00
parent 658ce2c3d4
commit 2f99afbd9a
2 changed files with 7 additions and 4 deletions

View File

@ -1901,6 +1901,7 @@ struct _virDomainGraphicsDef {
bool portReserved; bool portReserved;
int websocket; int websocket;
bool websocketGenerated; bool websocketGenerated;
bool websocketReserved;
bool autoport; bool autoport;
char *keymap; char *keymap;
virDomainGraphicsAuthDef auth; virDomainGraphicsAuthDef auth;

View File

@ -4678,9 +4678,11 @@ qemuProcessGraphicsReservePorts(virDomainGraphicsDef *graphics,
return -1; return -1;
graphics->data.vnc.portReserved = true; graphics->data.vnc.portReserved = true;
} }
if (graphics->data.vnc.websocket > 0 && if (graphics->data.vnc.websocket > 0) {
virPortAllocatorSetUsed(graphics->data.vnc.websocket) < 0) if (virPortAllocatorSetUsed(graphics->data.vnc.websocket) < 0)
return -1; return -1;
graphics->data.vnc.websocketReserved = true;
}
break; break;
case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
@ -8270,7 +8272,7 @@ void qemuProcessStop(virQEMUDriver *driver,
virPortAllocatorRelease(graphics->data.vnc.websocket); virPortAllocatorRelease(graphics->data.vnc.websocket);
graphics->data.vnc.websocketGenerated = false; graphics->data.vnc.websocketGenerated = false;
graphics->data.vnc.websocket = -1; graphics->data.vnc.websocket = -1;
} else if (graphics->data.vnc.websocket) { } else if (graphics->data.vnc.websocketReserved) {
virPortAllocatorRelease(graphics->data.vnc.websocket); virPortAllocatorRelease(graphics->data.vnc.websocket);
} }
} }