thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

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

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