aboutsummaryrefslogtreecommitdiff
path: root/blockjob.c
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2016-06-16 17:56:24 +0100
committerStefan Hajnoczi <stefanha@redhat.com>2016-06-20 14:25:36 +0100
commitfc9c0a9c4b2c07cf2b8683f2617af584f14c93e7 (patch)
tree6ba2f4dbb6b1750dde1938c694705f1f04174147 /blockjob.c
parenta7f3b7ff03a4712b9fc1089cc568eea7296af069 (diff)
blockjob: add pause points
Block jobs are coroutines that usually perform I/O but sometimes also sleep or yield. Currently only sleeping or yielded block jobs can be paused. This means jobs that do not sleep or yield (using block_job_yield()) are unaffected by block_job_pause(). Add block_job_pause_point() so that block jobs can mark quiescent points that are suitable for pausing. This solves the problem that it can take a block job a long time to pause if it is performing a long series of I/O operations. Transitioning to paused state involves a .pause()/.resume() callback. These callbacks are used to ensure that I/O and event loop activity has ceased while the job is at a pause point. Note that this patch introduces a stricter pause state than previously. The job->busy flag was incorrectly documented as a quiescent state without I/O pending. This is violated by any job that has I/O pending across sleep or block_job_yield(), like the mirror block job. [Add missing block_job_should_pause() check to avoid deadlock after job->driver->pause() in block_job_pause_point(). --Stefan] Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Message-id: 1466096189-6477-4-git-send-email-stefanha@redhat.com
Diffstat (limited to 'blockjob.c')
-rw-r--r--blockjob.c38
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)