cryptospore / rpms / qemu-kvm

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