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

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