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

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