Patchwork [01/12] vmstate: Avoid seeking

login
register
mail settings
Submitter Juan Quintela
Date Dec. 2, 2009, 11:36 a.m.
Message ID <356d13f1e7112c6daa693a0d937b74adc7de8f93.1259753146.git.quintela@redhat.com>
Download mbox | patch
Permalink /patch/39994/
State New
Headers show

Comments

Juan Quintela - Dec. 2, 2009, 11:36 a.m.
From: Jan Kiszka <jan.kiszka@web.de>

Seeking on vmstate save/load does not work if the underlying file is a
stream. We could try to make all QEMUFile* forward-seek-aware, but first
attempts in this direction indicated that it's saner to convert the few
qemu_fseek-on-vmstates users to plain reads/writes.

This fixes various subtle vmstate corruptions where unused fields were
involved.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 savevm.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)

Patch

diff --git a/savevm.c b/savevm.c
index 18c2e54..833bf3c 100644
--- a/savevm.c
+++ b/savevm.c
@@ -959,13 +959,27 @@  const VMStateInfo vmstate_info_buffer = {

 static int get_unused_buffer(QEMUFile *f, void *pv, size_t size)
 {
-    qemu_fseek(f, size, SEEK_CUR);
-    return 0;
+    uint8_t buf[1024];
+    int block_len;
+
+    while (size > 0) {
+        block_len = MIN(sizeof(buf), size);
+        size -= block_len;
+        qemu_get_buffer(f, buf, block_len);
+    }
+   return 0;
 }

 static void put_unused_buffer(QEMUFile *f, void *pv, size_t size)
 {
-    qemu_fseek(f, size, SEEK_CUR);
+    static const uint8_t buf[1024];
+    int block_len;
+
+    while (size > 0) {
+        block_len = MIN(sizeof(buf), size);
+        size -= block_len;
+        qemu_put_buffer(f, buf, block_len);
+    }
 }

 const VMStateInfo vmstate_info_unused_buffer = {