Patchwork [v13,08/13] Change ram_save_block to return -1 if there are no more changes

login
register
mail settings
Submitter Orit Wasserman
Date June 27, 2012, 10:34 a.m.
Message ID <1340793261-11400-9-git-send-email-owasserm@redhat.com>
Download mbox | patch
Permalink /patch/167613/
State New
Headers show

Comments

Orit Wasserman - June 27, 2012, 10:34 a.m.
It will return 0 if the page is unmodifed.

Signed-off-by: Orit Wasserman <owasserm@redhat.com>
---
 arch_init.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)
Juan Quintela - June 29, 2012, 4:46 p.m.
Orit Wasserman <owasserm@redhat.com> wrote:
> It will return 0 if the page is unmodifed.
>
> Signed-off-by: Orit Wasserman <owasserm@redhat.com>

This does another thing, it adds stage parameter to ram_save_block(),
and it "shouldn't" need it (famous last words).

> -static int ram_save_block(QEMUFile *f)
> +static int ram_save_block(QEMUFile *f, int stage)

Patch

diff --git a/arch_init.c b/arch_init.c
index ee20c33..ef7b4d6 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -184,11 +184,11 @@  static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
 static RAMBlock *last_block;
 static ram_addr_t last_offset;
 
-static int ram_save_block(QEMUFile *f)
+static int ram_save_block(QEMUFile *f, int stage)
 {
     RAMBlock *block = last_block;
     ram_addr_t offset = last_offset;
-    int bytes_sent = 0;
+    int bytes_sent = -1;
     MemoryRegion *mr;
 
     if (!block)
@@ -353,9 +353,12 @@  int ram_save_live(QEMUFile *f, int stage, void *opaque)
     while ((ret = qemu_file_rate_limit(f)) == 0) {
         int bytes_sent;
 
-        bytes_sent = ram_save_block(f);
-        bytes_transferred += bytes_sent;
-        if (bytes_sent == 0) { /* no more blocks */
+        bytes_sent = ram_save_block(f, stage);
+        /* bytes_sent 0 represent unchanged page,
+           bytes_sent -1 represent no more blocks*/
+        if (bytes_sent > 0) {
+            bytes_transferred += bytes_sent;
+        } else if (bytes_sent == -1) { /* no more blocks */
             break;
         }
     }
@@ -378,7 +381,7 @@  int ram_save_live(QEMUFile *f, int stage, void *opaque)
         int bytes_sent;
 
         /* flush all remaining blocks regardless of rate limiting */
-        while ((bytes_sent = ram_save_block(f)) != 0) {
+        while ((bytes_sent = ram_save_block(f, stage)) != -1) {
             bytes_transferred += bytes_sent;
         }
         memory_global_dirty_log_stop();