0a122b
From ab8cff98f973031b20d7f1971b4fe42d8bf6488c Mon Sep 17 00:00:00 2001
0a122b
Message-Id: <ab8cff98f973031b20d7f1971b4fe42d8bf6488c.1387382496.git.minovotn@redhat.com>
0a122b
In-Reply-To: <c5386144fbf09f628148101bc674e2421cdd16e3.1387382496.git.minovotn@redhat.com>
0a122b
References: <c5386144fbf09f628148101bc674e2421cdd16e3.1387382496.git.minovotn@redhat.com>
0a122b
From: Nigel Croxon <ncroxon@redhat.com>
0a122b
Date: Thu, 14 Nov 2013 22:52:52 +0100
0a122b
Subject: [PATCH 16/46] rdma: send pc.ram
0a122b
0a122b
RH-Author: Nigel Croxon <ncroxon@redhat.com>
0a122b
Message-id: <1384469598-13137-17-git-send-email-ncroxon@redhat.com>
0a122b
Patchwork-id: 55700
0a122b
O-Subject: [RHEL7.0 PATCH 16/42] rdma: send pc.ram
0a122b
Bugzilla: 1011720
0a122b
RH-Acked-by: Orit Wasserman <owasserm@redhat.com>
0a122b
RH-Acked-by: Amit Shah <amit.shah@redhat.com>
0a122b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
0a122b
Bugzilla: 1011720
0a122b
https://bugzilla.redhat.com/show_bug.cgi?id=1011720
0a122b
0a122b
>From commit ID:
0a122b
commit 0033b8b42a1cc2a9350619ea19e11954b12fb819
0a122b
Author: Michael R. Hines <mrhines@us.ibm.com>
0a122b
Date:   Mon Jul 22 10:01:55 2013 -0400
0a122b
0a122b
    rdma: send pc.ram
0a122b
0a122b
    This takes advantages of the previous patches:
0a122b
0a122b
    1. use the new QEMUFileOps hook 'save_page'
0a122b
0a122b
    2. call out to the right accessor methods to invoke
0a122b
       the iteration hooks defined in QEMUFileOps
0a122b
0a122b
    Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
    Reviewed-by: Chegu Vinod <chegu_vinod@hp.com>
0a122b
    Tested-by: Chegu Vinod <chegu_vinod@hp.com>
0a122b
    Tested-by: Michael R. Hines <mrhines@us.ibm.com>
0a122b
    Signed-off-by: Michael R. Hines <mrhines@us.ibm.com>
0a122b
    Signed-off-by: Juan Quintela <quintela@redhat.com>
0a122b
---
0a122b
 arch_init.c |   33 ++++++++++++++++++++++++++++++++-
0a122b
 1 files changed, 32 insertions(+), 1 deletions(-)
0a122b
0a122b
Signed-off-by: Michal Novotny <minovotn@redhat.com>
0a122b
---
0a122b
 arch_init.c | 33 ++++++++++++++++++++++++++++++++-
0a122b
 1 file changed, 32 insertions(+), 1 deletion(-)
0a122b
0a122b
diff --git a/arch_init.c b/arch_init.c
0a122b
index e7da520..034341c 100644
0a122b
--- a/arch_init.c
0a122b
+++ b/arch_init.c
0a122b
@@ -118,6 +118,7 @@ static void check_guest_throttling(void);
0a122b
 #define RAM_SAVE_FLAG_EOS      0x10
0a122b
 #define RAM_SAVE_FLAG_CONTINUE 0x20
0a122b
 #define RAM_SAVE_FLAG_XBZRLE   0x40
0a122b
+/* 0x80 is reserved in migration.h start with 0x100 next */
0a122b
 
0a122b
 
0a122b
 static struct defconfig_file {
0a122b
@@ -476,6 +477,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
0a122b
                 ram_bulk_stage = false;
0a122b
             }
