diff mbox

[04/21] arch_init: refactor host_from_stream_offset()

Message ID fa4b8e7142ca5be3af7e2f05b84a7e73473aea59.1325055139.git.yamahata@valinux.co.jp
State New
Headers show

Commit Message

Isaku Yamahata Dec. 29, 2011, 1:25 a.m. UTC
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 arch_init.c |   25 ++++++++++++++++++-------
 arch_init.h |    9 +++++++++
 2 files changed, 27 insertions(+), 7 deletions(-)
diff mbox

Patch

diff --git a/arch_init.c b/arch_init.c
index 5ad6956..d55e39c 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -335,21 +335,22 @@  int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
     return (stage == 2) && (expected_time <= migrate_max_downtime());
 }
 
-static inline void *host_from_stream_offset(QEMUFile *f,
-                                            ram_addr_t offset,
-                                            int flags)
+void *ram_load_host_from_stream_offset(QEMUFile *f,
+                                       ram_addr_t offset,
+                                       int flags,
+                                       RAMBlock **last_blockp)
 {
-    static RAMBlock *block = NULL;
+    RAMBlock *block;
     char id[256];
     uint8_t len;
 
     if (flags & RAM_SAVE_FLAG_CONTINUE) {
-        if (!block) {
+        if (!(*last_blockp)) {
             fprintf(stderr, "Ack, bad migration stream!\n");
             return NULL;
         }
 
-        return block->host + offset;
+        return (*last_blockp)->host + offset;
     }
 
     len = qemu_get_byte(f);
@@ -357,14 +358,24 @@  static inline void *host_from_stream_offset(QEMUFile *f,
     id[len] = 0;
 
     QLIST_FOREACH(block, &ram_list.blocks, next) {
-        if (!strncmp(id, block->idstr, sizeof(id)))
+        if (!strncmp(id, block->idstr, sizeof(id))) {
+            *last_blockp = block;
             return block->host + offset;
+        }
     }
 
     fprintf(stderr, "Can't find block %s!\n", id);
     return NULL;
 }
 
+static inline void *host_from_stream_offset(QEMUFile *f,
+                                            ram_addr_t offset,
+                                            int flags)
+{
+    static RAMBlock *block = NULL;
+    return ram_load_host_from_stream_offset(f, offset, flags, &block);
+}
+
 int ram_load(QEMUFile *f, void *opaque, int version_id)
 {
     ram_addr_t addr;
diff --git a/arch_init.h b/arch_init.h
index a3aa059..14d6644 100644
--- a/arch_init.h
+++ b/arch_init.h
@@ -1,6 +1,8 @@ 
 #ifndef QEMU_ARCH_INIT_H
 #define QEMU_ARCH_INIT_H
 
+#include "qemu-common.h"
+
 extern const char arch_config_name[];
 
 enum {
@@ -41,4 +43,11 @@  int xen_available(void);
 
 #define RAM_SAVE_VERSION_ID     4 /* currently version 4 */
 
+#ifdef NEED_CPU_H
+void *ram_load_host_from_stream_offset(QEMUFile *f,
+                                       ram_addr_t offset,
+                                       int flags,
+                                       RAMBlock **last_blockp);
+#endif
+
 #endif