qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 23/33] migration: simplify some error reporting in save_snapshot(


From: Daniel P . Berrangé
Subject: [PATCH 23/33] migration: simplify some error reporting in save_snapshot()
Date: Thu, 4 Feb 2021 17:18:57 +0000

Re-arrange code to remove need for a separate 'ret2' variable, accepting
the duplicated qemu_fclose() call as resulting in clearer code to follow
the flow of.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 migration/savevm.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/migration/savevm.c b/migration/savevm.c
index 23e4d5a1a2..fdf8b6edfb 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -2788,7 +2788,7 @@ bool save_snapshot(const char *name, bool overwrite, 
const char *vmstate,
 {
     BlockDriverState *bs;
     QEMUSnapshotInfo sn1, *sn = &sn1;
-    int ret = -1, ret2;
+    int ret = -1;
     QEMUFile *f;
     int saved_vm_running;
     uint64_t vm_state_size;
@@ -2818,11 +2818,11 @@ bool save_snapshot(const char *name, bool overwrite, 
const char *vmstate,
                 return false;
             }
         } else {
-            ret2 = bdrv_all_has_snapshot(name, has_devices, devices, errp);
-            if (ret2 < 0) {
+            ret = bdrv_all_has_snapshot(name, has_devices, devices, errp);
+            if (ret < 0) {
                 return false;
             }
-            if (ret2 == 1) {
+            if (ret == 1) {
                 error_setg(errp,
                            "Snapshot '%s' already exists in one or more 
devices",
                            name);
@@ -2874,13 +2874,14 @@ bool save_snapshot(const char *name, bool overwrite, 
const char *vmstate,
     f = qemu_fopen_bdrv(bs, 1);
 
     ret = qemu_savevm_state(f, errp);
-    vm_state_size = qemu_ftell(f);
-    ret2 = qemu_fclose(f);
     if (ret < 0) {
+        qemu_fclose(f);
         goto the_end;
     }
-    if (ret2 < 0) {
-        ret = ret2;
+    vm_state_size = qemu_ftell(f);
+    ret = qemu_fclose(f);
+    if (ret < 0) {
+        error_setg_errno(errp, -ret, "failed to close vmstate file");
         goto the_end;
     }
 
-- 
2.29.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]