port allocator: remove range on manual port reserving

Range check in virPortAllocatorSetUsed is not useful anymore
when we manage ports for entire unsigned short range values.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
This commit is contained in:
Nikolay Shirokovskiy 2018-02-06 12:09:07 +03:00 committed by Michal Privoznik
parent 7ebc4f2a4c
commit 853e1542ac
7 changed files with 17 additions and 49 deletions

View File

@ -409,9 +409,7 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
return -1; return -1;
graphics->data.vnc.port = port; graphics->data.vnc.port = port;
} else { } else {
if (virPortAllocatorSetUsed(driver->remotePorts, if (virPortAllocatorSetUsed(graphics->data.vnc.port, true) < 0)
graphics->data.vnc.port,
true) < 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

@ -425,9 +425,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(data->driver->remotePorts, if (virPortAllocatorSetUsed(vnc_port, true) < 0) {
vnc_port,
true) < 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

@ -4226,8 +4226,7 @@ qemuProcessStartHook(virQEMUDriverPtr driver,
static int static int
qemuProcessGraphicsReservePorts(virQEMUDriverPtr driver, qemuProcessGraphicsReservePorts(virDomainGraphicsDefPtr graphics,
virDomainGraphicsDefPtr graphics,
bool reconnect) bool reconnect)
{ {
virDomainGraphicsListenDefPtr glisten; virDomainGraphicsListenDefPtr glisten;
@ -4245,16 +4244,12 @@ qemuProcessGraphicsReservePorts(virQEMUDriverPtr driver,
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(driver->remotePorts, if (virPortAllocatorSetUsed(graphics->data.vnc.port, true) < 0)
graphics->data.vnc.port,
true) < 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(driver->remotePorts, virPortAllocatorSetUsed(graphics->data.vnc.websocket, true) < 0)
graphics->data.vnc.websocket,
true) < 0)
return -1; return -1;
break; break;
@ -4263,17 +4258,13 @@ qemuProcessGraphicsReservePorts(virQEMUDriverPtr driver,
return 0; return 0;
if (graphics->data.spice.port > 0) { if (graphics->data.spice.port > 0) {
if (virPortAllocatorSetUsed(driver->remotePorts, if (virPortAllocatorSetUsed(graphics->data.spice.port, true) < 0)
graphics->data.spice.port,
true) < 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(driver->remotePorts, if (virPortAllocatorSetUsed(graphics->data.spice.tlsPort, true) < 0)
graphics->data.spice.tlsPort,
true) < 0)
return -1; return -1;
graphics->data.spice.tlsPortReserved = true; graphics->data.spice.tlsPortReserved = true;
} }
@ -4553,7 +4544,7 @@ qemuProcessSetupGraphics(virQEMUDriverPtr driver,
for (i = 0; i < vm->def->ngraphics; i++) { for (i = 0; i < vm->def->ngraphics; i++) {
graphics = vm->def->graphics[i]; graphics = vm->def->graphics[i];
if (qemuProcessGraphicsReservePorts(driver, graphics, false) < 0) if (qemuProcessGraphicsReservePorts(graphics, false) < 0)
goto cleanup; goto cleanup;
} }
} }
@ -6741,9 +6732,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
virPortAllocatorRelease(driver->remotePorts, virPortAllocatorRelease(driver->remotePorts,
graphics->data.vnc.port); graphics->data.vnc.port);
} else if (graphics->data.vnc.portReserved) { } else if (graphics->data.vnc.portReserved) {
virPortAllocatorSetUsed(driver->remotePorts, virPortAllocatorSetUsed(graphics->data.spice.port, false);
graphics->data.spice.port,
false);
graphics->data.vnc.portReserved = false; graphics->data.vnc.portReserved = false;
} }
if (graphics->data.vnc.websocketGenerated) { if (graphics->data.vnc.websocketGenerated) {
@ -6752,9 +6741,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(driver->remotePorts, virPortAllocatorSetUsed(graphics->data.vnc.websocket, false);
graphics->data.vnc.websocket,
false);
} }
} }
if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
@ -6765,16 +6752,12 @@ void qemuProcessStop(virQEMUDriverPtr driver,
graphics->data.spice.tlsPort); graphics->data.spice.tlsPort);
} else { } else {
if (graphics->data.spice.portReserved) { if (graphics->data.spice.portReserved) {
virPortAllocatorSetUsed(driver->remotePorts, virPortAllocatorSetUsed(graphics->data.spice.port, false);
graphics->data.spice.port,
false);
graphics->data.spice.portReserved = false; graphics->data.spice.portReserved = false;
} }
if (graphics->data.spice.tlsPortReserved) { if (graphics->data.spice.tlsPortReserved) {
virPortAllocatorSetUsed(driver->remotePorts, virPortAllocatorSetUsed(graphics->data.spice.tlsPort, false);
graphics->data.spice.tlsPort,
false);
graphics->data.spice.tlsPortReserved = false; graphics->data.spice.tlsPortReserved = false;
} }
} }
@ -7365,9 +7348,7 @@ qemuProcessReconnect(void *opaque)
} }
for (i = 0; i < obj->def->ngraphics; i++) { for (i = 0; i < obj->def->ngraphics; i++) {
if (qemuProcessGraphicsReservePorts(driver, if (qemuProcessGraphicsReservePorts(obj->def->graphics[i], true) < 0)
obj->def->graphics[i],
true) < 0)
goto error; goto error;
} }

View File

@ -301,8 +301,7 @@ virPortAllocatorRelease(virPortAllocatorRangePtr range,
} }
int int
virPortAllocatorSetUsed(virPortAllocatorRangePtr range, virPortAllocatorSetUsed(unsigned short port,
unsigned short port,
bool value) bool value)
{ {
int ret = -1; int ret = -1;
@ -313,12 +312,6 @@ virPortAllocatorSetUsed(virPortAllocatorRangePtr range,
virObjectLock(pa); virObjectLock(pa);
if (port < range->start ||
port > range->end) {
ret = 0;
goto cleanup;
}
if (value) { if (value) {
if (virBitmapIsBitSet(pa->bitmap, port) || if (virBitmapIsBitSet(pa->bitmap, port) ||
virBitmapSetBit(pa->bitmap, port) < 0) { virBitmapSetBit(pa->bitmap, port) < 0) {

View File

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

View File

@ -97,7 +97,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
if (vmdef->graphics[0]->data.vnc.autoport) if (vmdef->graphics[0]->data.vnc.autoport)
virPortAllocatorRelease(gports, vmdef->graphics[0]->data.vnc.port); virPortAllocatorRelease(gports, vmdef->graphics[0]->data.vnc.port);
else else
virPortAllocatorSetUsed(gports, vmdef->graphics[0]->data.vnc.port, false); virPortAllocatorSetUsed(vmdef->graphics[0]->data.vnc.port, false);
} }
VIR_FREE(actualargv); VIR_FREE(actualargv);

View File

@ -118,7 +118,7 @@ testCompareXMLToDomConfig(const char *xmlfile,
if (vmdef->graphics[0]->data.vnc.autoport) if (vmdef->graphics[0]->data.vnc.autoport)
virPortAllocatorRelease(gports, vmdef->graphics[0]->data.vnc.port); virPortAllocatorRelease(gports, vmdef->graphics[0]->data.vnc.port);
else else
virPortAllocatorSetUsed(gports, vmdef->graphics[0]->data.vnc.port, false); virPortAllocatorSetUsed(vmdef->graphics[0]->data.vnc.port, false);
} }
VIR_FREE(expectjson); VIR_FREE(expectjson);