]> rtime.felk.cvut.cz Git - lisovros/qemu_apohw.git/commitdiff
migration: make qemu_ftell() public and support writable files
authorStefan Hajnoczi <stefanha@redhat.com>
Tue, 12 Feb 2013 09:37:14 +0000 (10:37 +0100)
committerAnthony Liguori <aliguori@us.ibm.com>
Tue, 12 Feb 2013 22:26:44 +0000 (16:26 -0600)
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>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Message-id: 1360661835-28663-2-git-send-email-stefanha@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
include/migration/qemu-file.h
savevm.c

index 68deefbcfba08ed059d77af609b0a85e57f42f34..46fc11dc99ef4322b93d45b929e95758df0b642e 100644 (file)
@@ -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);
 
index 0b6724dddb2f763b4f084a496f3e0d8f0bf2da62..a8a53efc9bcec800dcd4d4e266b2ecad41f99584 100644 (file)
--- 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)