yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
ae23c9
From 8096c2b37856e96d3eea5dc96537c02f35c534f8 Mon Sep 17 00:00:00 2001
ae23c9
From: Kevin Wolf <kwolf@redhat.com>
ae23c9
Date: Tue, 26 Jun 2018 09:48:08 +0200
ae23c9
Subject: [PATCH 100/268] job: Move defer_to_main_loop to Job
ae23c9
ae23c9
RH-Author: Kevin Wolf <kwolf@redhat.com>
ae23c9
Message-id: <20180626094856.6924-26-kwolf@redhat.com>
ae23c9
Patchwork-id: 81091
ae23c9
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 25/73] job: Move defer_to_main_loop 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
Move the defer_to_main_loop functionality from BlockJob to Job.
ae23c9
ae23c9
The code can be simplified because we can use job->aio_context in
ae23c9
job_defer_to_main_loop_bh() now, instead of having to access the
ae23c9
BlockDriverState.
ae23c9
ae23c9
Probably taking the data->aio_context lock in addition was already
ae23c9
unnecessary in the old code because we didn't actually make use of
ae23c9
anything protected by the old AioContext except getting the new
ae23c9
AioContext, in case it changed between scheduling the BH and running it.
ae23c9
But it's certainly unnecessary now that the BDS isn't accessed at all
ae23c9
any more.
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 1908a5590c7d214b1b6886bc19b81076fb65cec9)
ae23c9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ae23c9
---
ae23c9
 block/backup.c               |  7 +++---
ae23c9
 block/commit.c               | 11 +++++----
ae23c9
 block/mirror.c               | 15 ++++++------
ae23c9
 block/stream.c               | 14 +++++------
ae23c9
 blockjob.c                   | 57 ++++----------------------------------------
ae23c9
 include/block/blockjob.h     |  5 ----
ae23c9
 include/block/blockjob_int.h | 19 ---------------
ae23c9
 include/qemu/job.h           | 20 ++++++++++++++++
ae23c9
 job.c                        | 32 +++++++++++++++++++++++++
ae23c9
 tests/test-bdrv-drain.c      |  7 +++---
ae23c9
 tests/test-blockjob-txn.c    | 13 +++++-----
ae23c9
 tests/test-blockjob.c        |  7 +++---
ae23c9
 12 files changed, 97 insertions(+), 110 deletions(-)
ae23c9
ae23c9
diff --git a/block/backup.c b/block/backup.c
ae23c9
index ef0aa0e..22dd368 100644
ae23c9
--- a/block/backup.c
ae23c9
+++ b/block/backup.c
ae23c9
@@ -317,11 +317,12 @@ typedef struct {
ae23c9
     int ret;
ae23c9
 } BackupCompleteData;
ae23c9
 
ae23c9
-static void backup_complete(BlockJob *job, void *opaque)
ae23c9
+static void backup_complete(Job *job, void *opaque)
ae23c9
 {
ae23c9
+    BlockJob *bjob = container_of(job, BlockJob, job);
ae23c9
     BackupCompleteData *data = opaque;
ae23c9
 
ae23c9
-    block_job_completed(job, data->ret);
ae23c9
+    block_job_completed(bjob, data->ret);
ae23c9
     g_free(data);
ae23c9
 }
ae23c9
 
ae23c9
@@ -519,7 +520,7 @@ static void coroutine_fn backup_run(void *opaque)
ae23c9
 
ae23c9
     data = g_malloc(sizeof(*data));
ae23c9
     data->ret = ret;
ae23c9
-    block_job_defer_to_main_loop(&job->common, backup_complete, data);
ae23c9
+    job_defer_to_main_loop(&job->common.job, backup_complete, data);
ae23c9
 }
ae23c9
 
