We will need a little bit more code around qemuMonitorMigrateCancel to make sure it works as expected. The new qemuMigrationSrcCancel helper will avoid repeating the code in several places. Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx> --- src/qemu/qemu_driver.c | 9 +-------- src/qemu/qemu_migration.c | 37 +++++++++++++++++++++++-------------- src/qemu/qemu_migration.h | 4 ++++ src/qemu/qemu_process.c | 5 +---- 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 707f4cc1bb..a86efc769a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12808,17 +12808,10 @@ qemuDomainGetJobStats(virDomainPtr dom, static int qemuDomainAbortJobMigration(virDomainObj *vm) { - qemuDomainObjPrivate *priv = vm->privateData; - int ret; - VIR_DEBUG("Cancelling migration job at client request"); qemuDomainObjAbortAsyncJob(vm); - qemuDomainObjEnterMonitor(vm); - ret = qemuMonitorMigrateCancel(priv->mon); - qemuDomainObjExitMonitor(vm); - - return ret; + return qemuMigrationSrcCancel(vm, VIR_ASYNC_JOB_NONE); } diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 67d83ca743..5845dfdb9c 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -4611,6 +4611,24 @@ qemuMigrationSrcStart(virDomainObj *vm, } +int +qemuMigrationSrcCancel(virDomainObj *vm, + virDomainAsyncJob asyncJob) +{ + qemuDomainObjPrivate *priv = vm->privateData; + + VIR_DEBUG("Cancelling outgoing migration of domain %s", vm->def->name); + + if (qemuDomainObjEnterMonitorAsync(vm, asyncJob) < 0) + return -1; + + qemuMonitorMigrateCancel(priv->mon); + qemuDomainObjExitMonitor(vm); + + return 0; +} + + static int qemuMigrationSrcRun(virQEMUDriver *driver, virDomainObj *vm, @@ -4952,11 +4970,8 @@ qemuMigrationSrcRun(virQEMUDriver *driver, } if (cancel && - priv->job.current->status != VIR_DOMAIN_JOB_STATUS_HYPERVISOR_COMPLETED && - qemuDomainObjEnterMonitorAsync(vm, VIR_ASYNC_JOB_MIGRATION_OUT) == 0) { - qemuMonitorMigrateCancel(priv->mon); - qemuDomainObjExitMonitor(vm); - } + priv->job.current->status != VIR_DOMAIN_JOB_STATUS_HYPERVISOR_COMPLETED) + qemuMigrationSrcCancel(vm, VIR_ASYNC_JOB_MIGRATION_OUT); /* cancel any outstanding NBD jobs */ if (mig && mig->nbd) @@ -6900,11 +6915,8 @@ qemuMigrationSrcToFile(virQEMUDriver *driver, virDomainObj *vm, if (rc == -2) { virErrorPreserveLast(&orig_err); virCommandAbort(compressor); - if (virDomainObjIsActive(vm) && - qemuDomainObjEnterMonitorAsync(vm, asyncJob) == 0) { - qemuMonitorMigrateCancel(priv->mon); - qemuDomainObjExitMonitor(vm); - } + if (virDomainObjIsActive(vm)) + qemuMigrationSrcCancel(vm, asyncJob); } goto cleanup; } @@ -6945,16 +6957,13 @@ qemuMigrationSrcToFile(virQEMUDriver *driver, virDomainObj *vm, int qemuMigrationSrcCancelUnattended(virDomainObj *vm) { - qemuDomainObjPrivate *priv = vm->privateData; bool storage = false; size_t i; VIR_DEBUG("Canceling unfinished outgoing migration of domain %s", vm->def->name); - qemuDomainObjEnterMonitor(vm); - ignore_value(qemuMonitorMigrateCancel(priv->mon)); - qemuDomainObjExitMonitor(vm); + qemuMigrationSrcCancel(vm, VIR_ASYNC_JOB_NONE); for (i = 0; i < vm->def->ndisks; i++) { virDomainDiskDef *disk = vm->def->disks[i]; diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h index bbc71d118d..31a5547399 100644 --- a/src/qemu/qemu_migration.h +++ b/src/qemu/qemu_migration.h @@ -243,6 +243,10 @@ qemuMigrationSrcToFile(virQEMUDriver *driver, int qemuMigrationSrcCancelUnattended(virDomainObj *vm); +int +qemuMigrationSrcCancel(virDomainObj *vm, + virDomainAsyncJob asyncJob); + int qemuMigrationAnyFetchStats(virDomainObj *vm, virDomainAsyncJob asyncJob, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 4e8daf83fe..4465fa89e9 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3674,7 +3674,6 @@ qemuProcessRecoverJob(virQEMUDriver *driver, virDomainJobObj *job, unsigned int *stopFlags) { - qemuDomainObjPrivate *priv = vm->privateData; virDomainState state; int reason; @@ -3697,9 +3696,7 @@ qemuProcessRecoverJob(virQEMUDriver *driver, case VIR_ASYNC_JOB_SAVE: case VIR_ASYNC_JOB_DUMP: case VIR_ASYNC_JOB_SNAPSHOT: - qemuDomainObjEnterMonitor(vm); - ignore_value(qemuMonitorMigrateCancel(priv->mon)); - qemuDomainObjExitMonitor(vm); + qemuMigrationSrcCancel(vm, VIR_ASYNC_JOB_NONE); /* resume the domain but only if it was paused as a result of * running a migration-to-file operation. Although we are * recovering an async job, this function is run at startup -- 2.37.2