Blame SOURCES/kvm-blockjob-do-not-cancel-timer-in-resume.patch

357786
From c18e6451e1f5d1c060497f545a624ffdc9733fca Mon Sep 17 00:00:00 2001
357786
From: Kevin Wolf <kwolf@redhat.com>
357786
Date: Tue, 26 Jun 2018 09:47:46 +0200
357786
Subject: [PATCH 17/89] blockjob: do not cancel timer in resume
357786
357786
RH-Author: Kevin Wolf <kwolf@redhat.com>
357786
Message-id: <20180626094856.6924-4-kwolf@redhat.com>
357786
Patchwork-id: 81089
357786
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 03/73] blockjob: do not cancel timer in resume
357786
Bugzilla: 1513543
357786
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
357786
RH-Acked-by: Max Reitz <mreitz@redhat.com>
357786
RH-Acked-by: Fam Zheng <famz@redhat.com>
357786
357786
From: Stefan Hajnoczi <stefanha@redhat.com>
357786
357786
Currently the timer is cancelled and the block job is entered by
357786
block_job_resume().  This behavior causes drain to run extra blockjob
357786
iterations when the job was sleeping due to the ratelimit.
357786
357786
This patch leaves the job asleep when block_job_resume() is called.
357786
Jobs can still be forcibly woken up using block_job_enter(), which is
357786
used to cancel jobs.
357786
357786
After this patch drain no longer runs extra blockjob iterations.  This
357786
is the expected behavior that qemu-iotests 185 used to rely on.  We
357786
temporarily changed the 185 test output to make it pass for the QEMU
357786
2.12 release but now it's time to address this issue.
357786
357786
Cc: QingFeng Hao <haoqf@linux.vnet.ibm.com>
357786
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
357786
Reviewed-by: Eric Blake <eblake@redhat.com>
357786
Reviewed-by: QingFeng Hao <haoqf@linux.vnet.ibm.com>
357786
Message-id: 20180508135436.30140-3-stefanha@redhat.com
357786
Reviewed-by: Jeff Cody <jcody@redhat.com>
357786
Signed-off-by: Jeff Cody <jcody@redhat.com>
357786
(cherry picked from commit 4c7e813ce964e230bb55cf4afc862ccb091ca3a3)
357786
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
---
357786
 blockjob.c                 | 22 +++++++++++++++-------
357786
 tests/qemu-iotests/185     |  5 +----
357786
 tests/qemu-iotests/185.out | 12 +++++-------
357786
 3 files changed, 21 insertions(+), 18 deletions(-)
357786
357786
diff --git a/blockjob.c b/blockjob.c
357786
index 27f957e..7064389 100644
357786
--- a/blockjob.c
357786
+++ b/blockjob.c
357786
@@ -209,6 +209,18 @@ static void block_job_txn_del_job(BlockJob *job)
357786
     }
357786
 }
357786
 
357786
+/* Assumes the block_job_mutex is held */
357786
+static bool block_job_timer_pending(BlockJob *job)
357786
+{
357786
+    return timer_pending(&job->sleep_timer);
357786
+}
357786
+
357786
+/* Assumes the block_job_mutex is held */
357786
+static bool block_job_timer_not_pending(BlockJob *job)
357786
+{
357786
+    return !block_job_timer_pending(job);
357786
+}
357786
+
357786
 static void block_job_pause(BlockJob *job)
357786
 {
357786
     job->pause_count++;
357786
@@ -221,7 +233,9 @@ static void block_job_resume(BlockJob *job)
357786
     if (job->pause_count) {
357786
         return;
357786
     }
357786
-    block_job_enter(job);
357786
+
357786
+    /* kick only if no timer is pending */
357786
+    block_job_enter_cond(job, block_job_timer_not_pending);
357786
 }
357786
 
357786
 void block_job_ref(BlockJob *job)
357786
@@ -651,12 +665,6 @@ static void block_job_completed_txn_success(BlockJob *job)
357786
     }
357786
 }
357786
 
357786
-/* Assumes the block_job_mutex is held */
357786
-static bool block_job_timer_pending(BlockJob *job)
357786
-{
357786
-    return timer_pending(&job->sleep_timer);
357786
-}
357786
-
357786
 void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
