yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
ae23c9
From 02727b3014f58b63b589176a191a0ced5def4a65 Mon Sep 17 00:00:00 2001
ae23c9
From: Kevin Wolf <kwolf@redhat.com>
ae23c9
Date: Tue, 26 Jun 2018 09:48:19 +0200
ae23c9
Subject: [PATCH 111/268] job: Move .complete callback to Job
ae23c9
ae23c9
RH-Author: Kevin Wolf <kwolf@redhat.com>
ae23c9
Message-id: <20180626094856.6924-37-kwolf@redhat.com>
ae23c9
Patchwork-id: 81084
ae23c9
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 36/73] job: Move .complete callback to Job
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
This moves the .complete callback that tells a READY job to complete
ae23c9
from BlockJobDriver to JobDriver. The wrapper function job_complete()
ae23c9
doesn't require anything block job specific any more and can be moved
ae23c9
to Job.
ae23c9
ae23c9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
Reviewed-by: Max Reitz <mreitz@redhat.com>
ae23c9
(cherry picked from commit 3453d97243c72988c89a0105fa9546890eae7bd4)
ae23c9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ae23c9
---
ae23c9
 block/mirror.c               | 10 +++++-----
ae23c9
 blockdev.c                   |  2 +-
ae23c9
 blockjob.c                   | 23 +++++------------------
ae23c9
 include/block/blockjob.h     | 10 ----------
ae23c9
 include/block/blockjob_int.h |  6 ------
ae23c9
 include/qemu/job.h           |  8 ++++++++
ae23c9
 job.c                        | 16 ++++++++++++++++
ae23c9
 tests/test-bdrv-drain.c      |  6 +++---
ae23c9
 tests/test-blockjob.c        | 10 +++++-----
ae23c9
 9 files changed, 43 insertions(+), 48 deletions(-)
ae23c9
ae23c9
diff --git a/block/mirror.c b/block/mirror.c
ae23c9
index a579bd8..656237a 100644
ae23c9
--- a/block/mirror.c
ae23c9
+++ b/block/mirror.c
ae23c9
@@ -905,16 +905,16 @@ immediate_exit:
ae23c9
     job_defer_to_main_loop(&s->common.job, mirror_exit, data);
ae23c9
 }
ae23c9
 
ae23c9
-static void mirror_complete(BlockJob *job, Error **errp)
ae23c9
+static void mirror_complete(Job *job, Error **errp)
ae23c9
 {
ae23c9
-    MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
ae23c9
+    MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job);
ae23c9
     BlockDriverState *target;
ae23c9
 
ae23c9
     target = blk_bs(s->target);
ae23c9
 
ae23c9
     if (!s->synced) {
ae23c9
         error_setg(errp, "The active block job '%s' cannot be completed",
ae23c9
-                   job->job.id);
ae23c9
+                   job->id);
ae23c9
         return;
ae23c9
     }
ae23c9
 
ae23c9
@@ -995,8 +995,8 @@ static const BlockJobDriver mirror_job_driver = {
ae23c9
         .drain                  = block_job_drain,
ae23c9
         .start                  = mirror_run,
ae23c9
         .pause                  = mirror_pause,
ae23c9
+        .complete               = mirror_complete,
ae23c9
     },
ae23c9
-    .complete               = mirror_complete,
ae23c9
     .attached_aio_context   = mirror_attached_aio_context,
ae23c9
     .drain                  = mirror_drain,
ae23c9
 };
ae23c9
@@ -1010,8 +1010,8 @@ static const BlockJobDriver commit_active_job_driver = {
ae23c9
         .drain                  = block_job_drain,
ae23c9
         .start                  = mirror_run,
ae23c9
         .pause                  = mirror_pause,
ae23c9
+        .complete               = mirror_complete,
ae23c9
     },
ae23c9
-    .complete               = mirror_complete,
ae23c9
     .attached_aio_context   = mirror_attached_aio_context,
ae23c9
     .drain                  = mirror_drain,
ae23c9
 };
ae23c9
diff --git a/blockdev.c b/blockdev.c
ae23c9
index 24deaf1..dd9a080 100644
ae23c9
--- a/blockdev.c
ae23c9
+++ b/blockdev.c
ae23c9
@@ -3895,7 +3895,7 @@ void qmp_block_job_complete(const char *device, Error **errp)
ae23c9
     }
ae23c9
 
ae23c9
     trace_qmp_block_job_complete(job);
ae23c9
-    block_job_complete(job, errp);
ae23c9
+    job_complete(&job->job, errp);
ae23c9
     aio_context_release(aio_context);
ae23c9
 }
ae23c9
 
ae23c9
diff --git a/blockjob.c b/blockjob.c
ae23c9
index 63e1669..0ca7672 100644
ae23c9
--- a/blockjob.c
ae23c9
+++ b/blockjob.c
ae23c9
@@ -481,24 +481,6 @@ int64_t block_job_ratelimit_get_delay(BlockJob *job, uint64_t n)
ae23c9
     return ratelimit_calculate_delay(&job->limit, n);
