Blame SOURCES/kvm-job-Convert-block_job_cancel_async-to-Job.patch

1bdc94
From c1d6c990e959598f6a1269756b481e4e4230ded8 Mon Sep 17 00:00:00 2001
1bdc94
From: Kevin Wolf <kwolf@redhat.com>
1bdc94
Date: Tue, 26 Jun 2018 09:48:17 +0200
1bdc94
Subject: [PATCH 48/89] job: Convert block_job_cancel_async() to Job
1bdc94
1bdc94
RH-Author: Kevin Wolf <kwolf@redhat.com>
1bdc94
Message-id: <20180626094856.6924-35-kwolf@redhat.com>
1bdc94
Patchwork-id: 81072
1bdc94
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 34/73] job: Convert block_job_cancel_async() to Job
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
block_job_cancel_async() did two things that were still block job
1bdc94
specific:
1bdc94
1bdc94
* Setting job->force. This field makes sense on the Job level, so we can
1bdc94
  just move it. While at it, rename it to job->force_cancel to make its
1bdc94
  purpose more obvious.
1bdc94
1bdc94
* Resetting the I/O status. This can't be moved because generic Jobs
1bdc94
  don't have an I/O status. What the function really implements is a
1bdc94
  user resume, except without entering the coroutine. Consequently, it
1bdc94
  makes sense to call the .user_resume driver callback here which
1bdc94
  already resets the I/O status.
1bdc94
1bdc94
  The old block_job_cancel_async() has two separate if statements that
1bdc94
  check job->iostatus != BLOCK_DEVICE_IO_STATUS_OK and job->user_paused.
1bdc94
  However, the former condition always implies the latter (as is
1bdc94
  asserted in block_job_iostatus_reset()), so changing the explicit call
1bdc94
  of block_job_iostatus_reset() on the former condition with the
1bdc94
  .user_resume callback on the latter condition is equivalent and
1bdc94
  doesn't need to access any BlockJob specific state.
1bdc94
1bdc94
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
1bdc94
Reviewed-by: Max Reitz <mreitz@redhat.com>
1bdc94
(cherry picked from commit 004e95df98266da33e08c9f1731aca71b6d6d7c4)
1bdc94
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
1bdc94
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
1bdc94
---
1bdc94
 block/mirror.c           |  4 ++--
1bdc94
 blockjob.c               | 25 +++++++++++++------------
1bdc94
 include/block/blockjob.h |  6 ------
1bdc94
 include/qemu/job.h       |  6 ++++++
1bdc94
 4 files changed, 21 insertions(+), 20 deletions(-)
1bdc94
1bdc94
diff --git a/block/mirror.c b/block/mirror.c
1bdc94
index e9a90ea..c3951d1 100644
1bdc94
--- a/block/mirror.c
1bdc94
+++ b/block/mirror.c
1bdc94
@@ -871,7 +871,7 @@ static void coroutine_fn mirror_run(void *opaque)
1bdc94
         trace_mirror_before_sleep(s, cnt, s->synced, delay_ns);
1bdc94
         job_sleep_ns(&s->common.job, delay_ns);
1bdc94
         if (job_is_cancelled(&s->common.job) &&
1bdc94
-            (!s->synced || s->common.force))
1bdc94
+            (!s->synced || s->common.job.force_cancel))
1bdc94
         {
1bdc94
             break;
1bdc94
         }
1bdc94
@@ -884,7 +884,7 @@ immediate_exit:
1bdc94
          * or it was cancelled prematurely so that we do not guarantee that
1bdc94
          * the target is a copy of the source.
1bdc94
          */
