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 <pbonzini@redhat.com>
Tested-By: Jeff Cody <jcody@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Jeff Cody <jcody@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Paolo Bonzini 2017-11-29 11:25:12 +01:00 committed by Kevin Wolf
parent 5bf1d5a73a
commit 356f59b875

View File

@ -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);
}