ae23c9
 }
ae23c9
 
ae23c9
-void block_job_complete(BlockJob *job, Error **errp)
ae23c9
-{
ae23c9
-    /* Should not be reachable via external interface for internal jobs */
ae23c9
-    assert(job->job.id);
ae23c9
-    if (job_apply_verb(&job->job, JOB_VERB_COMPLETE, errp)) {
ae23c9
-        return;
ae23c9
-    }
ae23c9
-    if (job->job.pause_count || job_is_cancelled(&job->job) ||
ae23c9
-        !job->driver->complete)
ae23c9
-    {
ae23c9
-        error_setg(errp, "The active block job '%s' cannot be completed",
ae23c9
-                   job->job.id);
ae23c9
-        return;
ae23c9
-    }
ae23c9
-
ae23c9
-    job->driver->complete(job, errp);
ae23c9
-}
ae23c9
-
ae23c9
 void block_job_finalize(BlockJob *job, Error **errp)
ae23c9
 {
ae23c9
     assert(job && job->job.id);
ae23c9
@@ -571,6 +553,11 @@ void block_job_cancel_sync_all(void)
ae23c9
     }
ae23c9
 }
ae23c9
 
ae23c9
+static void block_job_complete(BlockJob *job, Error **errp)
ae23c9
+{
ae23c9
+    job_complete(&job->job, errp);
ae23c9
+}
ae23c9
+
ae23c9
 int block_job_complete_sync(BlockJob *job, Error **errp)
ae23c9
 {
ae23c9
     return block_job_finish_sync(job, &block_job_complete, errp);
ae23c9
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
ae23c9
index d975efe..85ce18a 100644
ae23c9
--- a/include/block/blockjob.h
ae23c9
+++ b/include/block/blockjob.h
ae23c9
@@ -154,16 +154,6 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp);
ae23c9
 void block_job_cancel(BlockJob *job, bool force);
ae23c9
 
ae23c9
 /**
ae23c9
- * block_job_complete:
ae23c9
- * @job: The job to be completed.
ae23c9
- * @errp: Error object.
ae23c9
- *
ae23c9
- * Asynchronously complete the specified job.
ae23c9
- */
ae23c9
-void block_job_complete(BlockJob *job, Error **errp);
ae23c9
-
ae23c9
-
ae23c9
-/**
ae23c9
  * block_job_finalize:
ae23c9
  * @job: The job to fully commit and finish.
ae23c9
  * @errp: Error object.
ae23c9
diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h
ae23c9
index 38fe22d..b8ca7bb 100644
ae23c9
--- a/include/block/blockjob_int.h
ae23c9
+++ b/include/block/blockjob_int.h
ae23c9
@@ -39,12 +39,6 @@ struct BlockJobDriver {
ae23c9
     JobDriver job_driver;
ae23c9
 
ae23c9
     /**
ae23c9
-     * Optional callback for job types whose completion must be triggered
ae23c9
-     * manually.
ae23c9
-     */
ae23c9
-    void (*complete)(BlockJob *job, Error **errp);
ae23c9
-
ae23c9
-    /**
ae23c9
      * If the callback is not NULL, prepare will be invoked when all the jobs
ae23c9
      * belonging to the same transaction complete; or upon this job's completion
ae23c9
      * if it is not in a transaction.
ae23c9
diff --git a/include/qemu/job.h b/include/qemu/job.h
ae23c9
index aebc195..8f7f71a 100644
ae23c9
--- a/include/qemu/job.h
ae23c9
+++ b/include/qemu/job.h
ae23c9
@@ -167,6 +167,12 @@ struct JobDriver {
ae23c9
      */
ae23c9
     void (*user_resume)(Job *job);
ae23c9
 
ae23c9
+    /**
ae23c9
+     * Optional callback for job types whose completion must be triggered
ae23c9
+     * manually.
ae23c9
+     */
ae23c9
+    void (*complete)(Job *job, Error **errp);
ae23c9
+
ae23c9
     /*
ae23c9
      * If the callback is not NULL, it will be invoked when the job has to be
ae23c9
      * synchronously cancelled or completed; it should drain any activities
ae23c9
@@ -363,6 +369,8 @@ int job_apply_verb(Job *job, JobVerb verb, Error **errp);
ae23c9
 /** The @job could not be started, free it. */
ae23c9
 void job_early_fail(Job *job);
ae23c9
 
ae23c9
+/** Asynchronously complete the specified @job. */
ae23c9
+void job_complete(Job *job, Error **errp);;
ae23c9
 
ae23c9
 typedef void JobDeferToMainLoopFn(Job *job, void *opaque);
ae23c9
 
