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