Migration is a job which takes some time and if it succeeds, there's
nothing to call another migration on. If a migration fails, it might
make sense to rerun it with different arguments, but this would only be
done once the first migration fails rather than while it is still
running.

If this was not enough, the migration job now stays active even if
post-copy migration fails and anyone possibly retrying the migration
would be waiting for the job timeout just to get a suboptimal error
message.

So let's special case getting a migration job when another one is
already active.

Signed-off-by: Jiri Denemark <jdene...@redhat.com>
---
 src/qemu/qemu_migration.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 63ebc15f65..72a2846d1f 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -82,6 +82,23 @@ VIR_ENUM_IMPL(qemuMigrationJobPhase,
 );
 
 
+static bool ATTRIBUTE_NONNULL(1)
+qemuMigrationJobIsAllowed(virDomainObj *vm)
+{
+    qemuDomainObjPrivate *priv = vm->privateData;
+
+    if (priv->job.asyncJob == VIR_ASYNC_JOB_MIGRATION_IN ||
+        priv->job.asyncJob == VIR_ASYNC_JOB_MIGRATION_OUT) {
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       _("another migration job is already running for domain 
'%s'"),
+                       vm->def->name);
+        return false;
+    }
+
+    return true;
+}
+
+
 static int ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT
 qemuMigrationJobStart(virQEMUDriver *driver,
                       virDomainObj *vm,
@@ -92,6 +109,9 @@ qemuMigrationJobStart(virQEMUDriver *driver,
     virDomainJobOperation op;
     unsigned long long mask;
 
+    if (!qemuMigrationJobIsAllowed(vm))
+        return -1;
+
     if (job == VIR_ASYNC_JOB_MIGRATION_IN) {
         op = VIR_DOMAIN_JOB_OPERATION_MIGRATION_IN;
         mask = VIR_JOB_NONE;
@@ -2629,6 +2649,9 @@ qemuMigrationSrcBegin(virConnectPtr conn,
             goto cleanup;
         asyncJob = VIR_ASYNC_JOB_MIGRATION_OUT;
     } else {
+        if (!qemuMigrationJobIsAllowed(vm))
+            goto cleanup;
+
         if (qemuDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
             goto cleanup;
         asyncJob = VIR_ASYNC_JOB_NONE;
-- 
2.35.1

Reply via email to