aboutsummaryrefslogtreecommitdiff
path: root/job.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2018-04-20 15:33:57 +0200
committerKevin Wolf <kwolf@redhat.com>2018-05-23 14:30:50 +0200
commit6a74c075aca731e7e945201a4ae2336b8e328433 (patch)
tree29eb312c2f1d00edb488a495cb9942db21946fd6 /job.c
parent3453d97243c72988c89a0105fa9546890eae7bd4 (diff)
job: Move job_finish_sync() to Job
block_job_finish_sync() doesn't contain anything block job specific any more, so it can be moved to Job. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'job.c')
-rw-r--r--job.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/job.c b/job.c
index 8ceac0b01e..aa74b4c03b 100644
--- a/job.c
+++ b/job.c
@@ -603,3 +603,31 @@ void job_defer_to_main_loop(Job *job, JobDeferToMainLoopFn *fn, void *opaque)
aio_bh_schedule_oneshot(qemu_get_aio_context(),
job_defer_to_main_loop_bh, data);
}
+
+int job_finish_sync(Job *job, void (*finish)(Job *, Error **errp), Error **errp)
+{
+ Error *local_err = NULL;
+ int ret;
+
+ job_ref(job);
+
+ if (finish) {
+ finish(job, &local_err);
+ }
+ if (local_err) {
+ error_propagate(errp, local_err);
+ job_unref(job);
+ return -EBUSY;
+ }
+ /* 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->deferred_to_main_loop && !job_is_completed(job)) {
+ job_drain(job);
+ }
+ while (!job_is_completed(job)) {
+ aio_poll(qemu_get_aio_context(), true);
+ }
+ ret = (job_is_cancelled(job) && job->ret == 0) ? -ECANCELED : job->ret;
+ job_unref(job);
+ return ret;
+}