Patchwork [v3,30/35] arch_init: factor out ram_load

login
register
mail settings
Submitter Isaku Yamahata
Date Oct. 30, 2012, 8:33 a.m.
Message ID <a23059ba6accfe67d2a1abf0f67c0c80440d3b6c.1351582535.git.yamahata@valinux.co.jp>
Download mbox | patch
Permalink /patch/195439/
State New
Headers show

Comments

Isaku Yamahata - Oct. 30, 2012, 8:33 a.m.
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 arch_init.c |   13 ++++++++++---
 arch_init.h |    3 +++
 2 files changed, 13 insertions(+), 3 deletions(-)

Patch

diff --git a/arch_init.c b/arch_init.c
index 9137013..f86a0b4 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -867,7 +867,9 @@  int ram_load_page(QEMUFile *f, void *host, int flags)
     return 0;
 }
 
-static int ram_load(QEMUFile *f, void *opaque, int version_id)
+int ram_load(QEMUFile *f, void *opaque, int version_id,
+             void *(host_from_stream_offset_p)(QEMUFile *f,
+                                               ram_addr_t offsset, int flags))
 {
     ram_addr_t addr;
     int flags, ret = 0;
@@ -899,7 +901,7 @@  static int ram_load(QEMUFile *f, void *opaque, int version_id)
 
         if (flags & (RAM_SAVE_FLAG_COMPRESS | RAM_SAVE_FLAG_PAGE |
                      RAM_SAVE_FLAG_XBZRLE)) {
-            host = host_from_stream_offset(f, addr, flags);
+            host = host_from_stream_offset_p(f, addr, flags);
             if (!host) {
                 return -EINVAL;
             }
@@ -922,6 +924,11 @@  done:
     return ret;
 }
 
+static int ram_load_precopy(QEMUFile *f, void *opaque, int version_id)
+{
+    return ram_load(f, opaque, version_id, &host_from_stream_offset);
+}
+
 static void ram_save_set_params(const MigrationParams *params, void *opaque)
 {
     if (params->postcopy) {
@@ -940,7 +947,7 @@  SaveVMHandlers savevm_ram_handlers = {
     .save_live_setup = ram_save_setup,
     .save_live_iterate = ram_save_iterate,
     .save_live_complete = ram_save_complete,
-    .load_state = ram_load,
+    .load_state = ram_load_precopy,
     .cancel = ram_migration_cancel,
 };
 
diff --git a/arch_init.h b/arch_init.h
index 9165456..3977ca7 100644
--- a/arch_init.h
+++ b/arch_init.h
@@ -54,6 +54,9 @@  bool ram_save_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
                    bool last_stage);
 RAMBlock *ram_find_block(const char *id, uint8_t len);
 int ram_load_mem_size(QEMUFile *f, ram_addr_t total_ram_bytes);
+int ram_load(QEMUFile *f, void *opaque, int version_id,
+             void *(host_from_stream_offset_p)(QEMUFile *f,
+                                               ram_addr_t offsset, int flags));
 #endif
 
 #endif