cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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