diff mbox

[RFC,07/13] savevm: Split qemu_savevm_state_complete_precopy() into two helper functions

Message ID 1452169208-840-8-git-send-email-zhang.zhanghailiang@huawei.com
State New
Headers show

Commit Message

Zhanghailiang Jan. 7, 2016, 12:20 p.m. UTC
We splited qemu_savevm_state_complete_precopy() into two helper functions,
qemu_savevm_section_full() and qemu_savevm_section_end().
The main reason to do that is, sometimes we may want to do this two works
separately.

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
---
 migration/savevm.c | 41 ++++++++++++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 11 deletions(-)
diff mbox

Patch

diff --git a/migration/savevm.c b/migration/savevm.c
index 9b22498..1b4e5bd 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -1026,18 +1026,12 @@  void qemu_savevm_state_complete_postcopy(QEMUFile *f)
     qemu_fflush(f);
 }
 
-void qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only)
+static int qemu_savevm_section_end(QEMUFile *f, bool iterable_only)
 {
-    QJSON *vmdesc;
-    int vmdesc_len;
     SaveStateEntry *se;
     int ret;
     bool in_postcopy = migration_in_postcopy(migrate_get_current());
 
-    trace_savevm_state_complete_precopy();
-
-    cpu_synchronize_all_states();
-
     QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
         if (!se->ops ||
             (in_postcopy && se->ops->save_live_complete_postcopy) ||
@@ -1060,13 +1054,18 @@  void qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only)
         save_section_footer(f, se);
         if (ret < 0) {
             qemu_file_set_error(f, ret);
-            return;
+            return -1;
         }
     }
+    return 0;
+}
 
-    if (iterable_only) {
-        return;
-    }
+static void qemu_savevm_section_full(QEMUFile *f)
+{
+    QJSON *vmdesc;
+    int vmdesc_len;
+    SaveStateEntry *se;
+    bool in_postcopy = migration_in_postcopy(migrate_get_current());
 
     vmdesc = qjson_new();
     json_prop_int(vmdesc, "page_size", TARGET_PAGE_SIZE);
@@ -1111,6 +1110,26 @@  void qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only)
         qemu_put_buffer(f, (uint8_t *)qjson_get_str(vmdesc), vmdesc_len);
     }
     object_unref(OBJECT(vmdesc));
+}
+
+void qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only)
+{
+    int ret;
+
+    trace_savevm_state_complete_precopy();
+
+    cpu_synchronize_all_states();
+
+    ret = qemu_savevm_section_end(f, iterable_only);
+    if (ret < 0) {
+        return;
+    }
+
+    if (iterable_only) {
+        return;
+    }
+
+    qemu_savevm_section_full(f);
 
     qemu_fflush(f);
 }