aboutsummaryrefslogtreecommitdiff
path: root/blockjob.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2018-04-20 17:00:29 +0200
committerKevin Wolf <kwolf@redhat.com>2018-05-23 14:30:50 +0200
commitb69f777dd9ba992fdd35828a90eefcd88c0ec332 (patch)
tree17a25005638cf2c9b8317751249374ccf060ce7f /blockjob.c
parent004e95df98266da33e08c9f1731aca71b6d6d7c4 (diff)
job: Add job_drain()
block_job_drain() contains a blk_drain() call which cannot be moved to Job, so add a new JobDriver callback JobDriver.drain which has a common implementation for all BlockJobs. In addition to this we keep the existing BlockJobDriver.drain callback that is called by the common drain implementation for all block jobs. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'blockjob.c')
-rw-r--r--blockjob.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/blockjob.c b/blockjob.c
index 4cac3670ad..63e166927a 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -169,14 +169,13 @@ static void block_job_attached_aio_context(AioContext *new_context,
job_resume(&job->job);
}
-static void block_job_drain(BlockJob *job)
+void block_job_drain(Job *job)
{
- /* If job is !job->job.busy this kicks it into the next pause point. */
- block_job_enter(job);
+ BlockJob *bjob = container_of(job, BlockJob, job);
- blk_drain(job->blk);
- if (job->driver->drain) {
- job->driver->drain(job);
+ blk_drain(bjob->blk);
+ if (bjob->driver->drain) {
+ bjob->driver->drain(bjob);
}
}
@@ -190,7 +189,7 @@ static void block_job_detach_aio_context(void *opaque)
job_pause(&job->job);
while (!job->job.paused && !job_is_completed(&job->job)) {
- block_job_drain(job);
+ job_drain(&job->job);
}
job->job.aio_context = NULL;
@@ -327,11 +326,11 @@ static int block_job_finish_sync(BlockJob *job,
job_unref(&job->job);
return -EBUSY;
}
- /* 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.
+ /* job_drain calls job_enter, and it should be enough to induce progress
+ * until the job completes or moves to the main thread.
*/
while (!job->job.deferred_to_main_loop && !job_is_completed(&job->job)) {
- block_job_drain(job);
+ job_drain(&job->job);
}
while (!job_is_completed(&job->job)) {
aio_poll(qemu_get_aio_context(), true);
@@ -713,6 +712,7 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver,
assert(is_block_job(&job->job));
assert(job->job.driver->free == &block_job_free);
assert(job->job.driver->user_resume == &block_job_user_resume);
+ assert(job->job.driver->drain == &block_job_drain);
job->driver = driver;
job->blk = blk;