|
|
ae23c9 |
From 011fbd28d5f69f770357bcca6a767605de84fe95 Mon Sep 17 00:00:00 2001
|
|
|
ae23c9 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
ae23c9 |
Date: Wed, 10 Oct 2018 20:22:00 +0100
|
|
|
ae23c9 |
Subject: [PATCH 34/49] job: Use AIO_WAIT_WHILE() in job_finish_sync()
|
|
|
ae23c9 |
|
|
|
ae23c9 |
RH-Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
ae23c9 |
Message-id: <20181010202213.7372-22-kwolf@redhat.com>
|
|
|
ae23c9 |
Patchwork-id: 82612
|
|
|
ae23c9 |
O-Subject: [RHEL-8 qemu-kvm PATCH 31/44] job: Use AIO_WAIT_WHILE() in job_finish_sync()
|
|
|
ae23c9 |
Bugzilla: 1637976
|
|
|
ae23c9 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
ae23c9 |
RH-Acked-by: John Snow <jsnow@redhat.com>
|
|
|
ae23c9 |
RH-Acked-by: Thomas Huth <thuth@redhat.com>
|
|
|
ae23c9 |
|
|
|
ae23c9 |
job_finish_sync() needs to release the AioContext lock of the job before
|
|
|
ae23c9 |
calling aio_poll(). Otherwise, callbacks called by aio_poll() would
|
|
|
ae23c9 |
possibly take the lock a second time and run into a deadlock with a
|
|
|
ae23c9 |
nested AIO_WAIT_WHILE() call.
|
|
|
ae23c9 |
|
|
|
ae23c9 |
Also, job_drain() without aio_poll() isn't necessarily enough to make
|
|
|
ae23c9 |
progress on a job, it could depend on bottom halves to be executed.
|
|
|
ae23c9 |
|
|
|
ae23c9 |
Combine both open-coded while loops into a single AIO_WAIT_WHILE() call
|
|
|
ae23c9 |
that solves both of these problems.
|
|
|
ae23c9 |
|
|
|
ae23c9 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
ae23c9 |
Reviewed-by: Fam Zheng <famz@redhat.com>
|
|
|
ae23c9 |
Reviewed-by: Max Reitz <mreitz@redhat.com>
|
|
|
ae23c9 |
(cherry picked from commit de0fbe64806321fc3e6399bfab360553db87a41d)
|
|
|
ae23c9 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
ae23c9 |
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
|
|
|
ae23c9 |
---
|
|
|
ae23c9 |
job.c | 14 ++++++--------
|
|
|
ae23c9 |
1 file changed, 6 insertions(+), 8 deletions(-)
|
|
|
ae23c9 |
|
|
|
ae23c9 |
diff --git a/job.c b/job.c
|
|
|
ae23c9 |
index 5a0ccc7..47b5a11 100644
|
|
|
ae23c9 |
--- a/job.c
|
|
|
ae23c9 |
+++ b/job.c
|
|
|
ae23c9 |
@@ -29,6 +29,7 @@
|
|
|
ae23c9 |
#include "qemu/job.h"
|
|
|
ae23c9 |
#include "qemu/id.h"
|
|
|
ae23c9 |
#include "qemu/main-loop.h"
|
|
|
ae23c9 |
+#include "block/aio-wait.h"
|
|
|
ae23c9 |
#include "trace-root.h"
|
|
|
ae23c9 |
#include "qapi/qapi-events-job.h"
|
|
|
ae23c9 |
|
|
|
ae23c9 |
@@ -957,6 +958,7 @@ void job_complete(Job *job, Error **errp)
|
|
|
ae23c9 |
int job_finish_sync(Job *job, void (*finish)(Job *, Error **errp), Error **errp)
|
|
|
ae23c9 |
{
|
|
|
ae23c9 |
Error *local_err = NULL;
|
|
|
ae23c9 |
+ AioWait dummy_wait = {};
|
|
|
ae23c9 |
int ret;
|
|
|
ae23c9 |
|
|
|
ae23c9 |
job_ref(job);
|
|
|
ae23c9 |
@@ -969,14 +971,10 @@ int job_finish_sync(Job *job, void (*finish)(Job *, Error **errp), Error **errp)
|
|
|
ae23c9 |
job_unref(job);
|
|
|
ae23c9 |
return -EBUSY;
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
- /* job_drain calls job_enter, and it should be enough to induce progress
|
|
|
ae23c9 |
- * until the job completes or moves to the main thread. */
|
|
|
ae23c9 |
- while (!job->deferred_to_main_loop && !job_is_completed(job)) {
|
|
|
ae23c9 |
- job_drain(job);
|
|
|
ae23c9 |
- }
|
|
|
ae23c9 |
- while (!job_is_completed(job)) {
|
|
|
ae23c9 |
- aio_poll(qemu_get_aio_context(), true);
|
|
|
ae23c9 |
- }
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ AIO_WAIT_WHILE(&dummy_wait, job->aio_context,
|
|
|
ae23c9 |
+ (job_drain(job), !job_is_completed(job)));
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
ret = (job_is_cancelled(job) && job->ret == 0) ? -ECANCELED : job->ret;
|
|
|
ae23c9 |
job_unref(job);
|
|
|
ae23c9 |
return ret;
|
|
|
ae23c9 |
--
|
|
|
ae23c9 |
1.8.3.1
|
|
|
ae23c9 |
|