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