Blame SOURCES/kvm-job-Move-cancelled-to-Job.patch

1bdc94
From e799889203d2f06adac2c1636b15be360e50f5a2 Mon Sep 17 00:00:00 2001
1bdc94
From: Kevin Wolf <kwolf@redhat.com>
1bdc94
Date: Tue, 26 Jun 2018 09:48:06 +0200
1bdc94
Subject: [PATCH 37/89] job: Move cancelled to Job
1bdc94
1bdc94
RH-Author: Kevin Wolf <kwolf@redhat.com>
1bdc94
Message-id: <20180626094856.6924-24-kwolf@redhat.com>
1bdc94
Patchwork-id: 81103
1bdc94
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 23/73] job: Move cancelled 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
We cannot yet move the whole logic around job cancelling to Job because
1bdc94
it depends on quite a few other things that are still only in BlockJob,
1bdc94
but we can move the cancelled field at least.
1bdc94
1bdc94
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
1bdc94
Reviewed-by: Max Reitz <mreitz@redhat.com>
1bdc94
Reviewed-by: John Snow <jsnow@redhat.com>
1bdc94
(cherry picked from commit daa7f2f9467bc5624f04f28d4b01b88f08c6589c)
1bdc94
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
1bdc94
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
1bdc94
---
1bdc94
 block/backup.c               |  6 +++---
1bdc94
 block/commit.c               |  4 ++--
1bdc94
 block/mirror.c               | 20 ++++++++++----------
1bdc94
 block/stream.c               |  4 ++--
1bdc94
 blockjob.c                   | 28 +++++++++++++---------------
1bdc94
 include/block/blockjob.h     |  8 --------
1bdc94
 include/block/blockjob_int.h |  8 --------
1bdc94
 include/qemu/job.h           | 11 +++++++++++
1bdc94
 job.c                        |  5 +++++
1bdc94
 tests/test-blockjob-txn.c    |  6 +++---
1bdc94
 tests/test-blockjob.c        |  2 +-
1bdc94
 11 files changed, 50 insertions(+), 52 deletions(-)
