a7b9285
From 8d5406a6a42ece0d7d9e250aabe68ea8a0e3fbf6 Mon Sep 17 00:00:00 2001
Alon Levy 408bdb5
From: Paolo Bonzini <pbonzini@redhat.com>
Alon Levy 408bdb5
Date: Fri, 22 Feb 2013 17:36:13 +0100
a7b9285
Subject: [PATCH] migration: use qemu_file_set_error to pass error codes back
a7b9285
 to qemu_savevm_state
Alon Levy 408bdb5
Alon Levy 408bdb5
Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Alon Levy 408bdb5
Reviewed-by: Juan Quintela <quintela@redhat.com>
Alon Levy 408bdb5
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Alon Levy 408bdb5
Signed-off-by: Juan Quintela <quintela@redhat.com>
a7b9285
(cherry picked from commit 47c8c17af883b5bd0f147cfcec8d7ef8ff76023b)
Alon Levy 408bdb5
---
Alon Levy 408bdb5
 include/sysemu/sysemu.h |  6 +++---
Alon Levy 408bdb5
 savevm.c                | 44 ++++++++++++++++++--------------------------
Alon Levy 408bdb5
 2 files changed, 21 insertions(+), 29 deletions(-)
Alon Levy 408bdb5
Alon Levy 408bdb5
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
Alon Levy 408bdb5
index 1d9599e..28a9221 100644
Alon Levy 408bdb5
--- a/include/sysemu/sysemu.h
Alon Levy 408bdb5
+++ b/include/sysemu/sysemu.h
Alon Levy 408bdb5
@@ -73,10 +73,10 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict);
Alon Levy 408bdb5
 void qemu_announce_self(void);
Alon Levy 408bdb5
 
Alon Levy 408bdb5
 bool qemu_savevm_state_blocked(Error **errp);
Alon Levy 408bdb5
-int qemu_savevm_state_begin(QEMUFile *f,
Alon Levy 408bdb5
-                            const MigrationParams *params);
Alon Levy 408bdb5
+void qemu_savevm_state_begin(QEMUFile *f,
Alon Levy 408bdb5
+                             const MigrationParams *params);
Alon Levy 408bdb5
 int qemu_savevm_state_iterate(QEMUFile *f);
Alon Levy 408bdb5
-int qemu_savevm_state_complete(QEMUFile *f);
Alon Levy 408bdb5
+void qemu_savevm_state_complete(QEMUFile *f);
Alon Levy 408bdb5
 void qemu_savevm_state_cancel(void);
Alon Levy 408bdb5
 uint64_t qemu_savevm_state_pending(QEMUFile *f, uint64_t max_size);
Alon Levy 408bdb5
 int qemu_loadvm_state(QEMUFile *f);
Alon Levy 408bdb5
diff --git a/savevm.c b/savevm.c
Alon Levy 408bdb5
index a681177..a1690b4 100644
Alon Levy 408bdb5
--- a/savevm.c
Alon Levy 408bdb5
+++ b/savevm.c
Alon Levy 408bdb5
@@ -1579,8 +1579,8 @@ bool qemu_savevm_state_blocked(Error **errp)
Alon Levy 408bdb5
     return false;
Alon Levy 408bdb5
 }
Alon Levy 408bdb5
 
Alon Levy 408bdb5
-int qemu_savevm_state_begin(QEMUFile *f,
Alon Levy 408bdb5
-                            const MigrationParams *params)
Alon Levy 408bdb5
+void qemu_savevm_state_begin(QEMUFile *f,
Alon Levy 408bdb5
+                             const MigrationParams *params)
Alon Levy 408bdb5
 {
Alon Levy 408bdb5
     SaveStateEntry *se;
Alon Levy 408bdb5
     int ret;
Alon Levy 408bdb5
@@ -1620,11 +1620,10 @@ int qemu_savevm_state_begin(QEMUFile *f,
Alon Levy 408bdb5
 
Alon Levy 408bdb5
         ret = se->ops->save_live_setup(f, se->opaque);
Alon Levy 408bdb5
         if (ret < 0) {
Alon Levy 408bdb5
-            return ret;
Alon Levy 408bdb5
+            qemu_file_set_error(f, ret);
Alon Levy 408bdb5
+            break;
Alon Levy 408bdb5
         }
Alon Levy 408bdb5
     }
Alon Levy 408bdb5
-    ret = qemu_file_get_error(f);
Alon Levy 408bdb5
-    return ret;
Alon Levy 408bdb5
 }
Alon Levy 408bdb5
 
