summaryrefslogtreecommitdiff
path: root/blockjob.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2018-04-17 16:41:17 +0200
committerKevin Wolf <kwolf@redhat.com>2018-05-23 14:30:50 +0200
commit1908a5590c7d214b1b6886bc19b81076fb65cec9 (patch)
tree3ed4b71aa335ca7f13104455a18954570f106b42 /blockjob.c
parent08be6fe26f6c76d900fc987f58d322b94bc4e248 (diff)
job: Move defer_to_main_loop to Job
Move the defer_to_main_loop functionality from BlockJob to Job. The code can be simplified because we can use job->aio_context in job_defer_to_main_loop_bh() now, instead of having to access the BlockDriverState. Probably taking the data->aio_context lock in addition was already unnecessary in the old code because we didn't actually make use of anything protected by the old AioContext except getting the new AioContext, in case it changed between scheduling the BH and running it. But it's certainly unnecessary now that the BDS isn't accessed at all any more. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Reviewed-by: John Snow <jsnow@redhat.com>
Diffstat (limited to 'blockjob.c')
-rw-r--r--blockjob.c57
1 files changed, 5 insertions, 52 deletions
diff --git a/blockjob.c b/blockjob.c
index 0a0b1c41dd..3ede511da0 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -360,7 +360,7 @@ static void block_job_decommission(BlockJob *job)
job->completed = true;
job->busy = false;
job->paused = false;
- job->deferred_to_main_loop = true;
+ job->job.deferred_to_main_loop = true;
block_job_txn_del_job(job);
job_state_transition(&job->job, JOB_STATUS_NULL);
job_unref(&job->job);
@@ -515,7 +515,7 @@ static int block_job_finish_sync(BlockJob *job,
/* block_job_drain calls block_job_enter, and it should be enough to
* induce progress until the job completes or moves to the main thread.
*/
- while (!job->deferred_to_main_loop && !job->completed) {
+ while (!job->job.deferred_to_main_loop && !job->completed) {
block_job_drain(job);
}
while (!job->completed) {
@@ -729,7 +729,7 @@ void block_job_cancel(BlockJob *job, bool force)
block_job_cancel_async(job, force);
if (!block_job_started(job)) {
block_job_completed(job, -ECANCELED);
- } else if (job->deferred_to_main_loop) {
+ } else if (job->job.deferred_to_main_loop) {
block_job_completed_txn_abort(job);
} else {
block_job_enter(job);
@@ -1045,7 +1045,7 @@ static void block_job_enter_cond(BlockJob *job, bool(*fn)(BlockJob *job))
if (!block_job_started(job)) {
return;
}
- if (job->deferred_to_main_loop) {
+ if (job->job.deferred_to_main_loop) {
return;
}
@@ -1060,7 +1060,7 @@ static void block_job_enter_cond(BlockJob *job, bool(*fn)(BlockJob *job))
return;
}
- assert(!job->deferred_to_main_loop);
+ assert(!job->job.deferred_to_main_loop);
timer_del(&job->sleep_timer);
job->busy = true;
block_job_unlock();
@@ -1166,50 +1166,3 @@ BlockErrorAction block_job_error_action(BlockJob *job, BlockdevOnError on_err,
}
return action;
}
-
-typedef struct {
- BlockJob *job;
- AioContext *aio_context;
- BlockJobDeferToMainLoopFn *fn;
- void *opaque;
-} BlockJobDeferToMainLoopData;
-
-static void block_job_defer_to_main_loop_bh(void *opaque)
-{
- BlockJobDeferToMainLoopData *data = opaque;
- AioContext *aio_context;
-
- /* Prevent race with block_job_defer_to_main_loop() */
- aio_context_acquire(data->aio_context);
-
- /* Fetch BDS AioContext again, in case it has changed */
- aio_context = blk_get_aio_context(data->job->blk);
- if (aio_context != data->aio_context) {
- aio_context_acquire(aio_context);
- }
-
- data->fn(data->job, data->opaque);
-
- if (aio_context != data->aio_context) {
- aio_context_release(aio_context);
- }
-
- aio_context_release(data->aio_context);
-
- g_free(data);
-}
-
-void block_job_defer_to_main_loop(BlockJob *job,
- BlockJobDeferToMainLoopFn *fn,
- void *opaque)
-{
- BlockJobDeferToMainLoopData *data = g_malloc(sizeof(*data));
- data->job = job;
- data->aio_context = blk_get_aio_context(job->blk);
- data->fn = fn;
- data->opaque = opaque;
- job->deferred_to_main_loop = true;
-
- aio_bh_schedule_oneshot(qemu_get_aio_context(),
- block_job_defer_to_main_loop_bh, data);
-}