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

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