Alon Levy 408bdb5
 /*
Alon Levy 408bdb5
@@ -1658,6 +1657,9 @@ int qemu_savevm_state_iterate(QEMUFile *f)
Alon Levy 408bdb5
         ret = se->ops->save_live_iterate(f, se->opaque);
Alon Levy 408bdb5
         trace_savevm_section_end(se->section_id);
Alon Levy 408bdb5
 
Alon Levy 408bdb5
+        if (ret < 0) {
Alon Levy 408bdb5
+            qemu_file_set_error(f, ret);
Alon Levy 408bdb5
+        }
Alon Levy 408bdb5
         if (ret <= 0) {
Alon Levy 408bdb5
             /* Do not proceed to the next vmstate before this one reported
Alon Levy 408bdb5
                completion of the current stage. This serializes the migration
Alon Levy 408bdb5
@@ -1666,14 +1668,10 @@ int qemu_savevm_state_iterate(QEMUFile *f)
Alon Levy 408bdb5
             break;
Alon Levy 408bdb5
         }
Alon Levy 408bdb5
     }
Alon Levy 408bdb5
-    if (ret != 0) {
Alon Levy 408bdb5
-        return ret;
Alon Levy 408bdb5
-    }
Alon Levy 408bdb5
-    ret = qemu_file_get_error(f);
Alon Levy 408bdb5
     return ret;
Alon Levy 408bdb5
 }
Alon Levy 408bdb5
 
Alon Levy 408bdb5
-int qemu_savevm_state_complete(QEMUFile *f)
Alon Levy 408bdb5
+void qemu_savevm_state_complete(QEMUFile *f)
Alon Levy 408bdb5
 {
Alon Levy 408bdb5
     SaveStateEntry *se;
Alon Levy 408bdb5
     int ret;
Alon Levy 408bdb5
@@ -1697,7 +1695,8 @@ int qemu_savevm_state_complete(QEMUFile *f)
Alon Levy 408bdb5
         ret = se->ops->save_live_complete(f, se->opaque);
Alon Levy 408bdb5
         trace_savevm_section_end(se->section_id);
Alon Levy 408bdb5
         if (ret < 0) {
Alon Levy 408bdb5
-            return ret;
Alon Levy 408bdb5
+            qemu_file_set_error(f, ret);
Alon Levy 408bdb5
+            return;
Alon Levy 408bdb5
         }
Alon Levy 408bdb5
     }
Alon Levy 408bdb5
 
Alon Levy 408bdb5
@@ -1725,8 +1724,6 @@ int qemu_savevm_state_complete(QEMUFile *f)
Alon Levy 408bdb5
     }
Alon Levy 408bdb5
 
Alon Levy 408bdb5
     qemu_put_byte(f, QEMU_VM_EOF);
Alon Levy 408bdb5
-
Alon Levy 408bdb5
-    return qemu_file_get_error(f);
Alon Levy 408bdb5
 }
Alon Levy 408bdb5
 
Alon Levy 408bdb5
 uint64_t qemu_savevm_state_pending(QEMUFile *f, uint64_t max_size)
Alon Levy 408bdb5
@@ -1771,26 +1768,21 @@ static int qemu_savevm_state(QEMUFile *f)
Alon Levy 408bdb5
         return -EINVAL;
Alon Levy 408bdb5
     }
Alon Levy 408bdb5
 
Alon Levy 408bdb5
-    ret = qemu_savevm_state_begin(f, &params);
Alon Levy 408bdb5
-    if (ret < 0)
Alon Levy 408bdb5
-        goto out;
Alon Levy 408bdb5
-
Alon Levy 408bdb5
-    do {
Alon Levy 408bdb5
-        ret = qemu_savevm_state_iterate(f);
Alon Levy 408bdb5
-        if (ret < 0)
Alon Levy 408bdb5
-            goto out;
Alon Levy 408bdb5
-    } while (ret == 0);
Alon Levy 408bdb5
-
Alon Levy 408bdb5
-    ret = qemu_savevm_state_complete(f);
Alon Levy 408bdb5
+    qemu_savevm_state_begin(f, &params);
Alon Levy 408bdb5
+    while (qemu_file_get_error(f) == 0) {
Alon Levy 408bdb5
+        if (qemu_savevm_state_iterate(f) > 0) {
Alon Levy 408bdb5
+            break;
Alon Levy 408bdb5
+        }
Alon Levy 408bdb5
+    }
Alon Levy 408bdb5
 
Alon Levy 408bdb5
-out:
Alon Levy 408bdb5
+    ret = qemu_file_get_error(f);
Alon Levy 408bdb5
     if (ret == 0) {
Alon Levy 408bdb5
+        qemu_savevm_state_complete(f);
Alon Levy 408bdb5
         ret = qemu_file_get_error(f);
Alon Levy 408bdb5
     }
Alon Levy 408bdb5
     if (ret != 0) {
Alon Levy 408bdb5
         qemu_savevm_state_cancel();
Alon Levy 408bdb5
     }
Alon Levy 408bdb5
-
Alon Levy 408bdb5
     return ret;
Alon Levy 408bdb5
 }
Alon Levy 408bdb5