[libvirt] [PATCH v1] qemu: migration: Convert to virErrorRestore/virErrorPreserveLast

Syed Humaid posted 1 patch 5 years, 7 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20190429175627.376-1-syedhumaidbinharoon@gmail.com
src/qemu/qemu_migration.c | 75 +++++++++++++--------------------------
1 file changed, 24 insertions(+), 51 deletions(-)
[libvirt] [PATCH v1] qemu: migration: Convert to virErrorRestore/virErrorPreserveLast
Posted by Syed Humaid 5 years, 7 months ago
Replaced usages of virSaveLastError and virSetError/virFreeError with
virErrorPreserveLast and virErrorRestore respectively.

Signed-off-by: Syed Humaid <syedhumaidbinharoon@gmail.com>
---
 src/qemu/qemu_migration.c | 75 +++++++++++++--------------------------
 1 file changed, 24 insertions(+), 51 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index e3ad4e52a7..b1fe79aed9 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -722,7 +722,7 @@ qemuMigrationSrcNBDCopyCancel(virQEMUDriverPtr driver,
         if (rv != 0) {
             if (rv < 0) {
                 if (!err)
-                    err = virSaveLastError();
+                    virErrorPreserveLast(&err);
                 failed = true;
             }
             qemuBlockJobSyncEnd(vm, job, asyncJob);
@@ -747,7 +747,7 @@ qemuMigrationSrcNBDCopyCancel(virQEMUDriverPtr driver,
         }
 
         if (failed && !err)
-            err = virSaveLastError();
+            virErrorPreserveLast(&err);
 
         if (virDomainObjWait(vm) < 0)
             goto cleanup;
@@ -769,10 +769,7 @@ qemuMigrationSrcNBDCopyCancel(virQEMUDriverPtr driver,
     ret = failed ? -1 : 0;
 
  cleanup:
-    if (err) {
-        virSetError(err);
-        virFreeError(err);
-    }
+    virErrorRestore(&err);
     return ret;
 }
 
@@ -3189,16 +3186,13 @@ static void qemuMigrationSrcIOFunc(void *arg)
     return;
 
  abrt:
-    err = virSaveLastError();
+    virErrorPreserveLast(&err); 
     if (err && err->code == VIR_ERR_OK) {
         virFreeError(err);
         err = NULL;
     }
     virStreamAbort(data->st);
-    if (err) {
-        virSetError(err);
-        virFreeError(err);
-    }
+    virErrorRestore(&err);
 
  error:
     /* Let the source qemu know that the transfer cant continue anymore.
@@ -3685,15 +3679,12 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
     if (events)
         priv->signalIOError = false;
 
-    if (orig_err) {
-        virSetError(orig_err);
-        virFreeError(orig_err);
-    }
+    virErrorRestore(&orig_err);
 
     return ret;
 
  error:
-    orig_err = virSaveLastError();
+    virErrorPreserveLast(&orig_err); 
 
     if (virDomainObjIsActive(vm)) {
         if (cancel &&
@@ -3948,7 +3939,7 @@ qemuMigrationSrcPerformPeer2Peer2(virQEMUDriverPtr driver,
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("domainMigratePrepare2 did not set uri"));
         cancelled = true;
-        orig_err = virSaveLastError();
+        virErrorPreserveLast(&orig_err);
         goto finish;
     }
 
@@ -3971,7 +3962,7 @@ qemuMigrationSrcPerformPeer2Peer2(virQEMUDriverPtr driver,
 
     /* Perform failed. Make sure Finish doesn't overwrite the error */
     if (ret < 0)
-        orig_err = virSaveLastError();
+        virErrorPreserveLast(&orig_err);
 
     /* If Perform returns < 0, then we need to cancel the VM
      * startup on the destination
@@ -4004,10 +3995,7 @@ qemuMigrationSrcPerformPeer2Peer2(virQEMUDriverPtr driver,
 
     virObjectUnref(st);
 
-    if (orig_err) {
-        virSetError(orig_err);
-        virFreeError(orig_err);
-    }
+    virErrorRestore(&orig_err);
     VIR_FREE(uri_out);
     VIR_FREE(cookie);
 
@@ -4181,13 +4169,13 @@ qemuMigrationSrcPerformPeer2Peer3(virQEMUDriverPtr driver,
         if (useParams &&
             virTypedParamsReplaceString(&params, &nparams,
                                         VIR_MIGRATE_PARAM_URI, uri_out) < 0) {
-            orig_err = virSaveLastError();
+            virErrorPreserveLast(&orig_err);
             goto finish;
         }
     } else if (!uri && !(flags & VIR_MIGRATE_TUNNELLED)) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("domainMigratePrepare3 did not set uri"));
-        orig_err = virSaveLastError();
+        virErrorPreserveLast(&orig_err);
         goto finish;
     }
 
@@ -4220,7 +4208,7 @@ qemuMigrationSrcPerformPeer2Peer3(virQEMUDriverPtr driver,
 
     /* Perform failed. Make sure Finish doesn't overwrite the error */
     if (ret < 0) {
-        orig_err = virSaveLastError();
+        virErrorPreserveLast(&orig_err);
     } else {
         qemuMigrationJobSetPhase(driver, vm,
                                  QEMU_MIGRATION_PHASE_PERFORM3_DONE);
@@ -4312,7 +4300,7 @@ qemuMigrationSrcPerformPeer2Peer3(virQEMUDriverPtr driver,
      * one we need to preserve it in case confirm3 overwrites
      */
     if (!orig_err)
-        orig_err = virSaveLastError();
+        virErrorPreserveLast(&orig_err);
 
     /*
      * If cancelled, then src VM will be restarted, else
@@ -4344,10 +4332,7 @@ qemuMigrationSrcPerformPeer2Peer3(virQEMUDriverPtr driver,
 
     virObjectUnref(st);
 
-    if (orig_err) {
-        virSetError(orig_err);
-        virFreeError(orig_err);
-    }
+    virErrorRestore(&orig_err);
     VIR_FREE(uri_out);
     VIR_FREE(cookiein);
     VIR_FREE(cookieout);
@@ -4523,15 +4508,12 @@ qemuMigrationSrcPerformPeer2Peer(virQEMUDriverPtr driver,
     }
 
  cleanup:
-    orig_err = virSaveLastError();
+    virErrorPreserveLast(&orig_err);
     qemuDomainObjEnterRemote(vm);
     virConnectUnregisterCloseCallback(dconn, qemuMigrationSrcConnectionClosed);
     virObjectUnref(dconn);
     ignore_value(qemuDomainObjExitRemote(vm, false));
-    if (orig_err) {
-        virSetError(orig_err);
-        virFreeError(orig_err);
-    }
+    virErrorRestore(&orig_err);
     virObjectUnref(cfg);
     return ret;
 }
@@ -4619,7 +4601,7 @@ qemuMigrationSrcPerformJob(virQEMUDriverPtr driver,
 
  endjob:
     if (ret < 0)
-        orig_err = virSaveLastError();
+        virErrorPreserveLast(&orig_err);
 
     /* v2 proto has no confirm phase so we need to reset migration parameters
      * here
@@ -4639,10 +4621,7 @@ qemuMigrationSrcPerformJob(virQEMUDriverPtr driver,
         qemuDomainRemoveInactiveJob(driver, vm);
     }
 
-    if (orig_err) {
-        virSetError(orig_err);
-        virFreeError(orig_err);
-    }
+    virErrorRestore(&orig_err);
 
  cleanup:
     virObjectEventStateQueue(driver->domainEventState, event);
@@ -5052,7 +5031,7 @@ qemuMigrationDstFinish(virQEMUDriverPtr driver,
             /* Need to save the current error, in case shutting
              * down the process overwrites it
              */
-            orig_err = virSaveLastError();
+            virErrorPreserveLast(&orig_err);
 
             /*
              * In v3 protocol, the source VM is still available to
@@ -5181,10 +5160,7 @@ qemuMigrationDstFinish(virQEMUDriverPtr driver,
     VIR_FREE(priv->origname);
     virDomainObjEndAPI(&vm);
     qemuMigrationCookieFree(mig);
-    if (orig_err) {
-        virSetError(orig_err);
-        virFreeError(orig_err);
-    }
+    virErrorRestore(&orig_err);
     virObjectUnref(cfg);
 
     /* Set a special error if Finish is expected to return NULL as a result of
@@ -5289,7 +5265,7 @@ qemuMigrationSrcToFile(virQEMUDriverPtr driver, virDomainObjPtr vm,
 
     if (rc < 0) {
         if (rc == -2) {
-            orig_err = virSaveLastError();
+            virErrorPreserveLast(&orig_err);
             virCommandAbort(cmd);
             if (virDomainObjIsActive(vm) &&
                 qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) == 0) {
@@ -5308,7 +5284,7 @@ qemuMigrationSrcToFile(virQEMUDriverPtr driver, virDomainObjPtr vm,
 
  cleanup:
     if (ret < 0 && !orig_err)
-        orig_err = virSaveLastError();
+        virErrorPreserveLast(&orig_err);
 
     /* Restore max migration bandwidth */
     if (virDomainObjIsActive(vm) &&
@@ -5326,10 +5302,7 @@ qemuMigrationSrcToFile(virQEMUDriverPtr driver, virDomainObjPtr vm,
         virCommandFree(cmd);
     }
 
-    if (orig_err) {
-        virSetError(orig_err);
-        virFreeError(orig_err);
-    }
+    virErrorRestore(&orig_err);
 
     return ret;
 }
-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v1] qemu: migration: Convert to virErrorRestore/virErrorPreserveLast
Posted by Michal Privoznik 5 years, 6 months ago
On 4/29/19 7:56 PM, Syed Humaid wrote:
> Replaced usages of virSaveLastError and virSetError/virFreeError with
> virErrorPreserveLast and virErrorRestore respectively.
> 
> Signed-off-by: Syed Humaid <syedhumaidbinharoon@gmail.com>
> ---
>   src/qemu/qemu_migration.c | 75 +++++++++++++--------------------------
>   1 file changed, 24 insertions(+), 51 deletions(-)

Closer, but there is one place missing. Also there are some trailing 
blanks. Looking forward to v2.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list