[libvirt PATCH 0/3] Ensure synchronous behavior of migrate_cancel

See 3/3 for details. Jiri Denemark (3): qemu: Rename qemuMigrationSrcCancel qemu: Create wrapper for qemuMonitorMigrateCancel qemu: Make qemuMigrationSrcCancel optionally synchronous src/qemu/qemu_driver.c | 9 +---- src/qemu/qemu_migration.c | 76 +++++++++++++++++++++++++++++++-------- src/qemu/qemu_migration.h | 7 +++- src/qemu/qemu_process.c | 7 ++-- 4 files changed, 70 insertions(+), 29 deletions(-) -- 2.37.2

Let's call this qemuMigrationSrcCancelUnattended as the function is supposed to be used when no other thread is watching the migration. Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- src/qemu/qemu_migration.c | 2 +- src/qemu/qemu_migration.h | 2 +- src/qemu/qemu_process.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index b3b25d78b4..67d83ca743 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -6943,7 +6943,7 @@ qemuMigrationSrcToFile(virQEMUDriver *driver, virDomainObj *vm, int -qemuMigrationSrcCancel(virDomainObj *vm) +qemuMigrationSrcCancelUnattended(virDomainObj *vm) { qemuDomainObjPrivate *priv = vm->privateData; bool storage = false; diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h index d518889c19..bbc71d118d 100644 --- a/src/qemu/qemu_migration.h +++ b/src/qemu/qemu_migration.h @@ -241,7 +241,7 @@ qemuMigrationSrcToFile(virQEMUDriver *driver, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; int -qemuMigrationSrcCancel(virDomainObj *vm); +qemuMigrationSrcCancelUnattended(virDomainObj *vm); int qemuMigrationAnyFetchStats(virDomainObj *vm, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 32f03ff79a..4e8daf83fe 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3537,7 +3537,7 @@ qemuProcessRecoverMigrationOut(virQEMUDriver *driver, */ VIR_DEBUG("Cancelling unfinished migration of domain %s", vm->def->name); - if (qemuMigrationSrcCancel(vm) < 0) { + if (qemuMigrationSrcCancelUnattended(vm) < 0) { VIR_WARN("Could not cancel ongoing migration of domain %s", vm->def->name); } -- 2.37.2

On Thu, Sep 01, 2022 at 14:47:39 +0200, Jiri Denemark wrote:
Let's call this qemuMigrationSrcCancelUnattended as the function is supposed to be used when no other thread is watching the migration.
Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- src/qemu/qemu_migration.c | 2 +- src/qemu/qemu_migration.h | 2 +- src/qemu/qemu_process.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index b3b25d78b4..67d83ca743 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -6943,7 +6943,7 @@ qemuMigrationSrcToFile(virQEMUDriver *driver, virDomainObj *vm,
int
Maybe you should also add a function description here so that it's obvious. Or at least that the docs don't stay in the commit message only.
-qemuMigrationSrcCancel(virDomainObj *vm) +qemuMigrationSrcCancelUnattended(virDomainObj *vm) { qemuDomainObjPrivate *priv = vm->privateData; bool storage = false;
Reviewed-by: Peter Krempa <pkrempa@redhat.com>

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@redhat.com> --- 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

On Thu, Sep 01, 2022 at 14:47:40 +0200, Jiri Denemark wrote:
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@redhat.com> --- 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);
So this caller cared about the return value of 'qemuMonitorMigrateCancel' ...
- 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);
... but here you don't propagate it out. Instead the only possibility for this function to fail is from 'qemuDomainObjEnterMonitorAsync', but any caller that pases non-NONE asyncjob doesn't care about the return value at all.
+ qemuDomainObjExitMonitor(vm); + + return 0; +} + +
Also consider adding a comment too. With the above bug fixed: Reviewed-by: Peter Krempa <pkrempa@redhat.com>

