[libvirt] [PATCH 3/7] qemu: Split cleanup and error code in qemuMigrationRun

Jiri Denemark jdenemar at redhat.com
Thu Oct 19 13:56:28 UTC 2017


Let cleanup only do things common to both failure and success paths and
move error handling code inside the new "error" section.

Signed-off-by: Jiri Denemark <jdenemar at redhat.com>
---
 src/qemu/qemu_migration.c | 79 ++++++++++++++++++++++++-----------------------
 1 file changed, 40 insertions(+), 39 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index f0d4f9d98..6956901be 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3657,20 +3657,20 @@ qemuMigrationRun(virQEMUDriverPtr driver,
         if (persist_xml) {
             if (!(persistDef = qemuMigrationPrepareDef(driver, persist_xml,
                                                        NULL, NULL)))
-                goto cleanup;
+                goto error;
         } else {
             virDomainDefPtr def = vm->newDef ? vm->newDef : vm->def;
             if (!(persistDef = qemuDomainDefCopy(driver, def,
                                                  VIR_DOMAIN_XML_SECURE |
                                                  VIR_DOMAIN_XML_MIGRATABLE)))
-                goto cleanup;
+                goto error;
         }
     }
 
     mig = qemuMigrationEatCookie(driver, vm, cookiein, cookieinlen,
                                  cookieFlags | QEMU_MIGRATION_COOKIE_GRAPHICS);
     if (!mig)
-        goto cleanup;
+        goto error;
 
     if (qemuDomainMigrateGraphicsRelocate(driver, vm, mig, graphicsuri) < 0)
         VIR_WARN("unable to provide data for graphics client relocation");