1bdc94
-        assert(ret < 0 || ((s->common.force || !s->synced) &&
1bdc94
+        assert(ret < 0 || ((s->common.job.force_cancel || !s->synced) &&
1bdc94
                job_is_cancelled(&s->common.job)));
1bdc94
         assert(need_drain);
1bdc94
         mirror_wait_for_all_io(s);
1bdc94
diff --git a/blockjob.c b/blockjob.c
1bdc94
index 34c57da..4cac367 100644
1bdc94
--- a/blockjob.c
1bdc94
+++ b/blockjob.c
1bdc94
@@ -270,19 +270,20 @@ static int block_job_prepare(BlockJob *job)
1bdc94
     return job->job.ret;
1bdc94
 }
1bdc94
 
1bdc94
-static void block_job_cancel_async(BlockJob *job, bool force)
1bdc94
+static void job_cancel_async(Job *job, bool force)
1bdc94
 {
1bdc94
-    if (job->iostatus != BLOCK_DEVICE_IO_STATUS_OK) {
1bdc94
-        block_job_iostatus_reset(job);
1bdc94
-    }
1bdc94
-    if (job->job.user_paused) {
1bdc94
-        /* Do not call block_job_enter here, the caller will handle it.  */
1bdc94
-        job->job.user_paused = false;
1bdc94
-        job->job.pause_count--;
1bdc94
+    if (job->user_paused) {
1bdc94
+        /* Do not call job_enter here, the caller will handle it.  */
1bdc94
+        job->user_paused = false;
1bdc94
+        if (job->driver->user_resume) {
1bdc94
+            job->driver->user_resume(job);
1bdc94
+        }
1bdc94
+        assert(job->pause_count > 0);
1bdc94
+        job->pause_count--;
1bdc94
     }
1bdc94
-    job->job.cancelled = true;
1bdc94
+    job->cancelled = true;
1bdc94
     /* To prevent 'force == false' overriding a previous 'force == true' */
1bdc94
-    job->force |= force;
1bdc94
+    job->force_cancel |= force;
1bdc94
 }
1bdc94
 
1bdc94
 static int block_job_txn_apply(BlockJobTxn *txn, int fn(BlockJob *), bool lock)
1bdc94
@@ -367,7 +368,7 @@ static void block_job_completed_txn_abort(BlockJob *job)
1bdc94
      * on the caller, so leave it. */
1bdc94
     QLIST_FOREACH(other_job, &txn->jobs, txn_list) {
1bdc94
         if (other_job != job) {
1bdc94
-            block_job_cancel_async(other_job, false);
1bdc94
+            job_cancel_async(&other_job->job, false);
1bdc94
         }
1bdc94
     }
1bdc94
     while (!QLIST_EMPTY(&txn->jobs)) {
1bdc94
@@ -527,7 +528,7 @@ void block_job_cancel(BlockJob *job, bool force)
1bdc94
         job_do_dismiss(&job->job);
1bdc94
         return;
1bdc94
     }
1bdc94
-    block_job_cancel_async(job, force);
1bdc94
+    job_cancel_async(&job->job, force);
1bdc94
     if (!job_started(&job->job)) {
1bdc94
         block_job_completed(job, -ECANCELED);
1bdc94
     } else if (job->job.deferred_to_main_loop) {
1bdc94
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
1bdc94
index 3f405d1..d975efe 100644
1bdc94
--- a/include/block/blockjob.h
1bdc94
+++ b/include/block/blockjob.h
1bdc94
@@ -51,12 +51,6 @@ typedef struct BlockJob {
1bdc94
     BlockBackend *blk;
1bdc94
 
1bdc94
     /**
1bdc94
-     * Set to true if the job should abort immediately without waiting
1bdc94
-     * for data to be in sync.
1bdc94
-     */
1bdc94
-    bool force;
1bdc94
-
1bdc94
-    /**
1bdc94
      * Set to true when the job is ready to be completed.
1bdc94
      */
1bdc94
     bool ready;
1bdc94
diff --git a/include/qemu/job.h b/include/qemu/job.h
1bdc94
index 3e817be..2648c74 100644
1bdc94
--- a/include/qemu/job.h
1bdc94
+++ b/include/qemu/job.h
1bdc94
@@ -97,6 +97,12 @@ typedef struct Job {
1bdc94
      */
1bdc94
     bool cancelled;
1bdc94
 
1bdc94
+    /**
1bdc94
+     * Set to true if the job should abort immediately without waiting
1bdc94
+     * for data to be in sync.
1bdc94
+     */
1bdc94
+    bool force_cancel;
1bdc94
+
1bdc94
     /** Set to true when the job has deferred work to the main loop. */
1bdc94
     bool deferred_to_main_loop;
1bdc94
 
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94