ae23c9
diff --git a/job.c b/job.c
ae23c9
index 3772a35..8ceac0b 100644
ae23c9
--- a/job.c
ae23c9
+++ b/job.c
ae23c9
@@ -556,6 +556,22 @@ int job_finalize_single(Job *job)
ae23c9
     return 0;
ae23c9
 }
ae23c9
 
ae23c9
+void job_complete(Job *job, Error **errp)
ae23c9
+{
ae23c9
+    /* Should not be reachable via external interface for internal jobs */
ae23c9
+    assert(job->id);
ae23c9
+    if (job_apply_verb(job, JOB_VERB_COMPLETE, errp)) {
ae23c9
+        return;
ae23c9
+    }
ae23c9
+    if (job->pause_count || job_is_cancelled(job) || !job->driver->complete) {
ae23c9
+        error_setg(errp, "The active block job '%s' cannot be completed",
ae23c9
+                   job->id);
ae23c9
+        return;
ae23c9
+    }
ae23c9
+
ae23c9
+    job->driver->complete(job, errp);
ae23c9
+}
ae23c9
+
ae23c9
 
ae23c9
 typedef struct {
ae23c9
     Job *job;
ae23c9
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
ae23c9
index 58ea566..b428aac 100644
ae23c9
--- a/tests/test-bdrv-drain.c
ae23c9
+++ b/tests/test-bdrv-drain.c
ae23c9
@@ -514,9 +514,9 @@ static void coroutine_fn test_job_start(void *opaque)
ae23c9
     job_defer_to_main_loop(&s->common.job, test_job_completed, NULL);
ae23c9
 }
ae23c9
 
ae23c9
-static void test_job_complete(BlockJob *job, Error **errp)
ae23c9
+static void test_job_complete(Job *job, Error **errp)
ae23c9
 {
ae23c9
-    TestBlockJob *s = container_of(job, TestBlockJob, common);
ae23c9
+    TestBlockJob *s = container_of(job, TestBlockJob, common.job);
ae23c9
     s->should_complete = true;
ae23c9
 }
ae23c9
 
ae23c9
@@ -527,8 +527,8 @@ BlockJobDriver test_job_driver = {
ae23c9
         .user_resume    = block_job_user_resume,
ae23c9
         .drain          = block_job_drain,
ae23c9
         .start          = test_job_start,
ae23c9
+        .complete       = test_job_complete,
ae23c9
     },
ae23c9
-    .complete       = test_job_complete,
ae23c9
 };
ae23c9
 
ae23c9
 static void test_blockjob_common(enum drain_type drain_type)
ae23c9
diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c
ae23c9
index 592a136..e44c608 100644
ae23c9
--- a/tests/test-blockjob.c
ae23c9
+++ b/tests/test-blockjob.c
ae23c9
@@ -171,9 +171,9 @@ static void cancel_job_completed(Job *job, void *opaque)
ae23c9
     block_job_completed(bjob, 0);
ae23c9
 }
ae23c9
 
ae23c9
-static void cancel_job_complete(BlockJob *job, Error **errp)
ae23c9
+static void cancel_job_complete(Job *job, Error **errp)
ae23c9
 {
ae23c9
-    CancelJob *s = container_of(job, CancelJob, common);
ae23c9
+    CancelJob *s = container_of(job, CancelJob, common.job);
ae23c9
     s->should_complete = true;
ae23c9
 }
ae23c9
 
ae23c9
@@ -204,8 +204,8 @@ static const BlockJobDriver test_cancel_driver = {
ae23c9
         .user_resume   = block_job_user_resume,
ae23c9
         .drain         = block_job_drain,
ae23c9
         .start         = cancel_job_start,
ae23c9
+        .complete      = cancel_job_complete,
ae23c9
     },
ae23c9
-    .complete      = cancel_job_complete,
ae23c9
 };
ae23c9
 
ae23c9
 static CancelJob *create_common(BlockJob **pjob)
ae23c9
@@ -333,7 +333,7 @@ static void test_cancel_pending(void)
ae23c9
     block_job_enter(job);
ae23c9
     assert(job->job.status == JOB_STATUS_READY);
ae23c9
 
ae23c9
-    block_job_complete(job, &error_abort);
ae23c9
+    job_complete(&job->job, &error_abort);
ae23c9
     block_job_enter(job);
ae23c9
     while (!s->completed) {
ae23c9
         aio_poll(qemu_get_aio_context(), true);
ae23c9
@@ -357,7 +357,7 @@ static void test_cancel_concluded(void)
ae23c9
     block_job_enter(job);
ae23c9
     assert(job->job.status == JOB_STATUS_READY);
ae23c9
 
ae23c9
-    block_job_complete(job, &error_abort);
ae23c9
+    job_complete(&job->job, &error_abort);
ae23c9
     block_job_enter(job);
ae23c9
     while (!s->completed) {
ae23c9
         aio_poll(qemu_get_aio_context(), true);
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9