From 356f59b8757f47c0aca3e2e4e51d6010f64cade1 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 29 Nov 2017 11:25:12 +0100 Subject: blockjob: introduce block_job_do_yield Hide the clearing of job->busy in a single function, and set it in block_job_enter. This lets block_job_do_yield verify that qemu_coroutine_enter is not used while job->busy = false. Signed-off-by: Paolo Bonzini Tested-By: Jeff Cody Reviewed-by: Fam Zheng Reviewed-by: Jeff Cody Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- blockjob.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/blockjob.c b/blockjob.c index db9e4fc..4d22b7d 100644 --- a/blockjob.c +++ b/blockjob.c @@ -729,6 +729,15 @@ static bool block_job_should_pause(BlockJob *job) return job->pause_count > 0; } +static void block_job_do_yield(BlockJob *job) +{ + job->busy = false; + qemu_coroutine_yield(); + + /* Set by block_job_enter before re-entering the coroutine. */ + assert(job->busy); +} + void coroutine_fn block_job_pause_point(BlockJob *job) { assert(job && block_job_started(job)); @@ -746,9 +755,7 @@ void coroutine_fn block_job_pause_point(BlockJob *job) if (block_job_should_pause(job) && !block_job_is_cancelled(job)) { job->paused = true; - job->busy = false; - qemu_coroutine_yield(); /* wait for block_job_resume() */ - job->busy = true; + block_job_do_yield(job); job->paused = false; } @@ -778,9 +785,12 @@ void block_job_enter(BlockJob *job) return; } - if (!job->busy) { - bdrv_coroutine_enter(blk_bs(job->blk), job->co); + if (job->busy) { + return; } + + job->busy = true; + aio_co_wake(job->co); } bool block_job_is_cancelled(BlockJob *job) @@ -819,11 +829,9 @@ void block_job_yield(BlockJob *job) return; } - job->busy = false; if (!block_job_should_pause(job)) { - qemu_coroutine_yield(); + block_job_do_yield(job); } - job->busy = true; block_job_pause_point(job); } -- cgit v1.1