]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Rework qemuDomainMigrateSetMaxSpeed
authorJiri Denemark <jdenemar@redhat.com>
Mon, 4 Feb 2019 15:52:05 +0000 (16:52 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Thu, 7 Feb 2019 15:25:59 +0000 (16:25 +0100)
Let's make the code flow easier to follow and get rid of the ugly endjob
label inside if branch.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_driver.c

index 4084673cdbd002b6caef6a97e85b2e58dc2e7f49..0c0ed4fab98e7663eed55757ac80e963f2d75a7a 100644 (file)
@@ -14275,6 +14275,7 @@ qemuDomainMigrateSetMaxSpeed(virDomainPtr dom,
     virQEMUDriverPtr driver = dom->conn->privateData;
     virDomainObjPtr vm;
     qemuDomainObjPrivatePtr priv;
+    int rc;
     int ret = -1;
 
     virCheckFlags(0, -1);
@@ -14294,28 +14295,30 @@ qemuDomainMigrateSetMaxSpeed(virDomainPtr dom,
         goto cleanup;
     }
 
-    if (virDomainObjIsActive(vm)) {
-        if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MIGRATION_OP) < 0)
-            goto cleanup;
+    if (!virDomainObjIsActive(vm)) {
+        priv->migMaxBandwidth = bandwidth;
+        ret = 0;
+        goto cleanup;
+    }
 
-        if (virDomainObjCheckActive(vm) < 0)
-            goto endjob;
+    if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MIGRATION_OP) < 0)
+        goto cleanup;
 
-        VIR_DEBUG("Setting migration bandwidth to %luMbs", bandwidth);
-        qemuDomainObjEnterMonitor(driver, vm);
-        ret = qemuMonitorSetMigrationSpeed(priv->mon, bandwidth);
-        if (qemuDomainObjExitMonitor(driver, vm) < 0)
-            ret = -1;
+    if (virDomainObjCheckActive(vm) < 0)
+        goto endjob;
 
-        if (ret == 0)
-            priv->migMaxBandwidth = bandwidth;
+    VIR_DEBUG("Setting migration bandwidth to %luMbs", bandwidth);
+    qemuDomainObjEnterMonitor(driver, vm);
+    rc = qemuMonitorSetMigrationSpeed(priv->mon, bandwidth);
+    if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
+        goto endjob;
+
+    priv->migMaxBandwidth = bandwidth;
+
+    ret = 0;
 
  endjob:
-        qemuDomainObjEndJob(driver, vm);
-    } else {
-        priv->migMaxBandwidth = bandwidth;
-        ret = 0;
-    }
+    qemuDomainObjEndJob(driver, vm);
 
  cleanup:
     virDomainObjEndAPI(&vm);