Let's use virPortAllocatorRelease instead of virPortAllocatorSetUsed(false). --- src/bhyve/bhyve_command.c | 2 +- src/bhyve/bhyve_process.c | 2 +- src/qemu/qemu_process.c | 16 ++++++++-------- src/util/virportallocator.c | 22 ++++++---------------- src/util/virportallocator.h | 2 +- tests/bhyvexml2argvtest.c | 8 ++------ tests/libxlxml2domconfigtest.c | 8 ++------ 7 files changed, 21 insertions(+), 39 deletions(-) diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index 9d21788..d723cc2 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -411,7 +411,7 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def, return -1; graphics->data.vnc.port = port; } 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'", graphics->data.vnc.port, def->name); } diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c index 5e682fa..4ff6257 100644 --- a/src/bhyve/bhyve_process.c +++ b/src/bhyve/bhyve_process.c @@ -424,7 +424,7 @@ virBhyveProcessReconnect(virDomainObjPtr vm, if (vm->def->ngraphics == 1 && vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) { 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'", vnc_port, vm->def->name); } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index ddb699c..6c37f37 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4221,12 +4221,12 @@ qemuProcessGraphicsReservePorts(virDomainGraphicsDefPtr graphics, case VIR_DOMAIN_GRAPHICS_TYPE_VNC: if (!graphics->data.vnc.autoport || reconnect) { - if (virPortAllocatorSetUsed(graphics->data.vnc.port, true) < 0) + if (virPortAllocatorSetUsed(graphics->data.vnc.port) < 0) return -1; graphics->data.vnc.portReserved = true; } if (graphics->data.vnc.websocket > 0 && - virPortAllocatorSetUsed(graphics->data.vnc.websocket, true) < 0) + virPortAllocatorSetUsed(graphics->data.vnc.websocket) < 0) return -1; break; @@ -4235,13 +4235,13 @@ qemuProcessGraphicsReservePorts(virDomainGraphicsDefPtr graphics, return 0; if (graphics->data.spice.port > 0) { - if (virPortAllocatorSetUsed(graphics->data.spice.port, true) < 0) + if (virPortAllocatorSetUsed(graphics->data.spice.port) < 0) return -1; graphics->data.spice.portReserved = true; } if (graphics->data.spice.tlsPort > 0) { - if (virPortAllocatorSetUsed(graphics->data.spice.tlsPort, true) < 0) + if (virPortAllocatorSetUsed(graphics->data.spice.tlsPort) < 0) return -1; graphics->data.spice.tlsPortReserved = true; } @@ -6618,7 +6618,7 @@ void qemuProcessStop(virQEMUDriverPtr driver, if (graphics->data.vnc.autoport) { virPortAllocatorRelease(graphics->data.vnc.port); } else if (graphics->data.vnc.portReserved) { - virPortAllocatorSetUsed(graphics->data.spice.port, false); + virPortAllocatorRelease(graphics->data.spice.port); graphics->data.vnc.portReserved = false; } if (graphics->data.vnc.websocketGenerated) { @@ -6626,7 +6626,7 @@ void qemuProcessStop(virQEMUDriverPtr driver, graphics->data.vnc.websocketGenerated = false; graphics->data.vnc.websocket = -1; } 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) { @@ -6635,12 +6635,12 @@ void qemuProcessStop(virQEMUDriverPtr driver, virPortAllocatorRelease(graphics->data.spice.tlsPort); } else { if (graphics->data.spice.portReserved) { - virPortAllocatorSetUsed(graphics->data.spice.port, false); + virPortAllocatorRelease(graphics->data.spice.port); graphics->data.spice.portReserved = false; } if (graphics->data.spice.tlsPortReserved) { - virPortAllocatorSetUsed(graphics->data.spice.tlsPort, false); + virPortAllocatorRelease(graphics->data.spice.tlsPort); graphics->data.spice.tlsPortReserved = false; } } diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c index d800fdf..8620372 100644 --- a/src/util/virportallocator.c +++ b/src/util/virportallocator.c @@ -287,8 +287,7 @@ virPortAllocatorRelease(unsigned short port) } int -virPortAllocatorSetUsed(unsigned short port, - bool value) +virPortAllocatorSetUsed(unsigned short port) { int ret = -1; virPortAllocatorPtr pa = virPortAllocatorGet(); @@ -298,20 +297,11 @@ virPortAllocatorSetUsed(unsigned short port, virObjectLock(pa); - if (value) { - if (virBitmapIsBitSet(pa->bitmap, port) || - virBitmapSetBit(pa->bitmap, port) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to reserve port %d"), port); - goto cleanup; - } - } else { - if (virBitmapClearBit(pa->bitmap, port) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to release port %d"), - port); - goto cleanup; - } + if (virBitmapIsBitSet(pa->bitmap, port) || + virBitmapSetBit(pa->bitmap, port) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to reserve port %d"), port); + goto cleanup; } ret = 0; diff --git a/src/util/virportallocator.h b/src/util/virportallocator.h index 1d7505f..11696b7 100644 --- a/src/util/virportallocator.h +++ b/src/util/virportallocator.h @@ -40,6 +40,6 @@ int virPortAllocatorAcquire(virPortAllocatorRangePtr range, int virPortAllocatorRelease(unsigned short port); -int virPortAllocatorSetUsed(unsigned short port, bool value); +int virPortAllocatorSetUsed(unsigned short port); #endif /* __VIR_PORT_ALLOCATOR_H__ */ diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c index eb0f548..6f3b0c2 100644 --- a/tests/bhyvexml2argvtest.c +++ b/tests/bhyvexml2argvtest.c @@ -93,12 +93,8 @@ static int testCompareXMLToArgvFiles(const char *xml, out: if (vmdef && vmdef->ngraphics == 1 && - vmdef->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) { - if (vmdef->graphics[0]->data.vnc.autoport) - virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port); - else - virPortAllocatorSetUsed(vmdef->graphics[0]->data.vnc.port, false); - } + vmdef->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) + virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port); VIR_FREE(actualargv); VIR_FREE(actualld); diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c index 0dc5709..2e484c4 100644 --- a/tests/libxlxml2domconfigtest.c +++ b/tests/libxlxml2domconfigtest.c @@ -113,12 +113,8 @@ testCompareXMLToDomConfig(const char *xmlfile, cleanup: if (vmdef && vmdef->ngraphics == 1 && - vmdef->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) { - if (vmdef->graphics[0]->data.vnc.autoport) - virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port); - else - virPortAllocatorSetUsed(vmdef->graphics[0]->data.vnc.port, false); - } + vmdef->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) + virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port); VIR_FREE(expectjson); VIR_FREE(actualjson); -- 1.8.3.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list