Blame SOURCES/kvm-job-Replace-BlockJob.completed-with-job_is_completed.patch

357786
From bafcb1e3ffe5b9af344a7891f6a62eb296687a43 Mon Sep 17 00:00:00 2001
357786
From: Kevin Wolf <kwolf@redhat.com>
357786
Date: Tue, 26 Jun 2018 09:48:12 +0200
357786
Subject: [PATCH 43/89] job: Replace BlockJob.completed with job_is_completed()
357786
357786
RH-Author: Kevin Wolf <kwolf@redhat.com>
357786
Message-id: <20180626094856.6924-30-kwolf@redhat.com>
357786
Patchwork-id: 81094
357786
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 29/73] job: Replace BlockJob.completed with job_is_completed()
357786
Bugzilla: 1513543
357786
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
357786
RH-Acked-by: Max Reitz <mreitz@redhat.com>
357786
RH-Acked-by: Fam Zheng <famz@redhat.com>
357786
357786
Since we introduced an explicit status to block job, BlockJob.completed
357786
is redundant because it can be derived from the status. Remove the field
357786
from BlockJob and add a function to derive it from the status at the Job
357786
level.
357786
357786
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
357786
Reviewed-by: Max Reitz <mreitz@redhat.com>
357786
Reviewed-by: John Snow <jsnow@redhat.com>
357786
(cherry picked from commit dbe5e6c1f73b41282624b78a2375a5c3ee59e905)
357786
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
---
357786
 blockjob.c               | 16 +++++++---------
357786
 include/block/blockjob.h |  3 ---
357786
 include/qemu/job.h       |  3 +++
357786
 job.c                    | 22 ++++++++++++++++++++++
357786
 qemu-img.c               |  4 ++--
357786
 5 files changed, 34 insertions(+), 14 deletions(-)
357786
357786
diff --git a/blockjob.c b/blockjob.c
357786
index 6334a54..a1d1f48 100644
357786
--- a/blockjob.c
357786
+++ b/blockjob.c
357786
@@ -193,7 +193,7 @@ static void block_job_detach_aio_context(void *opaque)
357786
 
357786
     job_pause(&job->job);
357786
 
