Patchwork [for-1.4,1/2] migration: make qemu_ftell() public and support writable files

login
register
mail settings
Submitter Stefan Hajnoczi
Date Feb. 12, 2013, 9:37 a.m.
Message ID <1360661835-28663-2-git-send-email-stefanha@redhat.com>
Download mbox | patch
Permalink /patch/219752/
State New
Headers show

Comments

Stefan Hajnoczi - Feb. 12, 2013, 9:37 a.m.
Migration .save_live_iterate() functions return the number of bytes
transferred.  The easiest way of doing this is by calling qemu_ftell(f)
at the beginning and end of the function to calculate the difference.

Make qemu_ftell() public so that block-migration will be able to use it.
Also adjust the ftell calculation for writable files where buf_offset
does not include buf_size.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 include/migration/qemu-file.h | 1 +
 savevm.c                      | 9 +++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

Patch

diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h
index 68deefb..46fc11d 100644
--- a/include/migration/qemu-file.h
+++ b/include/migration/qemu-file.h
@@ -81,6 +81,7 @@  QEMUFile *qemu_popen(FILE *popen_file, const char *mode);
 QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
 int qemu_get_fd(QEMUFile *f);
 int qemu_fclose(QEMUFile *f);
+int64_t qemu_ftell(QEMUFile *f);
 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
 void qemu_put_byte(QEMUFile *f, int v);
 
diff --git a/savevm.c b/savevm.c
index 0b6724d..a8a53ef 100644
--- a/savevm.c
+++ b/savevm.c
@@ -673,9 +673,14 @@  int qemu_get_byte(QEMUFile *f)
     return result;
 }
 
-static int64_t qemu_ftell(QEMUFile *f)
+int64_t qemu_ftell(QEMUFile *f)
 {
-    return f->buf_offset - f->buf_size + f->buf_index;
+    /* buf_offset excludes buffer for writing but includes it for reading */
+    if (f->is_write) {
+        return f->buf_offset + f->buf_index;
+    } else {
+        return f->buf_offset - f->buf_size + f->buf_index;
+    }
 }
 
 int qemu_file_rate_limit(QEMUFile *f)