357786
 {
357786
     Error *local_err = NULL;
357786
diff --git a/tests/qemu-iotests/185 b/tests/qemu-iotests/185
357786
index 975404c..9a2d317 100755
357786
--- a/tests/qemu-iotests/185
357786
+++ b/tests/qemu-iotests/185
357786
@@ -101,14 +101,11 @@ echo
357786
 # command to be received (after receiving the command, the rest runs
357786
 # synchronously, so jobs can arbitrarily continue or complete).
357786
 #
357786
-# Jobs present while QEMU is terminating iterate once more due to
357786
-# bdrv_drain_all().
357786
-#
357786
 # The buffer size for commit and streaming is 512k (waiting for 8 seconds after
357786
 # the first request), for active commit and mirror it's large enough to cover
357786
 # the full 4M, and for backup it's the qcow2 cluster size, which we know is
357786
 # 64k. As all of these are at least as large as the speed, we are sure that the
357786
-# offset advances exactly twice before qemu exits.
357786
+# offset advances exactly once before qemu exits.
357786
 
357786
 _send_qemu_cmd $h \
357786
     "{ 'execute': 'block-commit',
357786
diff --git a/tests/qemu-iotests/185.out b/tests/qemu-iotests/185.out
357786
index 992162f..57eaf8d 100644
357786
--- a/tests/qemu-iotests/185.out
357786
+++ b/tests/qemu-iotests/185.out
357786
@@ -20,7 +20,7 @@ Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=67108864 backing_file=TEST_DIR/t.q
357786
 {"return": {}}
357786
 {"return": {}}
357786
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}}
357786
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_CANCELLED", "data": {"device": "disk", "len": 67108864, "offset": 1048576, "speed": 65536, "type": "commit"}}
357786
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_CANCELLED", "data": {"device": "disk", "len": 67108864, "offset": 524288, "speed": 65536, "type": "commit"}}
357786
 
357786
 === Start active commit job and exit qemu ===
357786
 
357786
@@ -28,8 +28,7 @@ Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=67108864 backing_file=TEST_DIR/t.q
357786
 {"return": {}}
357786
 {"return": {}}
357786
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}}
357786
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "disk", "len": 4194304, "offset": 4194304, "speed": 65536, "type": "commit"}}
357786
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "disk", "len": 4194304, "offset": 4194304, "speed": 65536, "type": "commit"}}
357786
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_CANCELLED", "data": {"device": "disk", "len": 4194304, "offset": 4194304, "speed": 65536, "type": "commit"}}
357786
 
357786
 === Start mirror job and exit qemu ===
357786
 
357786
@@ -38,8 +37,7 @@ Formatting 'TEST_DIR/t.qcow2.copy', fmt=qcow2 size=67108864 cluster_size=65536 l
357786
 {"return": {}}
357786
 {"return": {}}
357786
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}}
357786
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "disk", "len": 4194304, "offset": 4194304, "speed": 65536, "type": "mirror"}}
357786
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "disk", "len": 4194304, "offset": 4194304, "speed": 65536, "type": "mirror"}}
357786
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_CANCELLED", "data": {"device": "disk", "len": 4194304, "offset": 4194304, "speed": 65536, "type": "mirror"}}
357786
 
357786
 === Start backup job and exit qemu ===
357786
 
357786
@@ -48,7 +46,7 @@ Formatting 'TEST_DIR/t.qcow2.copy', fmt=qcow2 size=67108864 cluster_size=65536 l
357786
 {"return": {}}
357786
 {"return": {}}
357786
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}}
357786
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_CANCELLED", "data": {"device": "disk", "len": 67108864, "offset": 131072, "speed": 65536, "type": "backup"}}
357786
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_CANCELLED", "data": {"device": "disk", "len": 67108864, "offset": 65536, "speed": 65536, "type": "backup"}}
357786
 
357786
 === Start streaming job and exit qemu ===
357786
 
357786
@@ -56,6 +54,6 @@ Formatting 'TEST_DIR/t.qcow2.copy', fmt=qcow2 size=67108864 cluster_size=65536 l
357786
 {"return": {}}
357786
 {"return": {}}
357786
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}}
357786
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_CANCELLED", "data": {"device": "disk", "len": 67108864, "offset": 1048576, "speed": 65536, "type": "stream"}}
357786
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_CANCELLED", "data": {"device": "disk", "len": 67108864, "offset": 524288, "speed": 65536, "type": "stream"}}
357786
 No errors were found on the image.
357786
 *** done
357786
-- 
357786
1.8.3.1
357786