mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +00:00
qemu: Rework starting NBD server for migration
Clean up the semantics by using one extra self-describing variable. This also fixes the port allocation when the port is specified. Signed-off-by: Martin Kletzander <mkletzan@redhat.com> Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
parent
e31f24e299
commit
e74d627bb3
@ -383,12 +383,13 @@ qemuMigrationDstStartNBDServer(virQEMUDriverPtr driver,
|
|||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
unsigned short port = 0;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
virStorageNetHostDef server = {
|
virStorageNetHostDef server = {
|
||||||
.name = (char *)listenAddr, /* cast away const */
|
.name = (char *)listenAddr, /* cast away const */
|
||||||
.transport = VIR_STORAGE_NET_HOST_TRANS_TCP,
|
.transport = VIR_STORAGE_NET_HOST_TRANS_TCP,
|
||||||
|
.port = nbdPort,
|
||||||
};
|
};
|
||||||
|
bool server_started = false;
|
||||||
|
|
||||||
if (nbdPort < 0 || nbdPort > USHRT_MAX) {
|
if (nbdPort < 0 || nbdPort > USHRT_MAX) {
|
||||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||||
@ -424,20 +425,27 @@ qemuMigrationDstStartNBDServer(virQEMUDriverPtr driver,
|
|||||||
devicename = diskAlias;
|
devicename = diskAlias;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!server_started) {
|
||||||
|
if (server.port) {
|
||||||
|
if (virPortAllocatorSetUsed(server.port) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
} else {
|
||||||
|
unsigned short port = 0;
|
||||||
|
|
||||||
|
if (virPortAllocatorAcquire(driver->migrationPorts, &port) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
server.port = port;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (qemuDomainObjEnterMonitorAsync(driver, vm,
|
if (qemuDomainObjEnterMonitorAsync(driver, vm,
|
||||||
QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
|
QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (port == 0) {
|
if (!server_started &&
|
||||||
if (nbdPort)
|
qemuMonitorNBDServerStart(priv->mon, &server, tls_alias) < 0)
|
||||||
port = nbdPort;
|
goto exit_monitor;
|
||||||
else if (virPortAllocatorAcquire(driver->migrationPorts, &port) < 0)
|
|
||||||
goto exit_monitor;
|
|
||||||
|
|
||||||
server.port = port;
|
|
||||||
if (qemuMonitorNBDServerStart(priv->mon, &server, tls_alias) < 0)
|
|
||||||
goto exit_monitor;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qemuMonitorNBDServerAdd(priv->mon, devicename, exportname, true, NULL) < 0)
|
if (qemuMonitorNBDServerAdd(priv->mon, devicename, exportname, true, NULL) < 0)
|
||||||
goto exit_monitor;
|
goto exit_monitor;
|
||||||
@ -445,12 +453,13 @@ qemuMigrationDstStartNBDServer(virQEMUDriverPtr driver,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
priv->nbdPort = port;
|
priv->nbdPort = server.port;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (ret < 0 && nbdPort == 0)
|
if (ret < 0)
|
||||||
virPortAllocatorRelease(port);
|
virPortAllocatorRelease(server.port);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
exit_monitor:
|
exit_monitor:
|
||||||
|
Loading…
Reference in New Issue
Block a user