graphics: remember graphics not auto allocated ports

When looking for a port to allocate, the port allocator didn't take in
consideration ports that are statically set by the user.  Defining
these two graphics elements in the XML would cause an error, as the
port allocator would try to use the same port for the spice graphics
element:

    <graphics type='spice' autoport='yes'/>
    <graphics type='vnc' port='5900' autoport='no'/>

The new *[pP]ortReserved variables keep track of the ports that were
successfully tracked as used by the port allocator but that weren't
bound.

Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1081881

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2014-06-24 13:34:18 +02:00 committed by Michal Privoznik
parent 1d8d2fbcd0
commit 1a065caa79
2 changed files with 65 additions and 6 deletions

View File

@ -1385,6 +1385,7 @@ struct _virDomainGraphicsDef {
union { union {
struct { struct {
int port; int port;
bool portReserved;
int websocket; int websocket;
bool autoport; bool autoport;
char *keymap; char *keymap;
@ -1410,6 +1411,8 @@ struct _virDomainGraphicsDef {
struct { struct {
int port; int port;
int tlsPort; int tlsPort;
bool portReserved;
bool tlsPortReserved;
int mousemode; int mousemode;
char *keymap; char *keymap;
virDomainGraphicsAuthDef auth; virDomainGraphicsAuthDef auth;

View File

@ -3801,6 +3801,41 @@ int qemuProcessStart(virConnectPtr conn,
VIR_DEBUG("Ensuring no historical cgroup is lying around"); VIR_DEBUG("Ensuring no historical cgroup is lying around");
qemuRemoveCgroup(vm); qemuRemoveCgroup(vm);
for (i = 0; i < vm->def->ngraphics; ++i) {
virDomainGraphicsDefPtr graphics = vm->def->graphics[i];
if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
!graphics->data.vnc.autoport) {
if (virPortAllocatorSetUsed(driver->remotePorts,
graphics->data.vnc.port,
true) < 0) {
goto cleanup;
}
graphics->data.vnc.portReserved = true;
} else if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE &&
!graphics->data.spice.autoport) {
if (graphics->data.spice.port > 0) {
if (virPortAllocatorSetUsed(driver->remotePorts,
graphics->data.spice.port,
true) < 0)
goto cleanup;
graphics->data.spice.portReserved = true;
}
if (graphics->data.spice.tlsPort > 0) {
if (virPortAllocatorSetUsed(driver->remotePorts,
graphics->data.spice.tlsPort,
true) < 0)
goto cleanup;
graphics->data.spice.tlsPortReserved = true;
}
}
}
for (i = 0; i < vm->def->ngraphics; ++i) { for (i = 0; i < vm->def->ngraphics; ++i) {
virDomainGraphicsDefPtr graphics = vm->def->graphics[i]; virDomainGraphicsDefPtr graphics = vm->def->graphics[i];
if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) { if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
@ -4513,15 +4548,36 @@ void qemuProcessStop(virQEMUDriverPtr driver,
virPortAllocatorRelease(driver->remotePorts, virPortAllocatorRelease(driver->remotePorts,
graphics->data.vnc.port); graphics->data.vnc.port);
} }
else if (graphics->data.vnc.portReserved) {
virPortAllocatorSetUsed(driver->remotePorts,
graphics->data.spice.port,
false);
graphics->data.vnc.portReserved = false;
}
virPortAllocatorRelease(driver->webSocketPorts, virPortAllocatorRelease(driver->webSocketPorts,
graphics->data.vnc.websocket); graphics->data.vnc.websocket);
} }
if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE && if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
graphics->data.spice.autoport) { if (graphics->data.spice.autoport) {
virPortAllocatorRelease(driver->remotePorts, virPortAllocatorRelease(driver->remotePorts,
graphics->data.spice.port); graphics->data.spice.port);
virPortAllocatorRelease(driver->remotePorts, virPortAllocatorRelease(driver->remotePorts,
graphics->data.spice.tlsPort); graphics->data.spice.tlsPort);
} else {
if (graphics->data.spice.portReserved) {
virPortAllocatorSetUsed(driver->remotePorts,
graphics->data.spice.port,
false);
graphics->data.spice.portReserved = false;
}
if (graphics->data.spice.tlsPortReserved) {
virPortAllocatorSetUsed(driver->remotePorts,
graphics->data.spice.tlsPort,
false);
graphics->data.spice.tlsPortReserved = false;
}
}
} }
} }