mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
port allocator: remove range check in release function
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:
parent
853e1542ac
commit
56def261da
@ -296,8 +296,7 @@ virBhyveProcessStop(bhyveConnPtr driver,
|
|||||||
/* VNC autoport cleanup */
|
/* VNC autoport cleanup */
|
||||||
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) {
|
||||||
if (virPortAllocatorRelease(driver->remotePorts,
|
if (virPortAllocatorRelease(vm->def->graphics[0]->data.vnc.port) < 0) {
|
||||||
vm->def->graphics[0]->data.vnc.port) < 0) {
|
|
||||||
VIR_WARN("Failed to release VNC port for '%s'",
|
VIR_WARN("Failed to release VNC port for '%s'",
|
||||||
vm->def->name);
|
vm->def->name);
|
||||||
}
|
}
|
||||||
|
@ -777,8 +777,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
|
|||||||
vm->def->graphics[0]->data.vnc.autoport) {
|
vm->def->graphics[0]->data.vnc.autoport) {
|
||||||
vnc_port = vm->def->graphics[0]->data.vnc.port;
|
vnc_port = vm->def->graphics[0]->data.vnc.port;
|
||||||
if (vnc_port >= LIBXL_VNC_PORT_MIN) {
|
if (vnc_port >= LIBXL_VNC_PORT_MIN) {
|
||||||
if (virPortAllocatorRelease(driver->reservedGraphicsPorts,
|
if (virPortAllocatorRelease(vnc_port) < 0)
|
||||||
vnc_port) < 0)
|
|
||||||
VIR_DEBUG("Could not mark port %d as unused", vnc_port);
|
VIR_DEBUG("Could not mark port %d as unused", vnc_port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -805,7 +805,7 @@ libxlDomainMigrationPrepare(virConnectPtr dconn,
|
|||||||
}
|
}
|
||||||
VIR_FREE(socks);
|
VIR_FREE(socks);
|
||||||
virObjectUnref(args);
|
virObjectUnref(args);
|
||||||
virPortAllocatorRelease(driver->migrationPorts, priv->migrationPort);
|
virPortAllocatorRelease(priv->migrationPort);
|
||||||
priv->migrationPort = 0;
|
priv->migrationPort = 0;
|
||||||
|
|
||||||
/* Remove virDomainObj from domain list */
|
/* Remove virDomainObj from domain list */
|
||||||
@ -1262,7 +1262,7 @@ libxlDomainMigrationFinish(virConnectPtr dconn,
|
|||||||
virObjectEventPtr event = NULL;
|
virObjectEventPtr event = NULL;
|
||||||
virDomainPtr dom = NULL;
|
virDomainPtr dom = NULL;
|
||||||
|
|
||||||
virPortAllocatorRelease(driver->migrationPorts, priv->migrationPort);
|
virPortAllocatorRelease(priv->migrationPort);
|
||||||
priv->migrationPort = 0;
|
priv->migrationPort = 0;
|
||||||
|
|
||||||
if (cancelled)
|
if (cancelled)
|
||||||
|
@ -582,7 +582,7 @@ qemuMigrationDstStartNBDServer(virQEMUDriverPtr driver,
|
|||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(diskAlias);
|
VIR_FREE(diskAlias);
|
||||||
if (ret < 0 && nbdPort == 0)
|
if (ret < 0 && nbdPort == 0)
|
||||||
virPortAllocatorRelease(driver->migrationPorts, port);
|
virPortAllocatorRelease(port);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
exit_monitor:
|
exit_monitor:
|
||||||
@ -610,7 +610,7 @@ qemuMigrationDstStopNBDServer(virQEMUDriverPtr driver,
|
|||||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
virPortAllocatorRelease(driver->migrationPorts, priv->nbdPort);
|
virPortAllocatorRelease(priv->nbdPort);
|
||||||
priv->nbdPort = 0;
|
priv->nbdPort = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -2270,7 +2270,7 @@ qemuMigrationDstPrepareCleanup(virQEMUDriverPtr driver,
|
|||||||
qemuDomainJobTypeToString(priv->job.active),
|
qemuDomainJobTypeToString(priv->job.active),
|
||||||
qemuDomainAsyncJobTypeToString(priv->job.asyncJob));
|
qemuDomainAsyncJobTypeToString(priv->job.asyncJob));
|
||||||
|
|
||||||
virPortAllocatorRelease(driver->migrationPorts, priv->migrationPort);
|
virPortAllocatorRelease(priv->migrationPort);
|
||||||
priv->migrationPort = 0;
|
priv->migrationPort = 0;
|
||||||
|
|
||||||
if (!qemuMigrationJobIsActive(vm, QEMU_ASYNC_JOB_MIGRATION_IN))
|
if (!qemuMigrationJobIsActive(vm, QEMU_ASYNC_JOB_MIGRATION_IN))
|
||||||
@ -2949,7 +2949,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
|
|||||||
* it is given in parameters
|
* it is given in parameters
|
||||||
*/
|
*/
|
||||||
if (nbdPort == 0)
|
if (nbdPort == 0)
|
||||||
virPortAllocatorRelease(driver->migrationPorts, priv->nbdPort);
|
virPortAllocatorRelease(priv->nbdPort);
|
||||||
priv->nbdPort = 0;
|
priv->nbdPort = 0;
|
||||||
virDomainObjRemoveTransientDef(vm);
|
virDomainObjRemoveTransientDef(vm);
|
||||||
qemuDomainRemoveInactiveJob(driver, vm);
|
qemuDomainRemoveInactiveJob(driver, vm);
|
||||||
@ -3190,7 +3190,7 @@ qemuMigrationDstPrepareDirect(virQEMUDriverPtr driver,
|
|||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
VIR_FREE(*uri_out);
|
VIR_FREE(*uri_out);
|
||||||
if (autoPort)
|
if (autoPort)
|
||||||
virPortAllocatorRelease(driver->migrationPorts, port);
|
virPortAllocatorRelease(port);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -5554,7 +5554,7 @@ qemuMigrationDstFinish(virQEMUDriverPtr driver,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(jobInfo);
|
VIR_FREE(jobInfo);
|
||||||
virPortAllocatorRelease(driver->migrationPorts, port);
|
virPortAllocatorRelease(port);
|
||||||
if (priv->mon)
|
if (priv->mon)
|
||||||
qemuMonitorSetDomainLog(priv->mon, NULL, NULL, NULL);
|
qemuMonitorSetDomainLog(priv->mon, NULL, NULL, NULL);
|
||||||
VIR_FREE(priv->origname);
|
VIR_FREE(priv->origname);
|
||||||
|
@ -6568,7 +6568,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virPortAllocatorRelease(driver->migrationPorts, priv->nbdPort);
|
virPortAllocatorRelease(priv->nbdPort);
|
||||||
priv->nbdPort = 0;
|
priv->nbdPort = 0;
|
||||||
|
|
||||||
if (priv->agent) {
|
if (priv->agent) {
|
||||||
@ -6729,15 +6729,13 @@ void qemuProcessStop(virQEMUDriverPtr driver,
|
|||||||
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) {
|
||||||
if (graphics->data.vnc.autoport) {
|
if (graphics->data.vnc.autoport) {
|
||||||
virPortAllocatorRelease(driver->remotePorts,
|
virPortAllocatorRelease(graphics->data.vnc.port);
|
||||||
graphics->data.vnc.port);
|
|
||||||
} else if (graphics->data.vnc.portReserved) {
|
} else if (graphics->data.vnc.portReserved) {
|
||||||
virPortAllocatorSetUsed(graphics->data.spice.port, false);
|
virPortAllocatorSetUsed(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) {
|
||||||
virPortAllocatorRelease(driver->webSocketPorts,
|
virPortAllocatorRelease(graphics->data.vnc.websocket);
|
||||||
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.websocket) {
|
||||||
@ -6746,10 +6744,8 @@ void qemuProcessStop(virQEMUDriverPtr driver,
|
|||||||
}
|
}
|
||||||
if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
|
if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
|
||||||
if (graphics->data.spice.autoport) {
|
if (graphics->data.spice.autoport) {
|
||||||
virPortAllocatorRelease(driver->remotePorts,
|
virPortAllocatorRelease(graphics->data.spice.port);
|
||||||
graphics->data.spice.port);
|
virPortAllocatorRelease(graphics->data.spice.tlsPort);
|
||||||
virPortAllocatorRelease(driver->remotePorts,
|
|
||||||
graphics->data.spice.tlsPort);
|
|
||||||
} else {
|
} else {
|
||||||
if (graphics->data.spice.portReserved) {
|
if (graphics->data.spice.portReserved) {
|
||||||
virPortAllocatorSetUsed(graphics->data.spice.port, false);
|
virPortAllocatorSetUsed(graphics->data.spice.port, false);
|
||||||
|
@ -266,8 +266,7 @@ virPortAllocatorAcquire(virPortAllocatorRangePtr range,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
virPortAllocatorRelease(virPortAllocatorRangePtr range,
|
virPortAllocatorRelease(unsigned short port)
|
||||||
unsigned short port)
|
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virPortAllocatorPtr pa = virPortAllocatorGet();
|
virPortAllocatorPtr pa = virPortAllocatorGet();
|
||||||
@ -280,13 +279,6 @@ virPortAllocatorRelease(virPortAllocatorRangePtr range,
|
|||||||
|
|
||||||
virObjectLock(pa);
|
virObjectLock(pa);
|
||||||
|
|
||||||
if (port < range->start ||
|
|
||||||
port > range->end) {
|
|
||||||
virReportInvalidArg(port, "port %d must be in range (%d, %d)",
|
|
||||||
port, range->start, range->end);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virBitmapClearBit(pa->bitmap, port) < 0) {
|
if (virBitmapClearBit(pa->bitmap, port) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Failed to release port %d"),
|
_("Failed to release port %d"),
|
||||||
|
@ -43,8 +43,7 @@ void virPortAllocatorRangeFree(virPortAllocatorRangePtr range);
|
|||||||
int virPortAllocatorAcquire(virPortAllocatorRangePtr range,
|
int virPortAllocatorAcquire(virPortAllocatorRangePtr range,
|
||||||
unsigned short *port);
|
unsigned short *port);
|
||||||
|
|
||||||
int virPortAllocatorRelease(virPortAllocatorRangePtr range,
|
int virPortAllocatorRelease(unsigned short port);
|
||||||
unsigned short port);
|
|
||||||
|
|
||||||
int virPortAllocatorSetUsed(unsigned short port, bool value);
|
int virPortAllocatorSetUsed(unsigned short port, bool value);
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
|||||||
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)
|
if (vmdef->graphics[0]->data.vnc.autoport)
|
||||||
virPortAllocatorRelease(gports, vmdef->graphics[0]->data.vnc.port);
|
virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port);
|
||||||
else
|
else
|
||||||
virPortAllocatorSetUsed(vmdef->graphics[0]->data.vnc.port, false);
|
virPortAllocatorSetUsed(vmdef->graphics[0]->data.vnc.port, false);
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ testCompareXMLToDomConfig(const char *xmlfile,
|
|||||||
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)
|
if (vmdef->graphics[0]->data.vnc.autoport)
|
||||||
virPortAllocatorRelease(gports, vmdef->graphics[0]->data.vnc.port);
|
virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port);
|
||||||
else
|
else
|
||||||
virPortAllocatorSetUsed(vmdef->graphics[0]->data.vnc.port, false);
|
virPortAllocatorSetUsed(vmdef->graphics[0]->data.vnc.port, false);
|
||||||
}
|
}
|
||||||
|
@ -98,13 +98,13 @@ static int testAllocAll(const void *args ATTRIBUTE_UNUSED)
|
|||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
virPortAllocatorRelease(ports, p1);
|
virPortAllocatorRelease(p1);
|
||||||
virPortAllocatorRelease(ports, p2);
|
virPortAllocatorRelease(p2);
|
||||||
virPortAllocatorRelease(ports, p3);
|
virPortAllocatorRelease(p3);
|
||||||
virPortAllocatorRelease(ports, p4);
|
virPortAllocatorRelease(p4);
|
||||||
virPortAllocatorRelease(ports, p5);
|
virPortAllocatorRelease(p5);
|
||||||
virPortAllocatorRelease(ports, p6);
|
virPortAllocatorRelease(p6);
|
||||||
virPortAllocatorRelease(ports, p7);
|
virPortAllocatorRelease(p7);
|
||||||
|
|
||||||
virPortAllocatorRangeFree(ports);
|
virPortAllocatorRangeFree(ports);
|
||||||
return ret;
|
return ret;
|
||||||
@ -142,8 +142,7 @@ static int testAllocReuse(const void *args ATTRIBUTE_UNUSED)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (virPortAllocatorRelease(p2) < 0)
|
||||||
if (virPortAllocatorRelease(ports, p2) < 0)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virPortAllocatorAcquire(ports, &p4) < 0)
|
if (virPortAllocatorAcquire(ports, &p4) < 0)
|
||||||
@ -155,9 +154,9 @@ static int testAllocReuse(const void *args ATTRIBUTE_UNUSED)
|
|||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
virPortAllocatorRelease(ports, p1);
|
virPortAllocatorRelease(p1);
|
||||||
virPortAllocatorRelease(ports, p3);
|
virPortAllocatorRelease(p3);
|
||||||
virPortAllocatorRelease(ports, p4);
|
virPortAllocatorRelease(p4);
|
||||||
|
|
||||||
virPortAllocatorRangeFree(ports);
|
virPortAllocatorRangeFree(ports);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user