a3fa63
From: Fam Zheng <famz@redhat.com>
a3fa63
Date: Wed, 13 May 2015 11:11:13 +0800
a3fa63
Subject: [PATCH] block/mirror: Sleep periodically during bitmap scanning
a3fa63
a3fa63
Before, we only yield after initializing dirty bitmap, where the QMP
a3fa63
command would return. That may take very long, and guest IO will be
a3fa63
blocked.
a3fa63
a3fa63
Add sleep points like the later mirror iterations.
a3fa63
a3fa63
Signed-off-by: Fam Zheng <famz@redhat.com>
a3fa63
Reviewed-by: Wen Congyang <wency@cn.fujitsu.com>
a3fa63
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
a3fa63
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
a3fa63
Message-id: 1431486673-19280-1-git-send-email-famz@redhat.com
a3fa63
Signed-off-by: Jeff Cody <jcody@redhat.com>
a3fa63
(cherry picked from commit 4c0cbd6fec7db182a6deb52d5a8a8e7b0c5cbe64)
a3fa63
---
a3fa63
 block/mirror.c | 13 ++++++++++++-
a3fa63
 1 file changed, 12 insertions(+), 1 deletion(-)
a3fa63
a3fa63
diff --git a/block/mirror.c b/block/mirror.c
a3fa63
index 9407287..6f1bc3c 100644
a3fa63
--- a/block/mirror.c
a3fa63
+++ b/block/mirror.c
a3fa63
@@ -453,11 +453,23 @@ static void coroutine_fn mirror_run(void *opaque)
a3fa63
     sectors_per_chunk = s->granularity >> BDRV_SECTOR_BITS;
a3fa63
     mirror_free_init(s);
a3fa63
 
a3fa63
+    last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
a3fa63
     if (!s->is_none_mode) {
a3fa63
         /* First part, loop on the sectors and initialize the dirty bitmap.  */
a3fa63
         BlockDriverState *base = s->base;
a3fa63
         for (sector_num = 0; sector_num < end; ) {
a3fa63
             int64_t next = (sector_num | (sectors_per_chunk - 1)) + 1;
a3fa63
+            int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
a3fa63
+
a3fa63
+            if (now - last_pause_ns > SLICE_TIME) {
a3fa63
+                last_pause_ns = now;
a3fa63
+                block_job_sleep_ns(&s->common, QEMU_CLOCK_REALTIME, 0);
a3fa63
+            }
a3fa63
+
a3fa63
+            if (block_job_is_cancelled(&s->common)) {
a3fa63
+                goto immediate_exit;
a3fa63
+            }
a3fa63
+
a3fa63
             ret = bdrv_is_allocated_above(bs, base,
a3fa63
                                           sector_num, next - sector_num, &n);
a3fa63
 
a3fa63
@@ -476,7 +488,6 @@ static void coroutine_fn mirror_run(void *opaque)
a3fa63
     }
a3fa63
 
a3fa63
     bdrv_dirty_iter_init(bs, s->dirty_bitmap, &s->hbi);
a3fa63
-    last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
a3fa63
     for (;;) {
a3fa63
         uint64_t delay_ns = 0;
a3fa63
         int64_t cnt;