0a122b
         } else {
0a122b
+            int ret;
0a122b
             uint8_t *p;
0a122b
             int cont = (block == last_sent_block) ?
0a122b
                 RAM_SAVE_FLAG_CONTINUE : 0;
0a122b
@@ -484,7 +486,18 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
0a122b
 
0a122b
             /* In doubt sent page as normal */
0a122b
             bytes_sent = -1;
0a122b
-            if (is_zero_page(p)) {
0a122b
+            ret = ram_control_save_page(f, block->offset,
0a122b
+                               offset, TARGET_PAGE_SIZE, &bytes_sent);
0a122b
+
0a122b
+            if (ret != RAM_SAVE_CONTROL_NOT_SUPP) {
0a122b
+                if (ret != RAM_SAVE_CONTROL_DELAYED) {
0a122b
+                    if (bytes_sent > 0) {
0a122b
+                        acct_info.norm_pages++;
0a122b
+                    } else if (bytes_sent == 0) {
0a122b
+                        acct_info.dup_pages++;
0a122b
+                    }
0a122b
+                }
0a122b
+            } else if (is_zero_page(p)) {
0a122b
                 acct_info.dup_pages++;
0a122b
                 bytes_sent = save_block_hdr(f, block, offset, cont,
0a122b
                                             RAM_SAVE_FLAG_COMPRESS);
0a122b
@@ -636,6 +649,10 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
0a122b
     }
0a122b
 
0a122b
     qemu_mutex_unlock_ramlist();
0a122b
+
0a122b
+    ram_control_before_iterate(f, RAM_CONTROL_SETUP);
0a122b
+    ram_control_after_iterate(f, RAM_CONTROL_SETUP);
0a122b
+
0a122b
     qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
0a122b
 
0a122b
     return 0;
0a122b
@@ -654,6 +671,8 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
0a122b
         reset_ram_globals();
0a122b
     }
0a122b
 
0a122b
+    ram_control_before_iterate(f, RAM_CONTROL_ROUND);
0a122b
+
0a122b
     t0 = qemu_get_clock_ns(rt_clock);
0a122b
     i = 0;
0a122b
     while ((ret = qemu_file_rate_limit(f)) == 0) {
0a122b
@@ -685,6 +704,12 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
0a122b
 
0a122b
     qemu_mutex_unlock_ramlist();
0a122b
 
0a122b
+    /*
0a122b
+     * Must occur before EOS (or any QEMUFile operation)
0a122b
+     * because of RDMA protocol.
0a122b
+     */
0a122b
+    ram_control_after_iterate(f, RAM_CONTROL_ROUND);
0a122b
+
0a122b
     if (ret < 0) {
0a122b
         bytes_transferred += total_sent;
0a122b
         return ret;
0a122b
@@ -702,6 +727,8 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
0a122b
     qemu_mutex_lock_ramlist();
0a122b
     migration_bitmap_sync();
0a122b
 
0a122b
+    ram_control_before_iterate(f, RAM_CONTROL_FINISH);
0a122b
+
0a122b
     /* try transferring iterative blocks of memory */
0a122b
 
0a122b
     /* flush all remaining blocks regardless of rate limiting */
0a122b
@@ -715,6 +742,8 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
0a122b
         }
0a122b
         bytes_transferred += bytes_sent;
0a122b
     }
0a122b
+
0a122b
+    ram_control_after_iterate(f, RAM_CONTROL_FINISH);
0a122b
     migration_end();
0a122b
 
0a122b
     qemu_mutex_unlock_ramlist();
0a122b
@@ -914,6 +943,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
0a122b
                 ret = -EINVAL;
0a122b
                 goto done;
0a122b
             }
0a122b
+        } else if (flags & RAM_SAVE_FLAG_HOOK) {
0a122b
+            ram_control_load_hook(f, flags);
0a122b
         }
0a122b
         error = qemu_file_get_error(f);
0a122b
         if (error) {
0a122b
-- 
0a122b
1.7.11.7
0a122b