]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Move success-only code out of endjob in qemuMigrationDstFinish
authorJiri Denemark <jdenemar@redhat.com>
Tue, 10 May 2022 13:20:25 +0000 (15:20 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 7 Jun 2022 15:40:20 +0000 (17:40 +0200)
Code executed only when dom != NULL can be moved before "endjob" label,
to the only place where dom is set.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/qemu/qemu_migration.c

index 29302128eab570daed23d047c91539e199cadc2d..a0c788cc5b8afb95bf27ea2280a86adb3b5208c5 100644 (file)
@@ -5813,8 +5813,16 @@ qemuMigrationDstFinish(virQEMUDriver *driver,
 
     if (flags & VIR_MIGRATE_OFFLINE) {
         if (retcode == 0 &&
-            qemuMigrationDstPersist(driver, vm, mig, false) == 0)
+            qemuMigrationDstPersist(driver, vm, mig, false) == 0) {
             dom = virGetDomain(dconn, vm->def->name, vm->def->uuid, -1);
+
+            if (dom &&
+                qemuMigrationCookieFormat(mig, driver, vm,
+                                          QEMU_MIGRATION_DESTINATION,
+                                          cookieout, cookieoutlen,
+                                          QEMU_MIGRATION_COOKIE_STATS) < 0)
+                VIR_WARN("Unable to encode migration cookie");
+        }
         goto endjob;
     }
 
@@ -5977,6 +5985,25 @@ qemuMigrationDstFinish(virQEMUDriver *driver,
     /* Guest is successfully running, so cancel previous auto destroy */
     qemuProcessAutoDestroyRemove(driver, vm);
 
+    if (jobData) {
+        priv->job.completed = g_steal_pointer(&jobData);
+        priv->job.completed->status = VIR_DOMAIN_JOB_STATUS_COMPLETED;
+        qemuDomainJobSetStatsType(priv->job.completed,
+                                  QEMU_DOMAIN_JOB_STATS_TYPE_MIGRATION);
+    }
+
+    if (qemuMigrationCookieFormat(mig, driver, vm,
+                                  QEMU_MIGRATION_DESTINATION,
+                                  cookieout, cookieoutlen,
+                                  QEMU_MIGRATION_COOKIE_STATS) < 0)
+        VIR_WARN("Unable to encode migration cookie");
+
+    /* Remove completed stats for post-copy, everything but timing fields
+     * is obsolete anyway.
+     */
+    if (inPostCopy)
+        g_clear_pointer(&priv->job.completed, virDomainJobDataFree);
+
     dom = virGetDomain(dconn, vm->def->name, vm->def->uuid, vm->def->id);
 
  endjob:
@@ -5997,27 +6024,6 @@ qemuMigrationDstFinish(virQEMUDriver *driver,
         }
     }
 
-    if (dom) {
-        if (jobData) {
-            priv->job.completed = g_steal_pointer(&jobData);
-            priv->job.completed->status = VIR_DOMAIN_JOB_STATUS_COMPLETED;
-            qemuDomainJobSetStatsType(priv->job.completed,
-                                      QEMU_DOMAIN_JOB_STATS_TYPE_MIGRATION);
-        }
-
-        if (qemuMigrationCookieFormat(mig, driver, vm,
-                                      QEMU_MIGRATION_DESTINATION,
-                                      cookieout, cookieoutlen,
-                                      QEMU_MIGRATION_COOKIE_STATS) < 0)
-            VIR_WARN("Unable to encode migration cookie");
-
-        /* Remove completed stats for post-copy, everything but timing fields
-         * is obsolete anyway.
-         */
-        if (inPostCopy)
-            g_clear_pointer(&priv->job.completed, virDomainJobDataFree);
-    }
-
     if (virDomainObjIsFailedPostcopy(vm)) {
         qemuProcessAutoDestroyRemove(driver, vm);
         qemuDomainCleanupAdd(vm, qemuProcessCleanupMigrationJob);