Blame SOURCES/kvm-job-Use-AIO_WAIT_WHILE-in-job_finish_sync.patch

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