qemu: Avoid deprecated migrate_set_speed QMP command

The same functionality can be achieved using migrate-set-parameters QMP
command with max-bandwidth parameter.

https://bugzilla.redhat.com/show_bug.cgi?id=1829545

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Jiri Denemark 2020-06-10 16:13:15 +02:00
parent 5fba42c21b
commit 92b8dbc66a
3 changed files with 59 additions and 16 deletions

View File

@ -14051,6 +14051,7 @@ qemuDomainMigrateSetMaxSpeed(virDomainPtr dom,
qemuDomainObjPrivatePtr priv; qemuDomainObjPrivatePtr priv;
bool postcopy = !!(flags & VIR_DOMAIN_MIGRATE_MAX_SPEED_POSTCOPY); bool postcopy = !!(flags & VIR_DOMAIN_MIGRATE_MAX_SPEED_POSTCOPY);
g_autoptr(qemuMigrationParams) migParams = NULL; g_autoptr(qemuMigrationParams) migParams = NULL;
bool bwParam;
unsigned long long max; unsigned long long max;
int ret = -1; int ret = -1;
@ -14089,12 +14090,20 @@ qemuDomainMigrateSetMaxSpeed(virDomainPtr dom,
VIR_DEBUG("Setting migration bandwidth to %luMbs", bandwidth); VIR_DEBUG("Setting migration bandwidth to %luMbs", bandwidth);
if (postcopy) { bwParam = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_MIGRATION_PARAM_BANDWIDTH);
if (postcopy || bwParam) {
qemuMigrationParam param;
if (!(migParams = qemuMigrationParamsNew())) if (!(migParams = qemuMigrationParamsNew()))
goto endjob; goto endjob;
if (qemuMigrationParamsSetULL(migParams, if (postcopy)
QEMU_MIGRATION_PARAM_MAX_POSTCOPY_BANDWIDTH, param = QEMU_MIGRATION_PARAM_MAX_POSTCOPY_BANDWIDTH;
else
param = QEMU_MIGRATION_PARAM_MAX_BANDWIDTH;
if (qemuMigrationParamsSetULL(migParams, param,
bandwidth * 1024 * 1024) < 0) bandwidth * 1024 * 1024) < 0)
goto endjob; goto endjob;
@ -14108,10 +14117,11 @@ qemuDomainMigrateSetMaxSpeed(virDomainPtr dom,
rc = qemuMonitorSetMigrationSpeed(priv->mon, bandwidth); rc = qemuMonitorSetMigrationSpeed(priv->mon, bandwidth);
if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
goto endjob; goto endjob;
priv->migMaxBandwidth = bandwidth;
} }
if (!postcopy)
priv->migMaxBandwidth = bandwidth;
ret = 0; ret = 0;
endjob: endjob:

View File

@ -3495,6 +3495,7 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
unsigned int cookieFlags = 0; unsigned int cookieFlags = 0;
bool abort_on_error = !!(flags & VIR_MIGRATE_ABORT_ON_ERROR); bool abort_on_error = !!(flags & VIR_MIGRATE_ABORT_ON_ERROR);
bool events = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_MIGRATION_EVENT); bool events = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_MIGRATION_EVENT);
bool bwParam = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_MIGRATION_PARAM_BANDWIDTH);
bool cancel = false; bool cancel = false;
unsigned int waitFlags; unsigned int waitFlags;
virDomainDefPtr persistDef = NULL; virDomainDefPtr persistDef = NULL;
@ -3582,6 +3583,11 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
goto error; goto error;
} }
if (bwParam &&
qemuMigrationParamsSetULL(migParams, QEMU_MIGRATION_PARAM_MAX_BANDWIDTH,
migrate_speed * 1024 * 1024) < 0)
goto error;
if (qemuMigrationParamsApply(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT, if (qemuMigrationParamsApply(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
migParams) < 0) migParams) < 0)
goto error; goto error;
@ -3644,7 +3650,8 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
goto exit_monitor; goto exit_monitor;
} }
if (qemuMonitorSetMigrationSpeed(priv->mon, migrate_speed) < 0) if (!bwParam &&
qemuMonitorSetMigrationSpeed(priv->mon, migrate_speed) < 0)
goto exit_monitor; goto exit_monitor;
/* connect to the destination qemu if needed */ /* connect to the destination qemu if needed */
@ -5299,18 +5306,34 @@ qemuMigrationSrcToFile(virQEMUDriverPtr driver, virDomainObjPtr vm,
qemuDomainAsyncJob asyncJob) qemuDomainAsyncJob asyncJob)
{ {
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
bool bwParam = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_MIGRATION_PARAM_BANDWIDTH);
int rc; int rc;
int ret = -1; int ret = -1;
int pipeFD[2] = { -1, -1 }; int pipeFD[2] = { -1, -1 };
unsigned long saveMigBandwidth = priv->migMaxBandwidth; unsigned long saveMigBandwidth = priv->migMaxBandwidth;
char *errbuf = NULL; char *errbuf = NULL;
virErrorPtr orig_err = NULL; virErrorPtr orig_err = NULL;
g_autoptr(qemuMigrationParams) migParams = NULL;
if (qemuMigrationSetDBusVMState(driver, vm) < 0) if (qemuMigrationSetDBusVMState(driver, vm) < 0)
return -1; return -1;
/* Increase migration bandwidth to unlimited since target is a file. /* Increase migration bandwidth to unlimited since target is a file.
* Failure to change migration speed is not fatal. */ * Failure to change migration speed is not fatal. */
if (bwParam) {
if (!(migParams = qemuMigrationParamsNew()))
return -1;
if (qemuMigrationParamsSetULL(migParams,
QEMU_MIGRATION_PARAM_MAX_BANDWIDTH,
QEMU_DOMAIN_MIG_BANDWIDTH_MAX * 1024 * 1024) < 0)
return -1;
if (qemuMigrationParamsApply(driver, vm, asyncJob, migParams) < 0)
return -1;
priv->migMaxBandwidth = QEMU_DOMAIN_MIG_BANDWIDTH_MAX;
} else {
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) == 0) { if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) == 0) {
qemuMonitorSetMigrationSpeed(priv->mon, qemuMonitorSetMigrationSpeed(priv->mon,
QEMU_DOMAIN_MIG_BANDWIDTH_MAX); QEMU_DOMAIN_MIG_BANDWIDTH_MAX);
@ -5318,6 +5341,7 @@ qemuMigrationSrcToFile(virQEMUDriverPtr driver, virDomainObjPtr vm,
if (qemuDomainObjExitMonitor(driver, vm) < 0) if (qemuDomainObjExitMonitor(driver, vm) < 0)
return -1; return -1;
} }
}
if (!virDomainObjIsActive(vm)) { if (!virDomainObjIsActive(vm)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -5397,12 +5421,21 @@ qemuMigrationSrcToFile(virQEMUDriverPtr driver, virDomainObjPtr vm,
virErrorPreserveLast(&orig_err); virErrorPreserveLast(&orig_err);
/* Restore max migration bandwidth */ /* Restore max migration bandwidth */
if (virDomainObjIsActive(vm) && if (virDomainObjIsActive(vm)) {
qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) == 0) { if (bwParam) {
if (qemuMigrationParamsSetULL(migParams,
QEMU_MIGRATION_PARAM_MAX_BANDWIDTH,
saveMigBandwidth * 1024 * 1024) == 0)
ignore_value(qemuMigrationParamsApply(driver, vm, asyncJob,
migParams));
} else {
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) == 0) {
qemuMonitorSetMigrationSpeed(priv->mon, saveMigBandwidth); qemuMonitorSetMigrationSpeed(priv->mon, saveMigBandwidth);
priv->migMaxBandwidth = saveMigBandwidth;
ignore_value(qemuDomainObjExitMonitor(driver, vm)); ignore_value(qemuDomainObjExitMonitor(driver, vm));
} }
}
priv->migMaxBandwidth = saveMigBandwidth;
}
VIR_FORCE_CLOSE(pipeFD[0]); VIR_FORCE_CLOSE(pipeFD[0]);
VIR_FORCE_CLOSE(pipeFD[1]); VIR_FORCE_CLOSE(pipeFD[1]);

View File

@ -3220,7 +3220,7 @@ mymain(void)
DO_TEST_GEN_DEPRECATED(qemuMonitorJSONChangeMedia, true); DO_TEST_GEN_DEPRECATED(qemuMonitorJSONChangeMedia, true);
DO_TEST_GEN(qemuMonitorJSONSaveVirtualMemory); DO_TEST_GEN(qemuMonitorJSONSaveVirtualMemory);
DO_TEST_GEN(qemuMonitorJSONSavePhysicalMemory); DO_TEST_GEN(qemuMonitorJSONSavePhysicalMemory);
DO_TEST_GEN_DEPRECATED(qemuMonitorJSONSetMigrationSpeed, false); DO_TEST_GEN_DEPRECATED(qemuMonitorJSONSetMigrationSpeed, true);
DO_TEST_GEN_DEPRECATED(qemuMonitorJSONSetMigrationDowntime, false); DO_TEST_GEN_DEPRECATED(qemuMonitorJSONSetMigrationDowntime, false);
DO_TEST_GEN(qemuMonitorJSONMigrate); DO_TEST_GEN(qemuMonitorJSONMigrate);
DO_TEST_GEN(qemuMonitorJSONDump); DO_TEST_GEN(qemuMonitorJSONDump);