Patchwork [v7,04/11] Add host_from_stream_offset_versioned function

login
register
mail settings
Submitter Orit Wasserman
Date Jan. 26, 2012, 2:24 p.m.
Message ID <1327587897-31192-5-git-send-email-owasserm@redhat.com>
Download mbox | patch
Permalink /patch/137933/
State New
Headers show

Comments

Orit Wasserman - Jan. 26, 2012, 2:24 p.m.
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
---
 arch_init.c |   26 +++++++++++++++++++++++---
 1 files changed, 23 insertions(+), 3 deletions(-)

Patch

diff --git a/arch_init.c b/arch_init.c
index ac21bc0..0f6037e 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -550,6 +550,18 @@  static inline void *host_from_stream_offset(QEMUFile *f,
     return NULL;
 }
 
+static inline void *host_from_stream_offset_versioned(int version_id,
+        QEMUFile *f, ram_addr_t offset, int flags)
+{
+        void *host;
+        if (version_id == 3) {
+                host = qemu_get_ram_ptr(offset);
+        } else {
+                host = host_from_stream_offset(f, offset, flags);
+        }
+        return host;
+}
+
 int ram_load(QEMUFile *f, void *opaque, int version_id)
 {
     ram_addr_t addr;
@@ -605,8 +617,11 @@  int ram_load(QEMUFile *f, void *opaque, int version_id)
             void *host;
             uint8_t ch;
 
-            host = host_from_stream_offset(f, addr, flags);
+            host = host_from_stream_offset_versioned(version_id,
+                                                     f, addr, flags);
             if (!host) {
+                fprintf(stderr, "Failed to convert RAM address to host"
+                        " for offset " RAM_ADDR_FMT "\n", addr);
                 return -EINVAL;
             }
 
@@ -621,8 +636,13 @@  int ram_load(QEMUFile *f, void *opaque, int version_id)
         } else if (flags & RAM_SAVE_FLAG_PAGE) {
             void *host;
 
-            host = host_from_stream_offset(f, addr, flags);
-
+            host = host_from_stream_offset_versioned(version_id,
+                                                     f, addr, flags);
+            if (!host) {
+                fprintf(stderr, "Failed to convert RAM address to host"
+                        " for offset " RAM_ADDR_FMT "\n", addr);
+                return -EINVAL;
+            }
             qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
         }
         error = qemu_file_get_error(f);