357786
-    while (!job->job.paused && !job->completed) {
357786
+    while (!job->job.paused && !job_is_completed(&job->job)) {
357786
         block_job_drain(job);
357786
     }
357786
 
357786
@@ -269,7 +269,6 @@ const BlockJobDriver *block_job_driver(BlockJob *job)
357786
 static void block_job_decommission(BlockJob *job)
357786
 {
357786
     assert(job);
357786
-    job->completed = true;
357786
     job->job.busy = false;
357786
     job->job.paused = false;
357786
     job->job.deferred_to_main_loop = true;
357786
@@ -334,7 +333,7 @@ static void block_job_clean(BlockJob *job)
357786
 
357786
 static int block_job_finalize_single(BlockJob *job)
357786
 {
357786
-    assert(job->completed);
357786
+    assert(job_is_completed(&job->job));
357786
 
357786
     /* Ensure abort is called for late-transactional failures */
357786
     block_job_update_rc(job);
357786
@@ -427,10 +426,10 @@ static int block_job_finish_sync(BlockJob *job,
357786
     /* block_job_drain calls block_job_enter, and it should be enough to
357786
      * induce progress until the job completes or moves to the main thread.
357786
     */
357786
-    while (!job->job.deferred_to_main_loop && !job->completed) {
357786
+    while (!job->job.deferred_to_main_loop && !job_is_completed(&job->job)) {
357786
         block_job_drain(job);
357786
     }
357786
-    while (!job->completed) {
357786
+    while (!job_is_completed(&job->job)) {
357786
         aio_poll(qemu_get_aio_context(), true);
357786
     }
357786
     ret = (job_is_cancelled(&job->job) && job->ret == 0)
357786
@@ -471,7 +470,7 @@ static void block_job_completed_txn_abort(BlockJob *job)
357786
     while (!QLIST_EMPTY(&txn->jobs)) {
357786
         other_job = QLIST_FIRST(&txn->jobs);
357786
         ctx = blk_get_aio_context(other_job->blk);
357786
-        if (!other_job->completed) {
357786
+        if (!job_is_completed(&other_job->job)) {
357786
             assert(job_is_cancelled(&other_job->job));
357786
             block_job_finish_sync(other_job, NULL, NULL);
357786
         }
357786
@@ -513,7 +512,7 @@ static void block_job_completed_txn_success(BlockJob *job)
357786
      * txn.
357786
      */
357786
     QLIST_FOREACH(other_job, &txn->jobs, txn_list) {
357786
-        if (!other_job->completed) {
357786
+        if (!job_is_completed(&other_job->job)) {
357786
             return;
357786
         }
357786
         assert(other_job->ret == 0);
357786
@@ -847,9 +846,8 @@ void block_job_early_fail(BlockJob *job)
357786
 
357786
 void block_job_completed(BlockJob *job, int ret)
357786
 {
357786
-    assert(job && job->txn && !job->completed);
357786
+    assert(job && job->txn && !job_is_completed(&job->job));
357786
     assert(blk_bs(job->blk)->job == job);
357786
-    job->completed = true;
357786
     job->ret = ret;
357786
     block_job_update_rc(job);
357786
     trace_block_job_completed(job, ret, job->ret);
357786
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
357786
index 556a8f6..3e94e18 100644
357786
--- a/include/block/blockjob.h
357786
+++ b/include/block/blockjob.h
357786
@@ -88,9 +88,6 @@ typedef struct BlockJob {
357786
     /** The opaque value that is passed to the completion function.  */
357786
     void *opaque;
357786
 
357786
-    /** True when job has reported completion by calling block_job_completed. */
357786
-    bool completed;
357786
-
357786
     /** ret code passed to block_job_completed. */
357786
     int ret;
357786
 
357786
diff --git a/include/qemu/job.h b/include/qemu/job.h
357786
index bc63985..858f3be 100644
357786
--- a/include/qemu/job.h
357786
+++ b/include/qemu/job.h
357786
@@ -214,6 +214,9 @@ const char *job_type_str(const Job *job);
357786
 /** Returns whether the job is scheduled for cancellation. */
357786
 bool job_is_cancelled(Job *job);
357786
 
357786
+/** Returns whether the job is in a completed state. */
357786
+bool job_is_completed(Job *job);
357786
+
357786
 /**
357786
  * Request @job to pause at the next pause point. Must be paired with
357786
  * job_resume(). If the job is supposed to be resumed by user action, call
357786
diff --git a/job.c b/job.c
357786
index fd10b1d..aaacfcc 100644
357786
--- a/job.c
357786
+++ b/job.c
357786
@@ -121,6 +121,28 @@ bool job_is_cancelled(Job *job)
357786
     return job->cancelled;
357786
 }
357786
 
357786
+bool job_is_completed(Job *job)
357786
+{
357786
+    switch (job->status) {
357786
+    case JOB_STATUS_UNDEFINED:
357786
+    case JOB_STATUS_CREATED:
357786
+    case JOB_STATUS_RUNNING:
357786
+    case JOB_STATUS_PAUSED:
357786
+    case JOB_STATUS_READY:
357786
+    case JOB_STATUS_STANDBY:
357786
+        return false;
357786
+    case JOB_STATUS_WAITING:
357786
+    case JOB_STATUS_PENDING:
357786
+    case JOB_STATUS_ABORTING:
357786
+    case JOB_STATUS_CONCLUDED:
357786
+    case JOB_STATUS_NULL:
357786
+        return true;
357786
+    default:
357786
+        g_assert_not_reached();
357786
+    }
357786
+    return false;
357786
+}
357786
+
357786
 bool job_started(Job *job)
357786
 {
357786
     return job->co;
357786
diff --git a/qemu-img.c b/qemu-img.c
357786
index f745919..f5bb0ef 100644
357786
--- a/qemu-img.c
357786
+++ b/qemu-img.c
357786
@@ -878,9 +878,9 @@ static void run_block_job(BlockJob *job, Error **errp)
357786
         aio_poll(aio_context, true);
357786
         qemu_progress_print(job->len ?
357786
                             ((float)job->offset / job->len * 100.f) : 0.0f, 0);
357786
-    } while (!job->ready && !job->completed);
357786
+    } while (!job->ready && !job_is_completed(&job->job));
357786
 
357786
-    if (!job->completed) {
357786
+    if (!job_is_completed(&job->job)) {
357786
         ret = block_job_complete_sync(job, errp);
357786
     } else {
357786
         ret = job->ret;
357786
-- 
357786
1.8.3.1
357786