diff options
Diffstat (limited to 'blockjob.c')
-rw-r--r-- | blockjob.c | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/blockjob.c b/blockjob.c index 21cc3ee332..874b573bd5 100644 --- a/blockjob.c +++ b/blockjob.c @@ -257,6 +257,32 @@ static bool block_job_should_pause(BlockJob *job) return job->pause_count > 0; } +void coroutine_fn block_job_pause_point(BlockJob *job) +{ + if (!block_job_should_pause(job)) { + return; + } + if (block_job_is_cancelled(job)) { + return; + } + + if (job->driver->pause) { + job->driver->pause(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; + job->paused = false; + } + + if (job->driver->resume) { + job->driver->resume(job); + } +} + void block_job_resume(BlockJob *job) { assert(job->pause_count > 0); @@ -364,11 +390,9 @@ void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns) if (!block_job_should_pause(job)) { co_aio_sleep_ns(blk_get_aio_context(job->blk), type, ns); } - /* The job can be paused while sleeping, so check this again */ - if (block_job_should_pause(job)) { - qemu_coroutine_yield(); - } job->busy = true; + + block_job_pause_point(job); } void block_job_yield(BlockJob *job) @@ -381,8 +405,12 @@ void block_job_yield(BlockJob *job) } job->busy = false; - qemu_coroutine_yield(); + if (!block_job_should_pause(job)) { + qemu_coroutine_yield(); + } job->busy = true; + + block_job_pause_point(job); } BlockJobInfo *block_job_query(BlockJob *job) |