port allocator: remove release functionality from set used

Let's use virPortAllocatorRelease instead of virPortAllocatorSetUsed(false).

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
This commit is contained in:
Nikolay Shirokovskiy 2018-02-06 12:09:10 +03:00 committed by Michal Privoznik
parent 4c9c7a5ba2
commit 5dbda5e972
7 changed files with 21 additions and 39 deletions

View File

@ -409,7 +409,7 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
return -1; return -1;
graphics->data.vnc.port = port; graphics->data.vnc.port = port;
} else { } else {
if (virPortAllocatorSetUsed(graphics->data.vnc.port, true) < 0) if (virPortAllocatorSetUsed(graphics->data.vnc.port) < 0)
VIR_WARN("Failed to mark VNC port '%d' as used by '%s'", VIR_WARN("Failed to mark VNC port '%d' as used by '%s'",
graphics->data.vnc.port, def->name); graphics->data.vnc.port, def->name);
} }

View File

@ -424,7 +424,7 @@ virBhyveProcessReconnect(virDomainObjPtr vm,
if (vm->def->ngraphics == 1 && if (vm->def->ngraphics == 1 &&
vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) { vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
int vnc_port = vm->def->graphics[0]->data.vnc.port; int vnc_port = vm->def->graphics[0]->data.vnc.port;
if (virPortAllocatorSetUsed(vnc_port, true) < 0) { if (virPortAllocatorSetUsed(vnc_port) < 0) {
VIR_WARN("Failed to mark VNC port '%d' as used by '%s'", VIR_WARN("Failed to mark VNC port '%d' as used by '%s'",
vnc_port, vm->def->name); vnc_port, vm->def->name);
} }

View File

@ -4244,12 +4244,12 @@ qemuProcessGraphicsReservePorts(virDomainGraphicsDefPtr graphics,
case VIR_DOMAIN_GRAPHICS_TYPE_VNC: case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
if (!graphics->data.vnc.autoport || if (!graphics->data.vnc.autoport ||
reconnect) { reconnect) {
if (virPortAllocatorSetUsed(graphics->data.vnc.port, true) < 0) if (virPortAllocatorSetUsed(graphics->data.vnc.port) < 0)
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, true) < 0) virPortAllocatorSetUsed(graphics->data.vnc.websocket) < 0)
return -1; return -1;
break; break;
@ -4258,13 +4258,13 @@ qemuProcessGraphicsReservePorts(virDomainGraphicsDefPtr graphics,
return 0; return 0;
if (graphics->data.spice.port > 0) { if (graphics->data.spice.port > 0) {
if (virPortAllocatorSetUsed(graphics->data.spice.port, true) < 0) if (virPortAllocatorSetUsed(graphics->data.spice.port) < 0)
return -1; return -1;
graphics->data.spice.portReserved = true; graphics->data.spice.portReserved = true;
} }
if (graphics->data.spice.tlsPort > 0) { if (graphics->data.spice.tlsPort > 0) {
if (virPortAllocatorSetUsed(graphics->data.spice.tlsPort, true) < 0) if (virPortAllocatorSetUsed(graphics->data.spice.tlsPort) < 0)
return -1; return -1;
graphics->data.spice.tlsPortReserved = true; graphics->data.spice.tlsPortReserved = true;
} }
@ -6731,7 +6731,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
if (graphics->data.vnc.autoport) { if (graphics->data.vnc.autoport) {
virPortAllocatorRelease(graphics->data.vnc.port); virPortAllocatorRelease(graphics->data.vnc.port);
} else if (graphics->data.vnc.portReserved) { } else if (graphics->data.vnc.portReserved) {
virPortAllocatorSetUsed(graphics->data.spice.port, false); virPortAllocatorRelease(graphics->data.spice.port);
graphics->data.vnc.portReserved = false; graphics->data.vnc.portReserved = false;
} }
if (graphics->data.vnc.websocketGenerated) { if (graphics->data.vnc.websocketGenerated) {
@ -6739,7 +6739,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
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.websocket) {
virPortAllocatorSetUsed(graphics->data.vnc.websocket, false); virPortAllocatorRelease(graphics->data.vnc.websocket);
} }
} }
if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
@ -6748,12 +6748,12 @@ void qemuProcessStop(virQEMUDriverPtr driver,
virPortAllocatorRelease(graphics->data.spice.tlsPort); virPortAllocatorRelease(graphics->data.spice.tlsPort);
} else { } else {
if (graphics->data.spice.portReserved) { if (graphics->data.spice.portReserved) {
virPortAllocatorSetUsed(graphics->data.spice.port, false); virPortAllocatorRelease(graphics->data.spice.port);
graphics->data.spice.portReserved = false; graphics->data.spice.portReserved = false;
} }
if (graphics->data.spice.tlsPortReserved) { if (graphics->data.spice.tlsPortReserved) {
virPortAllocatorSetUsed(graphics->data.spice.tlsPort, false); virPortAllocatorRelease(graphics->data.spice.tlsPort);
graphics->data.spice.tlsPortReserved = false; graphics->data.spice.tlsPortReserved = false;
} }
} }

View File

@ -287,8 +287,7 @@ virPortAllocatorRelease(unsigned short port)
} }
int int
virPortAllocatorSetUsed(unsigned short port, virPortAllocatorSetUsed(unsigned short port)
bool value)
{ {
int ret = -1; int ret = -1;
virPortAllocatorPtr pa = virPortAllocatorGet(); virPortAllocatorPtr pa = virPortAllocatorGet();
@ -298,21 +297,12 @@ virPortAllocatorSetUsed(unsigned short port,
virObjectLock(pa); virObjectLock(pa);
if (value) {
if (virBitmapIsBitSet(pa->bitmap, port) || if (virBitmapIsBitSet(pa->bitmap, port) ||
virBitmapSetBit(pa->bitmap, port) < 0) { virBitmapSetBit(pa->bitmap, port) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to reserve port %d"), port); _("Failed to reserve port %d"), port);
goto cleanup; goto cleanup;
} }
} else {
if (virBitmapClearBit(pa->bitmap, port) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to release port %d"),
port);
goto cleanup;
}
}
ret = 0; ret = 0;
cleanup: cleanup:

View File

@ -40,6 +40,6 @@ int virPortAllocatorAcquire(virPortAllocatorRangePtr range,
int virPortAllocatorRelease(unsigned short port); int virPortAllocatorRelease(unsigned short port);
int virPortAllocatorSetUsed(unsigned short port, bool value); int virPortAllocatorSetUsed(unsigned short port);
#endif /* __VIR_PORT_ALLOCATOR_H__ */ #endif /* __VIR_PORT_ALLOCATOR_H__ */

View File

@ -93,12 +93,8 @@ static int testCompareXMLToArgvFiles(const char *xml,
out: out:
if (vmdef && if (vmdef &&
vmdef->ngraphics == 1 && vmdef->ngraphics == 1 &&
vmdef->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) { vmdef->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC)
if (vmdef->graphics[0]->data.vnc.autoport)
virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port); virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port);
else
virPortAllocatorSetUsed(vmdef->graphics[0]->data.vnc.port, false);
}
VIR_FREE(actualargv); VIR_FREE(actualargv);
VIR_FREE(actualld); VIR_FREE(actualld);

View File

@ -113,12 +113,8 @@ testCompareXMLToDomConfig(const char *xmlfile,
cleanup: cleanup:
if (vmdef && if (vmdef &&
vmdef->ngraphics == 1 && vmdef->ngraphics == 1 &&
vmdef->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) { vmdef->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC)
if (vmdef->graphics[0]->data.vnc.autoport)
virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port); virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port);
else
virPortAllocatorSetUsed(vmdef->graphics[0]->data.vnc.port, false);
}
VIR_FREE(expectjson); VIR_FREE(expectjson);
VIR_FREE(actualjson); VIR_FREE(actualjson);