We have always considered "migrate_cancel" QMP command to return after successfully cancelling the migration. But this is no longer true (to be honest I'm not sure it ever was) as it just changes the migration state to "cancelling". In most cases the migration is canceled pretty quickly and we don't really notice anything, but sometimes it takes so long we even get to clearing migration capabilities before the migration is actually canceled, which fails as capabilities can only be changed when no migration is running. So to avoid this issue, we can wait for the migration to be really canceled after sending migrate_cancel. The only place where we don't need synchronous behavior is when we're cancelling migration on user's request while it is actively watched by another thread. https://bugzilla.redhat.com/show_bug.cgi?id=2114866 Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_migration.c | 45 +++++++++++++++++++++++++++++++++++---- src/qemu/qemu_migration.h | 3 ++- src/qemu/qemu_process.c | 2 +- 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a86efc769a..71a1de19b8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12811,7 +12811,7 @@ qemuDomainAbortJobMigration(virDomainObj *vm) VIR_DEBUG("Cancelling migration job at client request"); qemuDomainObjAbortAsyncJob(vm); - return qemuMigrationSrcCancel(vm, VIR_ASYNC_JOB_NONE); + return qemuMigrationSrcCancel(vm, VIR_ASYNC_JOB_NONE, false); } diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 5845dfdb9c..83c3ca4dcf 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -4611,9 +4611,37 @@ qemuMigrationSrcStart(virDomainObj *vm, } +static bool +qemuMigrationSrcIsCanceled(virDomainObj *vm) +{ + qemuDomainObjPrivate *priv = vm->privateData; + virDomainJobData *jobData = priv->job.current; + + qemuMigrationUpdateJobType(jobData); + switch (jobData->status) { + case VIR_DOMAIN_JOB_STATUS_FAILED: + case VIR_DOMAIN_JOB_STATUS_CANCELED: + case VIR_DOMAIN_JOB_STATUS_COMPLETED: + case VIR_DOMAIN_JOB_STATUS_NONE: + return true; + + case VIR_DOMAIN_JOB_STATUS_MIGRATING: + case VIR_DOMAIN_JOB_STATUS_POSTCOPY: + case VIR_DOMAIN_JOB_STATUS_PAUSED: + case VIR_DOMAIN_JOB_STATUS_HYPERVISOR_COMPLETED: + case VIR_DOMAIN_JOB_STATUS_POSTCOPY_PAUSED: + case VIR_DOMAIN_JOB_STATUS_ACTIVE: + break; + } + + return false; +} + + int qemuMigrationSrcCancel(virDomainObj *vm, - virDomainAsyncJob asyncJob) + virDomainAsyncJob asyncJob, + bool wait) { qemuDomainObjPrivate *priv = vm->privateData; @@ -4625,6 +4653,15 @@ qemuMigrationSrcCancel(virDomainObj *vm, qemuMonitorMigrateCancel(priv->mon); qemuDomainObjExitMonitor(vm); + if (virDomainObjIsActive(vm) && wait) { + VIR_DEBUG("Waiting for migration to be canceled"); + + while (!qemuMigrationSrcIsCanceled(vm)) { + if (qemuDomainObjWait(vm) < 0) + return -1; + } + } + return 0; } @@ -4971,7 +5008,7 @@ qemuMigrationSrcRun(virQEMUDriver *driver, if (cancel && priv->job.current->status != VIR_DOMAIN_JOB_STATUS_HYPERVISOR_COMPLETED) - qemuMigrationSrcCancel(vm, VIR_ASYNC_JOB_MIGRATION_OUT); + qemuMigrationSrcCancel(vm, VIR_ASYNC_JOB_MIGRATION_OUT, true); /* cancel any outstanding NBD jobs */ if (mig && mig->nbd) @@ -6916,7 +6953,7 @@ qemuMigrationSrcToFile(virQEMUDriver *driver, virDomainObj *vm, virErrorPreserveLast(&orig_err); virCommandAbort(compressor); if (virDomainObjIsActive(vm)) - qemuMigrationSrcCancel(vm, asyncJob); + qemuMigrationSrcCancel(vm, asyncJob, true); } goto cleanup; } @@ -6963,7 +7000,7 @@ qemuMigrationSrcCancelUnattended(virDomainObj *vm) VIR_DEBUG("Canceling unfinished outgoing migration of domain %s", vm->def->name); - qemuMigrationSrcCancel(vm, VIR_ASYNC_JOB_NONE); + qemuMigrationSrcCancel(vm, VIR_ASYNC_JOB_NONE, true); 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 31a5547399..fbea45ad4e 100644 --- a/src/qemu/qemu_migration.h +++ b/src/qemu/qemu_migration.h @@ -245,7 +245,8 @@ qemuMigrationSrcCancelUnattended(virDomainObj *vm); int qemuMigrationSrcCancel(virDomainObj *vm, - virDomainAsyncJob asyncJob); + virDomainAsyncJob asyncJob, + bool wait); int qemuMigrationAnyFetchStats(virDomainObj *vm, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 4465fa89e9..08eefd0fba 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3696,7 +3696,7 @@ qemuProcessRecoverJob(virQEMUDriver *driver, case VIR_ASYNC_JOB_SAVE: case VIR_ASYNC_JOB_DUMP: case VIR_ASYNC_JOB_SNAPSHOT: - qemuMigrationSrcCancel(vm, VIR_ASYNC_JOB_NONE); + qemuMigrationSrcCancel(vm, VIR_ASYNC_JOB_NONE, true); /* 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

On Thu, Sep 01, 2022 at 14:47:41 +0200, Jiri Denemark wrote:
We have always considered "migrate_cancel" QMP command to return after successfully cancelling the migration. But this is no longer true (to be honest I'm not sure it ever was) as it just changes the migration state to "cancelling". In most cases the migration is canceled pretty quickly and we don't really notice anything, but sometimes it takes so long we even get to clearing migration capabilities before the migration is actually canceled, which fails as capabilities can only be changed when no migration is running. So to avoid this issue, we can wait for the migration to be really canceled after sending migrate_cancel. The only place where we don't need synchronous behavior is when we're cancelling migration on user's request while it is actively watched by another thread.
https://bugzilla.redhat.com/show_bug.cgi?id=2114866
Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_migration.c | 45 +++++++++++++++++++++++++++++++++++---- src/qemu/qemu_migration.h | 3 ++- src/qemu/qemu_process.c | 2 +- 4 files changed, 45 insertions(+), 7 deletions(-)
[...]
int qemuMigrationSrcCancel(virDomainObj *vm, - virDomainAsyncJob asyncJob) + virDomainAsyncJob asyncJob, + bool wait) { qemuDomainObjPrivate *priv = vm->privateData;
@@ -4625,6 +4653,15 @@ qemuMigrationSrcCancel(virDomainObj *vm, qemuMonitorMigrateCancel(priv->mon); qemuDomainObjExitMonitor(vm);
+ if (virDomainObjIsActive(vm) && wait) {
Is the call to virDomainObjIsActive() necessary here? IIUC the domain shutdown code is always executed in a way to make sure that waiting threads are always woken.
+ VIR_DEBUG("Waiting for migration to be canceled"); + + while (!qemuMigrationSrcIsCanceled(vm)) { + if (qemuDomainObjWait(vm) < 0)
So here if the VM would crash before we wait we'd report success and if it crashed during our wait we'll report failure, which seems weird too.
+ return -1; + }
The rest of the patch looks okay.

On Thu, Sep 01, 2022 at 16:51:34 +0200, Peter Krempa wrote:
On Thu, Sep 01, 2022 at 14:47:41 +0200, Jiri Denemark wrote:
We have always considered "migrate_cancel" QMP command to return after successfully cancelling the migration. But this is no longer true (to be honest I'm not sure it ever was) as it just changes the migration state to "cancelling". In most cases the migration is canceled pretty quickly and we don't really notice anything, but sometimes it takes so long we even get to clearing migration capabilities before the migration is actually canceled, which fails as capabilities can only be changed when no migration is running. So to avoid this issue, we can wait for the migration to be really canceled after sending migrate_cancel. The only place where we don't need synchronous behavior is when we're cancelling migration on user's request while it is actively watched by another thread.
https://bugzilla.redhat.com/show_bug.cgi?id=2114866
Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_migration.c | 45 +++++++++++++++++++++++++++++++++++---- src/qemu/qemu_migration.h | 3 ++- src/qemu/qemu_process.c | 2 +- 4 files changed, 45 insertions(+), 7 deletions(-)
[...]
int qemuMigrationSrcCancel(virDomainObj *vm, - virDomainAsyncJob asyncJob) + virDomainAsyncJob asyncJob, + bool wait) { qemuDomainObjPrivate *priv = vm->privateData;
@@ -4625,6 +4653,15 @@ qemuMigrationSrcCancel(virDomainObj *vm, qemuMonitorMigrateCancel(priv->mon); qemuDomainObjExitMonitor(vm);
+ if (virDomainObjIsActive(vm) && wait) {
Is the call to virDomainObjIsActive() necessary here? IIUC the domain shutdown code is always executed in a way to make sure that waiting threads are always woken.
+ VIR_DEBUG("Waiting for migration to be canceled"); + + while (!qemuMigrationSrcIsCanceled(vm)) { + if (qemuDomainObjWait(vm) < 0)
So here if the VM would crash before we wait we'd report success and if it crashed during our wait we'll report failure, which seems weird too.
Oh right, qemuDomainObjWait already checks for virDomainObjIsActive so we don't have to do it explicitly here. Just if (wait) { ... } is enough. Jirka

On Thu, Sep 01, 2022 at 17:18:55 +0200, Jiri Denemark wrote:
On Thu, Sep 01, 2022 at 16:51:34 +0200, Peter Krempa wrote:
On Thu, Sep 01, 2022 at 14:47:41 +0200, Jiri Denemark wrote:
We have always considered "migrate_cancel" QMP command to return after successfully cancelling the migration. But this is no longer true (to be honest I'm not sure it ever was) as it just changes the migration state to "cancelling". In most cases the migration is canceled pretty quickly and we don't really notice anything, but sometimes it takes so long we even get to clearing migration capabilities before the migration is actually canceled, which fails as capabilities can only be changed when no migration is running. So to avoid this issue, we can wait for the migration to be really canceled after sending migrate_cancel. The only place where we don't need synchronous behavior is when we're cancelling migration on user's request while it is actively watched by another thread.
https://bugzilla.redhat.com/show_bug.cgi?id=2114866
Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_migration.c | 45 +++++++++++++++++++++++++++++++++++---- src/qemu/qemu_migration.h | 3 ++- src/qemu/qemu_process.c | 2 +- 4 files changed, 45 insertions(+), 7 deletions(-)
[...]
int qemuMigrationSrcCancel(virDomainObj *vm, - virDomainAsyncJob asyncJob) + virDomainAsyncJob asyncJob, + bool wait) { qemuDomainObjPrivate *priv = vm->privateData;
@@ -4625,6 +4653,15 @@ qemuMigrationSrcCancel(virDomainObj *vm, qemuMonitorMigrateCancel(priv->mon); qemuDomainObjExitMonitor(vm);
+ if (virDomainObjIsActive(vm) && wait) {
Is the call to virDomainObjIsActive() necessary here? IIUC the domain shutdown code is always executed in a way to make sure that waiting threads are always woken.
+ VIR_DEBUG("Waiting for migration to be canceled"); + + while (!qemuMigrationSrcIsCanceled(vm)) { + if (qemuDomainObjWait(vm) < 0)
So here if the VM would crash before we wait we'd report success and if it crashed during our wait we'll report failure, which seems weird too.
Oh right, qemuDomainObjWait already checks for virDomainObjIsActive so we don't have to do it explicitly here. Just
if (wait) { ... }
is enough.
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
participants (2)
-
Jiri Denemark
-
Peter Krempa