@@ -3683,7 +3683,7 @@ qemuMigrationRun(virQEMUDriverPtr driver,
         if (qemuMigrationAddTLSObjects(driver, vm, cfg, false,
                                        QEMU_ASYNC_JOB_MIGRATION_OUT,
                                        &tlsAlias, &secAlias, migParams) < 0)
-            goto cleanup;
+            goto error;
 
         /* We need to add tls-hostname whenever QEMU itself does not
          * connect directly to the destination. */
@@ -3691,17 +3691,17 @@ qemuMigrationRun(virQEMUDriverPtr driver,
             spec->destType == MIGRATION_DEST_FD) {
             if (VIR_STRDUP(migParams->migrateTLSHostname,
                            spec->dest.host.name) < 0)
-                goto cleanup;
+                goto error;
         } else {
             /* Be sure there's nothing from a previous migration */
             if (VIR_STRDUP(migParams->migrateTLSHostname, "") < 0)
-                goto cleanup;
+                goto error;
         }
     } else {
         if (qemuMigrationSetEmptyTLSParams(driver, vm,
                                            QEMU_ASYNC_JOB_MIGRATION_OUT,
                                            migParams) < 0)
-            goto cleanup;
+            goto error;
     }
 
     if (migrate_flags & (QEMU_MONITOR_MIGRATE_NON_SHARED_DISK |
@@ -3715,7 +3715,7 @@ qemuMigrationRun(virQEMUDriverPtr driver,
                                          nmigrate_disks,
                                          migrate_disks,
                                          dconn) < 0) {
-                goto cleanup;
+                goto error;
             }
         } else {
             /* Destination doesn't support NBD server.
@@ -3729,37 +3729,37 @@ qemuMigrationRun(virQEMUDriverPtr driver,
     if (!(flags & VIR_MIGRATE_LIVE) &&
         virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING) {
         if (qemuMigrationSetOffline(driver, vm) < 0)
-            goto cleanup;
+            goto error;
     }
 
     if (qemuMigrationSetCompression(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
                                     compression, migParams) < 0)
-        goto cleanup;
+        goto error;
 
     if (qemuMigrationSetOption(driver, vm,
                                QEMU_MONITOR_MIGRATION_CAPS_AUTO_CONVERGE,
                                flags & VIR_MIGRATE_AUTO_CONVERGE,
                                QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
-        goto cleanup;
+        goto error;
 
     if (qemuMigrationSetOption(driver, vm,
                                QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
                                flags & VIR_MIGRATE_RDMA_PIN_ALL,
                                QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
-        goto cleanup;
+        goto error;
 
     if (qemuMigrationSetPostCopy(driver, vm,
                                  flags & VIR_MIGRATE_POSTCOPY,
                                  QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
-        goto cleanup;
+        goto error;
 
     if (qemuMigrationSetParams(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
                                migParams) < 0)
-        goto cleanup;
+        goto error;
 
     if (qemuDomainObjEnterMonitorAsync(driver, vm,
                                        QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
-        goto cleanup;
+        goto error;
 
     if (priv->job.abortJob) {
         /* explicitly do this *after* we entered the monitor,
@@ -3770,7 +3770,7 @@ qemuMigrationRun(virQEMUDriverPtr driver,
         virReportError(VIR_ERR_OPERATION_ABORTED, _("%s: %s"),
                        qemuDomainAsyncJobTypeToString(priv->job.asyncJob),
                        _("canceled by client"));
-        goto cleanup;
+        goto error;
     }
 
     if (qemuMonitorSetMigrationSpeed(priv->mon, migrate_speed) < 0)
@@ -3817,7 +3817,7 @@ qemuMigrationRun(virQEMUDriverPtr driver,
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
         ret = -1;
     if (ret < 0)
-        goto cleanup;
+        goto error;
     ret = -1;
 
     /* From this point onwards we *must* call cancel to abort the
@@ -3846,7 +3846,7 @@ qemuMigrationRun(virQEMUDriverPtr driver,
     if (rc == -2)
         goto cancel;
     else if (rc == -1)
-        goto cleanup;
+        goto error;
 
     if (priv->job.current->status == QEMU_DOMAIN_JOB_STATUS_POSTCOPY)
         inPostCopy = true;
@@ -3901,28 +3901,10 @@ qemuMigrationRun(virQEMUDriverPtr driver,
     ret = 0;
 
  cleanup:
-    if (ret < 0 && !orig_err)
-        orig_err = virSaveLastError();
-
-    /* cancel any outstanding NBD jobs */
-    if (ret < 0 && mig && mig->nbd)
-        qemuMigrationCancelDriveMirror(driver, vm, false,
-                                       QEMU_ASYNC_JOB_MIGRATION_OUT,
-                                       dconn);
-
     VIR_FREE(tlsAlias);
     VIR_FREE(secAlias);
     virObjectUnref(cfg);
-
-    if (ret < 0 && iothread)
-        qemuMigrationStopTunnel(iothread, true);
-
     VIR_FORCE_CLOSE(fd);
-
-    if (priv->job.current->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE ||
-        priv->job.current->status == QEMU_DOMAIN_JOB_STATUS_MIGRATING)
-        priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
-
     virDomainDefFree(persistDef);
     qemuMigrationCookieFree(mig);
 
@@ -3936,9 +3918,28 @@ qemuMigrationRun(virQEMUDriverPtr driver,
 
     return ret;
 
+ error:
+    if (!orig_err)
+        orig_err = virSaveLastError();
+
+    /* cancel any outstanding NBD jobs */
+    if (mig && mig->nbd)
+        qemuMigrationCancelDriveMirror(driver, vm, false,
+                                       QEMU_ASYNC_JOB_MIGRATION_OUT,
+                                       dconn);
+
+    if (iothread)
+        qemuMigrationStopTunnel(iothread, true);
+
+    if (priv->job.current->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE ||
+        priv->job.current->status == QEMU_DOMAIN_JOB_STATUS_MIGRATING)
+        priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
+
+    goto cleanup;
+
  exit_monitor:
     ignore_value(qemuDomainObjExitMonitor(driver, vm));
-    goto cleanup;
+    goto error;
 
  cancel:
     orig_err = virSaveLastError();
@@ -3950,14 +3951,14 @@ qemuMigrationRun(virQEMUDriverPtr driver,
             ignore_value(qemuDomainObjExitMonitor(driver, vm));
         }
     }
-    goto cleanup;
+    goto error;
 
  cancelPostCopy:
     priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
     if (inPostCopy)
         goto cancel;
     else
-        goto cleanup;
+        goto error;
 }
 
 /* Perform migration using QEMU's native migrate support,
-- 
2.14.2




More information about the libvir-list mailing list