1bdc94
1bdc94
diff --git a/block/backup.c b/block/backup.c
1bdc94
index cfdb89d..ef0aa0e 100644
1bdc94
--- a/block/backup.c
1bdc94
+++ b/block/backup.c
1bdc94
@@ -329,7 +329,7 @@ static bool coroutine_fn yield_and_check(BackupBlockJob *job)
1bdc94
 {
1bdc94
     uint64_t delay_ns;
1bdc94
 
1bdc94
-    if (block_job_is_cancelled(&job->common)) {
1bdc94
+    if (job_is_cancelled(&job->common.job)) {
1bdc94
         return true;
1bdc94
     }
1bdc94
 
1bdc94
@@ -339,7 +339,7 @@ static bool coroutine_fn yield_and_check(BackupBlockJob *job)
1bdc94
     job->bytes_read = 0;
1bdc94
     block_job_sleep_ns(&job->common, delay_ns);
1bdc94
 
1bdc94
-    if (block_job_is_cancelled(&job->common)) {
1bdc94
+    if (job_is_cancelled(&job->common.job)) {
1bdc94
         return true;
1bdc94
     }
1bdc94
 
1bdc94
@@ -441,7 +441,7 @@ static void coroutine_fn backup_run(void *opaque)
1bdc94
     if (job->sync_mode == MIRROR_SYNC_MODE_NONE) {
1bdc94
         /* All bits are set in copy_bitmap to allow any cluster to be copied.
1bdc94
          * This does not actually require them to be copied. */
1bdc94
-        while (!block_job_is_cancelled(&job->common)) {
1bdc94
+        while (!job_is_cancelled(&job->common.job)) {
1bdc94
             /* Yield until the job is cancelled.  We just let our before_write
1bdc94
              * notify callback service CoW requests. */
1bdc94
             block_job_yield(&job->common);
1bdc94
diff --git a/block/commit.c b/block/commit.c
1bdc94
index 925c96a..85baea8 100644
1bdc94
--- a/block/commit.c
1bdc94
+++ b/block/commit.c
1bdc94
@@ -90,7 +90,7 @@ static void commit_complete(BlockJob *job, void *opaque)
1bdc94
      * the normal backing chain can be restored. */
1bdc94
     blk_unref(s->base);
1bdc94
 
1bdc94
-    if (!block_job_is_cancelled(&s->common) && ret == 0) {
1bdc94
+    if (!job_is_cancelled(&s->common.job) && ret == 0) {
1bdc94
         /* success */
1bdc94
         ret = bdrv_drop_intermediate(s->commit_top_bs, base,
1bdc94
                                      s->backing_file_str);
1bdc94
@@ -172,7 +172,7 @@ static void coroutine_fn commit_run(void *opaque)
1bdc94
          * with no pending I/O here so that bdrv_drain_all() returns.
1bdc94
          */
1bdc94
         block_job_sleep_ns(&s->common, delay_ns);
1bdc94
-        if (block_job_is_cancelled(&s->common)) {
1bdc94
+        if (job_is_cancelled(&s->common.job)) {
1bdc94
             break;
1bdc94
         }
1bdc94
         /* Copy if allocated above the base */
1bdc94
diff --git a/block/mirror.c b/block/mirror.c
1bdc94
index 0df4f70..424072e 100644
1bdc94
--- a/block/mirror.c
1bdc94
+++ b/block/mirror.c
1bdc94
@@ -622,7 +622,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
1bdc94
 
1bdc94
             mirror_throttle(s);
1bdc94
 
1bdc94
-            if (block_job_is_cancelled(&s->common)) {
1bdc94
+            if (job_is_cancelled(&s->common.job)) {
1bdc94
                 s->initial_zeroing_ongoing = false;
1bdc94
                 return 0;
1bdc94
             }
1bdc94
@@ -650,7 +650,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
1bdc94
 
1bdc94
         mirror_throttle(s);
1bdc94
 
1bdc94
-        if (block_job_is_cancelled(&s->common)) {
1bdc94
+        if (job_is_cancelled(&s->common.job)) {
1bdc94
             return 0;
1bdc94
         }
1bdc94
 
1bdc94
@@ -695,7 +695,7 @@ static void coroutine_fn mirror_run(void *opaque)
1bdc94
                                  checking for a NULL string */
1bdc94
     int ret = 0;
1bdc94
 
1bdc94
-    if (block_job_is_cancelled(&s->common)) {
1bdc94
+    if (job_is_cancelled(&s->common.job)) {
1bdc94
         goto immediate_exit;
1bdc94
     }
1bdc94
 
1bdc94
@@ -729,10 +729,10 @@ static void coroutine_fn mirror_run(void *opaque)
1bdc94
         /* Report BLOCK_JOB_READY and wait for complete. */
1bdc94
         block_job_event_ready(&s->common);
1bdc94
         s->synced = true;
1bdc94
-        while (!block_job_is_cancelled(&s->common) && !s->should_complete) {
1bdc94
+        while (!job_is_cancelled(&s->common.job) && !s->should_complete) {
1bdc94
             block_job_yield(&s->common);
1bdc94
         }
1bdc94
-        s->common.cancelled = false;
1bdc94
+        s->common.job.cancelled = false;
1bdc94
         goto immediate_exit;
1bdc94
     }
1bdc94
 
1bdc94
@@ -768,7 +768,7 @@ static void coroutine_fn mirror_run(void *opaque)
1bdc94
     s->last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
1bdc94
     if (!s->is_none_mode) {
1bdc94
         ret = mirror_dirty_init(s);
1bdc94
-        if (ret < 0 || block_job_is_cancelled(&s->common)) {
1bdc94
+        if (ret < 0 || job_is_cancelled(&s->common.job)) {
1bdc94
             goto immediate_exit;
1bdc94
         }
1bdc94
     }
1bdc94
@@ -828,7 +828,7 @@ static void coroutine_fn mirror_run(void *opaque)
1bdc94
             }
1bdc94
 
1bdc94
             should_complete = s->should_complete ||
1bdc94
-                block_job_is_cancelled(&s->common);
1bdc94
+                job_is_cancelled(&s->common.job);
1bdc94
             cnt = bdrv_get_dirty_count(s->dirty_bitmap);
1bdc94
         }
1bdc94
 
1bdc94
@@ -856,7 +856,7 @@ static void coroutine_fn mirror_run(void *opaque)
1bdc94
              * completion.
1bdc94
              */
1bdc94
             assert(QLIST_EMPTY(&bs->tracked_requests));
1bdc94
-            s->common.cancelled = false;
1bdc94
+            s->common.job.cancelled = false;
1bdc94
             need_drain = false;
1bdc94
             break;
1bdc94
         }
1bdc94
@@ -869,7 +869,7 @@ static void coroutine_fn mirror_run(void *opaque)
1bdc94
         }
1bdc94
         trace_mirror_before_sleep(s, cnt, s->synced, delay_ns);
1bdc94
         block_job_sleep_ns(&s->common, delay_ns);
1bdc94
-        if (block_job_is_cancelled(&s->common) &&
1bdc94
+        if (job_is_cancelled(&s->common.job) &&
1bdc94
             (!s->synced || s->common.force))
1bdc94
         {
1bdc94
             break;
1bdc94
@@ -884,7 +884,7 @@ immediate_exit:
1bdc94
          * the target is a copy of the source.
1bdc94
          */
1bdc94
         assert(ret < 0 || ((s->common.force || !s->synced) &&
1bdc94
-               block_job_is_cancelled(&s->common)));
1bdc94
+               job_is_cancelled(&s->common.job)));
1bdc94
         assert(need_drain);
1bdc94
         mirror_wait_for_all_io(s);
1bdc94
     }
1bdc94
diff --git a/block/stream.c b/block/stream.c
1bdc94
index 7273d22..22c71ae 100644
1bdc94
--- a/block/stream.c
1bdc94
+++ b/block/stream.c
1bdc94
@@ -66,7 +66,7 @@ static void stream_complete(BlockJob *job, void *opaque)
1bdc94
     BlockDriverState *base = s->base;
1bdc94
     Error *local_err = NULL;
1bdc94
 
1bdc94
-    if (!block_job_is_cancelled(&s->common) && bs->backing &&
1bdc94
+    if (!job_is_cancelled(&s->common.job) && bs->backing &&
1bdc94
         data->ret == 0) {
1bdc94
         const char *base_id = NULL, *base_fmt = NULL;
1bdc94
         if (base) {
1bdc94
@@ -141,7 +141,7 @@ static void coroutine_fn stream_run(void *opaque)
1bdc94
          * with no pending I/O here so that bdrv_drain_all() returns.
1bdc94
          */
1bdc94
         block_job_sleep_ns(&s->common, delay_ns);
1bdc94
-        if (block_job_is_cancelled(&s->common)) {
1bdc94
+        if (job_is_cancelled(&s->common.job)) {
1bdc94
             break;
1bdc94
         }
1bdc94
 
1bdc94
diff --git a/blockjob.c b/blockjob.c
1bdc94
index 0bf0a26..f4f9956 100644
1bdc94
--- a/blockjob.c
1bdc94
+++ b/blockjob.c
1bdc94
@@ -379,7 +379,7 @@ static void block_job_conclude(BlockJob *job)
1bdc94
 
1bdc94
 static void block_job_update_rc(BlockJob *job)
1bdc94
 {
1bdc94
-    if (!job->ret && block_job_is_cancelled(job)) {
1bdc94
+    if (!job->ret && job_is_cancelled(&job->job)) {
1bdc94
         job->ret = -ECANCELED;
1bdc94
     }
1bdc94
     if (job->ret) {
1bdc94
@@ -438,7 +438,7 @@ static int block_job_finalize_single(BlockJob *job)
1bdc94
 
1bdc94
     /* Emit events only if we actually started */
1bdc94
     if (block_job_started(job)) {
1bdc94
-        if (block_job_is_cancelled(job)) {
1bdc94
+        if (job_is_cancelled(&job->job)) {
1bdc94
             block_job_event_cancelled(job);
1bdc94
         } else {
1bdc94
             const char *msg = NULL;
1bdc94
@@ -464,7 +464,7 @@ static void block_job_cancel_async(BlockJob *job, bool force)
1bdc94
         job->user_paused = false;
1bdc94
         job->pause_count--;
1bdc94
     }
1bdc94
-    job->cancelled = true;
1bdc94
+    job->job.cancelled = true;
1bdc94
     /* To prevent 'force == false' overriding a previous 'force == true' */
1bdc94
     job->force |= force;
1bdc94
 }
1bdc94
@@ -519,7 +519,8 @@ static int block_job_finish_sync(BlockJob *job,
1bdc94
     while (!job->completed) {
1bdc94
         aio_poll(qemu_get_aio_context(), true);
1bdc94
     }
1bdc94
-    ret = (job->cancelled && job->ret == 0) ? -ECANCELED : job->ret;
1bdc94
+    ret = (job_is_cancelled(&job->job) && job->ret == 0)
1bdc94
+          ? -ECANCELED : job->ret;
1bdc94
     job_unref(&job->job);
1bdc94
     return ret;
1bdc94
 }
1bdc94
@@ -557,7 +558,7 @@ static void block_job_completed_txn_abort(BlockJob *job)
1bdc94
         other_job = QLIST_FIRST(&txn->jobs);
1bdc94
         ctx = blk_get_aio_context(other_job->blk);
1bdc94
         if (!other_job->completed) {
1bdc94
-            assert(other_job->cancelled);
1bdc94
+            assert(job_is_cancelled(&other_job->job));
1bdc94
             block_job_finish_sync(other_job, NULL, NULL);
1bdc94
         }
1bdc94
         block_job_finalize_single(other_job);
1bdc94
@@ -651,7 +652,9 @@ void block_job_complete(BlockJob *job, Error **errp)
1bdc94
     if (job_apply_verb(&job->job, JOB_VERB_COMPLETE, errp)) {
1bdc94
         return;
1bdc94
     }
1bdc94
-    if (job->pause_count || job->cancelled || !job->driver->complete) {
1bdc94
+    if (job->pause_count || job_is_cancelled(&job->job) ||
1bdc94
+        !job->driver->complete)
1bdc94
+    {
1bdc94
         error_setg(errp, "The active block job '%s' cannot be completed",
1bdc94
                    job->job.id);
1bdc94
         return;
1bdc94
@@ -1006,7 +1009,7 @@ void coroutine_fn block_job_pause_point(BlockJob *job)
1bdc94
     if (!block_job_should_pause(job)) {
1bdc94
         return;
1bdc94
     }
1bdc94
-    if (block_job_is_cancelled(job)) {
1bdc94
+    if (job_is_cancelled(&job->job)) {
1bdc94
         return;
1bdc94
     }
1bdc94
 
1bdc94
@@ -1014,7 +1017,7 @@ void coroutine_fn block_job_pause_point(BlockJob *job)
1bdc94
         job->driver->pause(job);
1bdc94
     }
1bdc94
 
1bdc94
-    if (block_job_should_pause(job) && !block_job_is_cancelled(job)) {
1bdc94
+    if (block_job_should_pause(job) && !job_is_cancelled(&job->job)) {
1bdc94
         JobStatus status = job->job.status;
1bdc94
         job_state_transition(&job->job, status == JOB_STATUS_READY
1bdc94
                                         ? JOB_STATUS_STANDBY
1bdc94
@@ -1066,17 +1069,12 @@ void block_job_enter(BlockJob *job)
1bdc94
     block_job_enter_cond(job, NULL);
1bdc94
 }
1bdc94
 
1bdc94
-bool block_job_is_cancelled(BlockJob *job)
1bdc94
-{
1bdc94
-    return job->cancelled;
1bdc94
-}
1bdc94
-
1bdc94
 void block_job_sleep_ns(BlockJob *job, int64_t ns)
1bdc94
 {
1bdc94
     assert(job->busy);
1bdc94
 
1bdc94
     /* Check cancellation *before* setting busy = false, too!  */
1bdc94
-    if (block_job_is_cancelled(job)) {
1bdc94
+    if (job_is_cancelled(&job->job)) {
1bdc94
         return;
1bdc94
     }
1bdc94
 
1bdc94
@@ -1092,7 +1090,7 @@ void block_job_yield(BlockJob *job)
1bdc94
     assert(job->busy);
1bdc94
 
1bdc94
     /* Check cancellation *before* setting busy = false, too!  */
1bdc94
-    if (block_job_is_cancelled(job)) {
1bdc94
+    if (job_is_cancelled(&job->job)) {
1bdc94
         return;
1bdc94
     }
1bdc94
 
1bdc94
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
1bdc94
index 087e782..1e708f4 100644
1bdc94
--- a/include/block/blockjob.h
1bdc94
+++ b/include/block/blockjob.h
1bdc94
@@ -57,14 +57,6 @@ typedef struct BlockJob {
1bdc94
     Coroutine *co;
1bdc94
 
1bdc94
     /**
1bdc94
-     * Set to true if the job should cancel itself.  The flag must
1bdc94
-     * always be tested just before toggling the busy flag from false
1bdc94
-     * to true.  After a job has been cancelled, it should only yield
1bdc94
-     * if #aio_poll will ("sooner or later") reenter the coroutine.
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
diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h
1bdc94
index 6f0fe3c..d64f30e 100644
1bdc94
--- a/include/block/blockjob_int.h
1bdc94
+++ b/include/block/blockjob_int.h
1bdc94
@@ -196,14 +196,6 @@ void block_job_early_fail(BlockJob *job);
1bdc94
 void block_job_completed(BlockJob *job, int ret);
1bdc94
 
1bdc94
 /**
1bdc94
- * block_job_is_cancelled:
1bdc94
- * @job: The job being queried.
1bdc94
- *
1bdc94
- * Returns whether the job is scheduled for cancellation.
1bdc94
- */
1bdc94
-bool block_job_is_cancelled(BlockJob *job);
1bdc94
-
1bdc94
-/**
1bdc94
  * block_job_pause_point:
1bdc94
  * @job: The job that is ready to pause.
1bdc94
  *
1bdc94
diff --git a/include/qemu/job.h b/include/qemu/job.h
1bdc94
index 0751e2a..5dfbec5 100644
1bdc94
--- a/include/qemu/job.h
1bdc94
+++ b/include/qemu/job.h
1bdc94
@@ -47,6 +47,14 @@ typedef struct Job {
1bdc94
     /** Current state; See @JobStatus for details. */
1bdc94
     JobStatus status;
1bdc94
 
1bdc94
+    /**
1bdc94
+     * Set to true if the job should cancel itself.  The flag must
1bdc94
+     * always be tested just before toggling the busy flag from false
1bdc94
+     * to true.  After a job has been cancelled, it should only yield
1bdc94
+     * if #aio_poll will ("sooner or later") reenter the coroutine.
1bdc94
+     */
1bdc94
+    bool cancelled;
1bdc94
+
1bdc94
     /** Element of the list of jobs */
1bdc94
     QLIST_ENTRY(Job) job_list;
1bdc94
 } Job;
1bdc94
@@ -93,6 +101,9 @@ JobType job_type(const Job *job);
1bdc94
 /** Returns the enum string for the JobType of a given Job. */
1bdc94
 const char *job_type_str(const Job *job);
1bdc94
 
1bdc94
+/** Returns whether the job is scheduled for cancellation. */
1bdc94
+bool job_is_cancelled(Job *job);
1bdc94
+
1bdc94
 /**
1bdc94
  * Get the next element from the list of block jobs after @job, or the
1bdc94
  * first one if @job is %NULL.
1bdc94
diff --git a/job.c b/job.c
1bdc94
index 926f1de..1abca6a 100644
1bdc94
--- a/job.c
1bdc94
+++ b/job.c
1bdc94
@@ -95,6 +95,11 @@ const char *job_type_str(const Job *job)
1bdc94
     return JobType_str(job_type(job));
1bdc94
 }
1bdc94
 
1bdc94
+bool job_is_cancelled(Job *job)
1bdc94
+{
1bdc94
+    return job->cancelled;
1bdc94
+}
1bdc94
+
1bdc94
 Job *job_next(Job *job)
1bdc94
 {
1bdc94
     if (!job) {
1bdc94
diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c
1bdc94
index b49b28c..26b4bbb 100644
1bdc94
--- a/tests/test-blockjob-txn.c
1bdc94
+++ b/tests/test-blockjob-txn.c
1bdc94
@@ -29,7 +29,7 @@ static void test_block_job_complete(BlockJob *job, void *opaque)
1bdc94
     BlockDriverState *bs = blk_bs(job->blk);
1bdc94
     int rc = (intptr_t)opaque;
1bdc94
 
1bdc94
-    if (block_job_is_cancelled(job)) {
1bdc94
+    if (job_is_cancelled(&job->job)) {
1bdc94
         rc = -ECANCELED;
1bdc94
     }
1bdc94
 
1bdc94
@@ -49,7 +49,7 @@ static void coroutine_fn test_block_job_run(void *opaque)
1bdc94
             block_job_yield(job);
1bdc94
         }
1bdc94
 
1bdc94
-        if (block_job_is_cancelled(job)) {
1bdc94
+        if (job_is_cancelled(&job->job)) {
1bdc94
             break;
1bdc94
         }
1bdc94
     }
1bdc94
@@ -66,7 +66,7 @@ typedef struct {
1bdc94
 static void test_block_job_cb(void *opaque, int ret)
1bdc94
 {
1bdc94
     TestBlockJobCBData *data = opaque;
1bdc94
-    if (!ret && block_job_is_cancelled(&data->job->common)) {
1bdc94
+    if (!ret && job_is_cancelled(&data->job->common.job)) {
1bdc94
         ret = -ECANCELED;
1bdc94
     }
1bdc94
     *data->result = ret;
1bdc94
diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c
1bdc94
index e24fc3f..fa31481 100644
1bdc94
--- a/tests/test-blockjob.c
1bdc94
+++ b/tests/test-blockjob.c
1bdc94
@@ -179,7 +179,7 @@ static void coroutine_fn cancel_job_start(void *opaque)
1bdc94
     CancelJob *s = opaque;
1bdc94
 
1bdc94
     while (!s->should_complete) {
1bdc94
-        if (block_job_is_cancelled(&s->common)) {
1bdc94
+        if (job_is_cancelled(&s->common.job)) {
1bdc94
             goto defer;
1bdc94
         }
1bdc94
 
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94