ae23c9
From c2e95d22694197ccf1fd74b8135f0f73f8ac623c Mon Sep 17 00:00:00 2001
ae23c9
From: Max Reitz <mreitz@redhat.com>
ae23c9
Date: Mon, 18 Jun 2018 14:47:34 +0200
ae23c9
Subject: [PATCH 033/268] block/mirror: honor ratelimit again
ae23c9
ae23c9
RH-Author: Max Reitz <mreitz@redhat.com>
ae23c9
Message-id: <20180618144736.29873-2-mreitz@redhat.com>
ae23c9
Patchwork-id: 80747
ae23c9
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 1/3] block/mirror: honor ratelimit again
ae23c9
Bugzilla: 1572856
ae23c9
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
ae23c9
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
RH-Acked-by: John Snow <jsnow@redhat.com>
ae23c9
ae23c9
From: Stefan Hajnoczi <stefanha@redhat.com>
ae23c9
ae23c9
Commit b76e4458b1eb3c32e9824fe6aa51f67d2b251748 ("block/mirror: change
ae23c9
the semantic of 'force' of block-job-cancel") accidentally removed the
ae23c9
ratelimit in the mirror job.
ae23c9
ae23c9
Reintroduce the ratelimit but keep the block-job-cancel force=true
ae23c9
behavior that was added in commit
ae23c9
b76e4458b1eb3c32e9824fe6aa51f67d2b251748.
ae23c9
ae23c9
Note that block_job_sleep_ns() returns immediately when the job is
ae23c9
cancelled.  Therefore it's safe to unconditionally call
ae23c9
block_job_sleep_ns() - a cancelled job does not sleep.
ae23c9
ae23c9
This commit fixes the non-deterministic qemu-iotests 185 output.  The
ae23c9
test relies on the ratelimit to make the job sleep until the 'quit'
ae23c9
command is processed.  Previously the job could complete before the
ae23c9
'quit' command was received since there was no ratelimit.
ae23c9
ae23c9
Cc: Liang Li <liliang.opensource@gmail.com>
ae23c9
Cc: Jeff Cody <jcody@redhat.com>
ae23c9
Cc: Kevin Wolf <kwolf@redhat.com>
ae23c9
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
ae23c9
Message-id: 20180424123527.19168-1-stefanha@redhat.com
ae23c9
Signed-off-by: Jeff Cody <jcody@redhat.com>
ae23c9
(cherry picked from commit ddc4115efdfa6619689fe18871aa2d37890b3463)
ae23c9
Signed-off-by: Max Reitz <mreitz@redhat.com>
ae23c9
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ae23c9
---
ae23c9
 block/mirror.c             | 8 +++++---
ae23c9
 tests/qemu-iotests/185.out | 2 +-
ae23c9
 2 files changed, 6 insertions(+), 4 deletions(-)
ae23c9
ae23c9
diff --git a/block/mirror.c b/block/mirror.c
ae23c9
index 820f512..9436a8d 100644
ae23c9
--- a/block/mirror.c
ae23c9
+++ b/block/mirror.c
ae23c9
@@ -868,12 +868,14 @@ static void coroutine_fn mirror_run(void *opaque)
ae23c9
         }
ae23c9
 
ae23c9
         ret = 0;
ae23c9
+
ae23c9
+        if (s->synced && !should_complete) {
ae23c9
+            delay_ns = (s->in_flight == 0 && cnt == 0 ? SLICE_TIME : 0);
ae23c9
+        }
ae23c9
         trace_mirror_before_sleep(s, cnt, s->synced, delay_ns);
ae23c9
+        block_job_sleep_ns(&s->common, delay_ns);
ae23c9
         if (block_job_is_cancelled(&s->common) && s->common.force) {
ae23c9
             break;
ae23c9
-        } else if (!should_complete) {
ae23c9
-            delay_ns = (s->in_flight == 0 && cnt == 0 ? SLICE_TIME : 0);
ae23c9
-            block_job_sleep_ns(&s->common, delay_ns);
ae23c9
         }
ae23c9
         s->last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
ae23c9
     }
ae23c9
diff --git a/tests/qemu-iotests/185.out b/tests/qemu-iotests/185.out
ae23c9
index 2c4b04d..992162f 100644
ae23c9
--- a/tests/qemu-iotests/185.out
ae23c9
+++ b/tests/qemu-iotests/185.out
ae23c9
@@ -36,9 +36,9 @@ Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=67108864 backing_file=TEST_DIR/t.q
ae23c9
 {"return": {}}
ae23c9
 Formatting 'TEST_DIR/t.qcow2.copy', fmt=qcow2 size=67108864 cluster_size=65536 lazy_refcounts=off refcount_bits=16
ae23c9
 {"return": {}}
ae23c9
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "disk", "len": 4194304, "offset": 4194304, "speed": 65536, "type": "mirror"}}
ae23c9
 {"return": {}}
ae23c9
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}}
ae23c9
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "disk", "len": 4194304, "offset": 4194304, "speed": 65536, "type": "mirror"}}
ae23c9
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "disk", "len": 4194304, "offset": 4194304, "speed": 65536, "type": "mirror"}}
ae23c9
 
ae23c9
 === Start backup job and exit qemu ===
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9