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