ae23c9
 static const BlockJobDriver backup_job_driver = {
ae23c9
diff --git a/block/commit.c b/block/commit.c
ae23c9
index 85baea8..d326766 100644
ae23c9
--- a/block/commit.c
ae23c9
+++ b/block/commit.c
ae23c9
@@ -72,9 +72,10 @@ typedef struct {
ae23c9
     int ret;
ae23c9
 } CommitCompleteData;
ae23c9
 
ae23c9
-static void commit_complete(BlockJob *job, void *opaque)
ae23c9
+static void commit_complete(Job *job, void *opaque)
ae23c9
 {
ae23c9
-    CommitBlockJob *s = container_of(job, CommitBlockJob, common);
ae23c9
+    CommitBlockJob *s = container_of(job, CommitBlockJob, common.job);
ae23c9
+    BlockJob *bjob = &s->common;
ae23c9
     CommitCompleteData *data = opaque;
ae23c9
     BlockDriverState *top = blk_bs(s->top);
ae23c9
     BlockDriverState *base = blk_bs(s->base);
ae23c9
@@ -90,7 +91,7 @@ static void commit_complete(BlockJob *job, void *opaque)
ae23c9
      * the normal backing chain can be restored. */
ae23c9
     blk_unref(s->base);
ae23c9
 
ae23c9
-    if (!job_is_cancelled(&s->common.job) && ret == 0) {
ae23c9
+    if (!job_is_cancelled(job) && ret == 0) {
ae23c9
         /* success */
ae23c9
         ret = bdrv_drop_intermediate(s->commit_top_bs, base,
ae23c9
                                      s->backing_file_str);
ae23c9
@@ -114,7 +115,7 @@ static void commit_complete(BlockJob *job, void *opaque)
ae23c9
      * block_job_finish_sync()), block_job_completed() won't free it and
ae23c9
      * therefore the blockers on the intermediate nodes remain. This would
ae23c9
      * cause bdrv_set_backing_hd() to fail. */
ae23c9
-    block_job_remove_all_bdrv(job);
ae23c9
+    block_job_remove_all_bdrv(bjob);
ae23c9
 
ae23c9
     block_job_completed(&s->common, ret);
ae23c9
     g_free(data);
ae23c9
@@ -211,7 +212,7 @@ out:
ae23c9
 
ae23c9
     data = g_malloc(sizeof(*data));
ae23c9
     data->ret = ret;
ae23c9
-    block_job_defer_to_main_loop(&s->common, commit_complete, data);
ae23c9
+    job_defer_to_main_loop(&s->common.job, commit_complete, data);
ae23c9
 }
ae23c9
 
ae23c9
 static const BlockJobDriver commit_job_driver = {
ae23c9
diff --git a/block/mirror.c b/block/mirror.c
ae23c9
index 424072e..90d4ac9 100644
ae23c9
--- a/block/mirror.c
ae23c9
+++ b/block/mirror.c
ae23c9
@@ -484,9 +484,10 @@ typedef struct {
ae23c9
     int ret;
ae23c9
 } MirrorExitData;
ae23c9
 
ae23c9
-static void mirror_exit(BlockJob *job, void *opaque)
ae23c9
+static void mirror_exit(Job *job, void *opaque)
ae23c9
 {
ae23c9
-    MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
ae23c9
+    MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job);
ae23c9
+    BlockJob *bjob = &s->common;
ae23c9
     MirrorExitData *data = opaque;
ae23c9
     AioContext *replace_aio_context = NULL;
ae23c9
     BlockDriverState *src = s->source;
ae23c9
@@ -568,7 +569,7 @@ static void mirror_exit(BlockJob *job, void *opaque)
ae23c9
      * the blockers on the intermediate nodes so that the resulting state is
ae23c9
      * valid. Also give up permissions on mirror_top_bs->backing, which might
ae23c9
      * block the removal. */
ae23c9
-    block_job_remove_all_bdrv(job);
ae23c9
+    block_job_remove_all_bdrv(bjob);
ae23c9
     bdrv_child_try_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL,
ae23c9
                             &error_abort);
ae23c9
     bdrv_replace_node(mirror_top_bs, backing_bs(mirror_top_bs), &error_abort);
ae23c9
@@ -576,9 +577,9 @@ static void mirror_exit(BlockJob *job, void *opaque)
ae23c9
     /* We just changed the BDS the job BB refers to (with either or both of the
ae23c9
      * bdrv_replace_node() calls), so switch the BB back so the cleanup does
ae23c9
      * the right thing. We don't need any permissions any more now. */
ae23c9
-    blk_remove_bs(job->blk);
ae23c9
-    blk_set_perm(job->blk, 0, BLK_PERM_ALL, &error_abort);
ae23c9
-    blk_insert_bs(job->blk, mirror_top_bs, &error_abort);
ae23c9
+    blk_remove_bs(bjob->blk);
ae23c9
+    blk_set_perm(bjob->blk, 0, BLK_PERM_ALL, &error_abort);
ae23c9
+    blk_insert_bs(bjob->blk, mirror_top_bs, &error_abort);
ae23c9
 
ae23c9
     block_job_completed(&s->common, data->ret);
ae23c9
 
ae23c9
@@ -901,7 +902,7 @@ immediate_exit:
ae23c9
     if (need_drain) {
ae23c9
         bdrv_drained_begin(bs);
ae23c9
     }
ae23c9
-    block_job_defer_to_main_loop(&s->common, mirror_exit, data);
ae23c9
+    job_defer_to_main_loop(&s->common.job, mirror_exit, data);
ae23c9
 }
ae23c9
 
ae23c9
 static void mirror_complete(BlockJob *job, Error **errp)
ae23c9
diff --git a/block/stream.c b/block/stream.c
ae23c9
index 22c71ae..0bba816 100644
ae23c9
--- a/block/stream.c
ae23c9
+++ b/block/stream.c
ae23c9
@@ -58,16 +58,16 @@ typedef struct {
ae23c9
     int ret;
ae23c9
 } StreamCompleteData;
ae23c9
 
ae23c9
-static void stream_complete(BlockJob *job, void *opaque)
ae23c9
+static void stream_complete(Job *job, void *opaque)
ae23c9
 {
ae23c9
-    StreamBlockJob *s = container_of(job, StreamBlockJob, common);
ae23c9
+    StreamBlockJob *s = container_of(job, StreamBlockJob, common.job);
ae23c9
+    BlockJob *bjob = &s->common;
ae23c9
     StreamCompleteData *data = opaque;
ae23c9
-    BlockDriverState *bs = blk_bs(job->blk);
ae23c9
+    BlockDriverState *bs = blk_bs(bjob->blk);
ae23c9
     BlockDriverState *base = s->base;
ae23c9
     Error *local_err = NULL;
ae23c9
 
ae23c9
-    if (!job_is_cancelled(&s->common.job) && bs->backing &&
ae23c9
-        data->ret == 0) {
ae23c9
+    if (!job_is_cancelled(job) && bs->backing && data->ret == 0) {
ae23c9
         const char *base_id = NULL, *base_fmt = NULL;
ae23c9
         if (base) {
ae23c9
             base_id = s->backing_file_str;
ae23c9
@@ -88,7 +88,7 @@ out:
ae23c9
     /* Reopen the image back in read-only mode if necessary */
ae23c9
     if (s->bs_flags != bdrv_get_flags(bs)) {
ae23c9
         /* Give up write permissions before making it read-only */
ae23c9
-        blk_set_perm(job->blk, 0, BLK_PERM_ALL, &error_abort);
ae23c9
+        blk_set_perm(bjob->blk, 0, BLK_PERM_ALL, &error_abort);
ae23c9
         bdrv_reopen(bs, s->bs_flags, NULL);
ae23c9
     }
ae23c9
 
ae23c9
@@ -205,7 +205,7 @@ out:
ae23c9
     /* Modify backing chain and close BDSes in main loop */
ae23c9
     data = g_malloc(sizeof(*data));
ae23c9
     data->ret = ret;
ae23c9
-    block_job_defer_to_main_loop(&s->common, stream_complete, data);
ae23c9
+    job_defer_to_main_loop(&s->common.job, stream_complete, data);
ae23c9
 }
ae23c9
 
ae23c9
 static const BlockJobDriver stream_job_driver = {
ae23c9
diff --git a/blockjob.c b/blockjob.c
ae23c9
index 0a0b1c4..3ede511 100644
ae23c9
--- a/blockjob.c
ae23c9
+++ b/blockjob.c
ae23c9
@@ -360,7 +360,7 @@ static void block_job_decommission(BlockJob *job)
ae23c9
     job->completed = true;
ae23c9
     job->busy = false;
ae23c9
     job->paused = false;
ae23c9
-    job->deferred_to_main_loop = true;
ae23c9
+    job->job.deferred_to_main_loop = true;
ae23c9
     block_job_txn_del_job(job);
ae23c9
     job_state_transition(&job->job, JOB_STATUS_NULL);
ae23c9
     job_unref(&job->job);
ae23c9
@@ -515,7 +515,7 @@ 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->deferred_to_main_loop && !job->completed) {
ae23c9
+    while (!job->job.deferred_to_main_loop && !job->completed) {
ae23c9
         block_job_drain(job);
ae23c9
     }
ae23c9
     while (!job->completed) {
ae23c9
@@ -729,7 +729,7 @@ void block_job_cancel(BlockJob *job, bool force)
ae23c9
     block_job_cancel_async(job, force);
ae23c9
     if (!block_job_started(job)) {
ae23c9
         block_job_completed(job, -ECANCELED);
ae23c9
-    } else if (job->deferred_to_main_loop) {
ae23c9
+    } else if (job->job.deferred_to_main_loop) {
ae23c9
         block_job_completed_txn_abort(job);
ae23c9
     } else {
ae23c9
         block_job_enter(job);
ae23c9
@@ -1045,7 +1045,7 @@ static void block_job_enter_cond(BlockJob *job, bool(*fn)(BlockJob *job))
ae23c9
     if (!block_job_started(job)) {
ae23c9
         return;
ae23c9
     }
ae23c9
-    if (job->deferred_to_main_loop) {
ae23c9
+    if (job->job.deferred_to_main_loop) {
ae23c9
         return;
ae23c9
     }
ae23c9
 
ae23c9
@@ -1060,7 +1060,7 @@ static void block_job_enter_cond(BlockJob *job, bool(*fn)(BlockJob *job))
ae23c9
         return;
ae23c9
     }
ae23c9
 
ae23c9
-    assert(!job->deferred_to_main_loop);
ae23c9
+    assert(!job->job.deferred_to_main_loop);
ae23c9
     timer_del(&job->sleep_timer);
ae23c9
     job->busy = true;
ae23c9
     block_job_unlock();
ae23c9
@@ -1166,50 +1166,3 @@ BlockErrorAction block_job_error_action(BlockJob *job, BlockdevOnError on_err,
ae23c9
     }
ae23c9
     return action;
ae23c9
 }
ae23c9
-
ae23c9
-typedef struct {
ae23c9
-    BlockJob *job;
ae23c9
-    AioContext *aio_context;
ae23c9
-    BlockJobDeferToMainLoopFn *fn;
ae23c9
-    void *opaque;
ae23c9
-} BlockJobDeferToMainLoopData;
ae23c9
-
ae23c9
-static void block_job_defer_to_main_loop_bh(void *opaque)
ae23c9
-{
ae23c9
-    BlockJobDeferToMainLoopData *data = opaque;
ae23c9
-    AioContext *aio_context;
ae23c9
-
ae23c9
-    /* Prevent race with block_job_defer_to_main_loop() */
ae23c9
-    aio_context_acquire(data->aio_context);
ae23c9
-
ae23c9
-    /* Fetch BDS AioContext again, in case it has changed */
ae23c9
-    aio_context = blk_get_aio_context(data->job->blk);
ae23c9
-    if (aio_context != data->aio_context) {
ae23c9
-        aio_context_acquire(aio_context);
ae23c9
-    }
ae23c9
-
ae23c9
-    data->fn(data->job, data->opaque);
ae23c9
-
ae23c9
-    if (aio_context != data->aio_context) {
ae23c9
-        aio_context_release(aio_context);
ae23c9
-    }
ae23c9
-
ae23c9
-    aio_context_release(data->aio_context);
ae23c9
-
ae23c9
-    g_free(data);
ae23c9
-}
ae23c9
-
ae23c9
-void block_job_defer_to_main_loop(BlockJob *job,
ae23c9
-                                  BlockJobDeferToMainLoopFn *fn,
ae23c9
-                                  void *opaque)
ae23c9
-{
ae23c9
-    BlockJobDeferToMainLoopData *data = g_malloc(sizeof(*data));
ae23c9
-    data->job = job;
ae23c9
-    data->aio_context = blk_get_aio_context(job->blk);
ae23c9
-    data->fn = fn;
ae23c9
-    data->opaque = opaque;
ae23c9
-    job->deferred_to_main_loop = true;
ae23c9
-
ae23c9
-    aio_bh_schedule_oneshot(qemu_get_aio_context(),
ae23c9
-                            block_job_defer_to_main_loop_bh, data);
ae23c9
-}
ae23c9
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
ae23c9
index 1e708f4..2a9e865 100644
ae23c9
--- a/include/block/blockjob.h
ae23c9
+++ b/include/block/blockjob.h
ae23c9
@@ -92,11 +92,6 @@ typedef struct BlockJob {
ae23c9
      */
ae23c9
     bool ready;
ae23c9
 
ae23c9
-    /**
ae23c9
-     * Set to true when the job has deferred work to the main loop.
ae23c9
-     */
ae23c9
-    bool deferred_to_main_loop;
ae23c9
-
ae23c9
     /** Status that is published by the query-block-jobs QMP API */
ae23c9
     BlockDeviceIoStatus iostatus;
ae23c9
 
ae23c9
diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h
ae23c9
index d64f30e..0c2f8de 100644
ae23c9
--- a/include/block/blockjob_int.h
ae23c9
+++ b/include/block/blockjob_int.h
ae23c9
@@ -233,23 +233,4 @@ void block_job_event_ready(BlockJob *job);
ae23c9
 BlockErrorAction block_job_error_action(BlockJob *job, BlockdevOnError on_err,
ae23c9
                                         int is_read, int error);
ae23c9
 
ae23c9
-typedef void BlockJobDeferToMainLoopFn(BlockJob *job, void *opaque);
ae23c9
-
ae23c9
-/**
ae23c9
- * block_job_defer_to_main_loop:
ae23c9
- * @job: The job
ae23c9
- * @fn: The function to run in the main loop
ae23c9
- * @opaque: The opaque value that is passed to @fn
ae23c9
- *
ae23c9
- * This function must be called by the main job coroutine just before it
ae23c9
- * returns.  @fn is executed in the main loop with the BlockDriverState
ae23c9
- * AioContext acquired.  Block jobs must call bdrv_unref(), bdrv_close(), and
ae23c9
- * anything that uses bdrv_drain_all() in the main loop.
ae23c9
- *
ae23c9
- * The @job AioContext is held while @fn executes.
ae23c9
- */
ae23c9
-void block_job_defer_to_main_loop(BlockJob *job,
ae23c9
-                                  BlockJobDeferToMainLoopFn *fn,
ae23c9
-                                  void *opaque);
ae23c9
-
ae23c9
 #endif
ae23c9
diff --git a/include/qemu/job.h b/include/qemu/job.h
ae23c9
index 01e083f..933e0ab 100644
ae23c9
--- a/include/qemu/job.h
ae23c9
+++ b/include/qemu/job.h
ae23c9
@@ -58,6 +58,9 @@ typedef struct Job {
ae23c9
      */
ae23c9
     bool cancelled;
ae23c9
 
ae23c9
+    /** Set to true when the job has deferred work to the main loop. */
ae23c9
+    bool deferred_to_main_loop;
ae23c9
+
ae23c9
     /** Element of the list of jobs */
ae23c9
     QLIST_ENTRY(Job) job_list;
ae23c9
 } Job;
ae23c9
@@ -131,6 +134,23 @@ Job *job_get(const char *id);
ae23c9
  */
ae23c9
 int job_apply_verb(Job *job, JobVerb verb, Error **errp);
ae23c9
 
ae23c9
+typedef void JobDeferToMainLoopFn(Job *job, void *opaque);
ae23c9
+
ae23c9
+/**
ae23c9
+ * @job: The job
ae23c9
+ * @fn: The function to run in the main loop
ae23c9
+ * @opaque: The opaque value that is passed to @fn
ae23c9
+ *
ae23c9
+ * This function must be called by the main job coroutine just before it
ae23c9
+ * returns.  @fn is executed in the main loop with the job AioContext acquired.
ae23c9
+ *
ae23c9
+ * Block jobs must call bdrv_unref(), bdrv_close(), and anything that uses
ae23c9
+ * bdrv_drain_all() in the main loop.
ae23c9
+ *
ae23c9
+ * The @job AioContext is held while @fn executes.
ae23c9
+ */
ae23c9
+void job_defer_to_main_loop(Job *job, JobDeferToMainLoopFn *fn, void *opaque);
ae23c9
+
ae23c9
 /* TODO To be removed from the public interface */
ae23c9
 void job_state_transition(Job *job, JobStatus s1);
ae23c9
 
ae23c9
diff --git a/job.c b/job.c
ae23c9
index 01074d0..c5a37fb 100644
ae23c9
--- a/job.c
ae23c9
+++ b/job.c
ae23c9
@@ -28,6 +28,7 @@
ae23c9
 #include "qapi/error.h"
ae23c9
 #include "qemu/job.h"
ae23c9
 #include "qemu/id.h"
ae23c9
+#include "qemu/main-loop.h"
ae23c9
 #include "trace-root.h"
ae23c9
 
ae23c9
 static QLIST_HEAD(, Job) jobs = QLIST_HEAD_INITIALIZER(jobs);
ae23c9
@@ -170,3 +171,34 @@ void job_unref(Job *job)
ae23c9
         g_free(job);
ae23c9
     }
ae23c9
 }
ae23c9
+
ae23c9
+typedef struct {
ae23c9
+    Job *job;
ae23c9
+    JobDeferToMainLoopFn *fn;
ae23c9
+    void *opaque;
ae23c9
+} JobDeferToMainLoopData;
ae23c9
+
ae23c9
+static void job_defer_to_main_loop_bh(void *opaque)
ae23c9
+{
ae23c9
+    JobDeferToMainLoopData *data = opaque;
ae23c9
+    Job *job = data->job;
ae23c9
+    AioContext *aio_context = job->aio_context;
ae23c9
+
ae23c9
+    aio_context_acquire(aio_context);
ae23c9
+    data->fn(data->job, data->opaque);
ae23c9
+    aio_context_release(aio_context);
ae23c9
+
ae23c9
+    g_free(data);
ae23c9
+}
ae23c9
+
ae23c9
+void job_defer_to_main_loop(Job *job, JobDeferToMainLoopFn *fn, void *opaque)
ae23c9
+{
ae23c9
+    JobDeferToMainLoopData *data = g_malloc(sizeof(*data));
ae23c9
+    data->job = job;
ae23c9
+    data->fn = fn;
ae23c9
+    data->opaque = opaque;
ae23c9
+    job->deferred_to_main_loop = true;
ae23c9
+
ae23c9
+    aio_bh_schedule_oneshot(qemu_get_aio_context(),
ae23c9
+                            job_defer_to_main_loop_bh, data);
ae23c9
+}
ae23c9
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
ae23c9
index f9e37d4..4f8cba8 100644
ae23c9
--- a/tests/test-bdrv-drain.c
ae23c9
+++ b/tests/test-bdrv-drain.c
ae23c9
@@ -496,9 +496,10 @@ typedef struct TestBlockJob {
ae23c9
     bool should_complete;
ae23c9
 } TestBlockJob;
ae23c9
 
ae23c9
-static void test_job_completed(BlockJob *job, void *opaque)
ae23c9
+static void test_job_completed(Job *job, void *opaque)
ae23c9
 {
ae23c9
-    block_job_completed(job, 0);
ae23c9
+    BlockJob *bjob = container_of(job, BlockJob, job);
ae23c9
+    block_job_completed(bjob, 0);
ae23c9
 }
ae23c9
 
ae23c9
 static void coroutine_fn test_job_start(void *opaque)
ae23c9
@@ -510,7 +511,7 @@ static void coroutine_fn test_job_start(void *opaque)
ae23c9
         block_job_sleep_ns(&s->common, 100000);
ae23c9
     }
ae23c9
 
ae23c9
-    block_job_defer_to_main_loop(&s->common, test_job_completed, NULL);
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
diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c
ae23c9
index 26b4bbb..c03f966 100644
ae23c9
--- a/tests/test-blockjob-txn.c
ae23c9
+++ b/tests/test-blockjob-txn.c
ae23c9
@@ -24,16 +24,17 @@ typedef struct {
ae23c9
     int *result;
ae23c9
 } TestBlockJob;
ae23c9
 
ae23c9
-static void test_block_job_complete(BlockJob *job, void *opaque)
ae23c9
+static void test_block_job_complete(Job *job, void *opaque)
ae23c9
 {
ae23c9
-    BlockDriverState *bs = blk_bs(job->blk);
ae23c9
+    BlockJob *bjob = container_of(job, BlockJob, job);
ae23c9
+    BlockDriverState *bs = blk_bs(bjob->blk);
ae23c9
     int rc = (intptr_t)opaque;
ae23c9
 
ae23c9
-    if (job_is_cancelled(&job->job)) {
ae23c9
+    if (job_is_cancelled(job)) {
ae23c9
         rc = -ECANCELED;
ae23c9
     }
ae23c9
 
ae23c9
-    block_job_completed(job, rc);
ae23c9
+    block_job_completed(bjob, rc);
ae23c9
     bdrv_unref(bs);
ae23c9
 }
ae23c9
 
ae23c9
@@ -54,8 +55,8 @@ static void coroutine_fn test_block_job_run(void *opaque)
ae23c9
         }
ae23c9
     }
ae23c9
 
ae23c9
-    block_job_defer_to_main_loop(job, test_block_job_complete,
ae23c9
-                                 (void *)(intptr_t)s->rc);
ae23c9
+    job_defer_to_main_loop(&job->job, test_block_job_complete,
ae23c9
+                           (void *)(intptr_t)s->rc);
ae23c9
 }
ae23c9
 
ae23c9
 typedef struct {
ae23c9
diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c
ae23c9
index fa31481..5f43bd7 100644
ae23c9
--- a/tests/test-blockjob.c
ae23c9
+++ b/tests/test-blockjob.c
ae23c9
@@ -161,11 +161,12 @@ typedef struct CancelJob {
ae23c9
     bool completed;
ae23c9
 } CancelJob;
ae23c9
 
ae23c9
-static void cancel_job_completed(BlockJob *job, void *opaque)
ae23c9
+static void cancel_job_completed(Job *job, void *opaque)
ae23c9
 {
ae23c9
+    BlockJob *bjob = container_of(job, BlockJob, job);
ae23c9
     CancelJob *s = opaque;
ae23c9
     s->completed = true;
ae23c9
-    block_job_completed(job, 0);
ae23c9
+    block_job_completed(bjob, 0);
ae23c9
 }
ae23c9
 
ae23c9
 static void cancel_job_complete(BlockJob *job, Error **errp)
ae23c9
@@ -191,7 +192,7 @@ static void coroutine_fn cancel_job_start(void *opaque)
ae23c9
     }
ae23c9
 
ae23c9
  defer:
ae23c9
-    block_job_defer_to_main_loop(&s->common, cancel_job_completed, s);
ae23c9
+    job_defer_to_main_loop(&s->common.job, cancel_job_completed, s);
ae23c9
 }
ae23c9
 
ae23c9
 static const BlockJobDriver test_cancel_driver = {
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9