yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
26ba25
From f4414f5600168109da86e321f1651f71605cf9aa Mon Sep 17 00:00:00 2001
26ba25
From: Kevin Wolf <kwolf@redhat.com>
26ba25
Date: Wed, 10 Oct 2018 20:21:45 +0100
26ba25
Subject: [PATCH 19/49] block: Allow AIO_WAIT_WHILE with NULL ctx
26ba25
26ba25
RH-Author: Kevin Wolf <kwolf@redhat.com>
26ba25
Message-id: <20181010202213.7372-7-kwolf@redhat.com>
26ba25
Patchwork-id: 82596
26ba25
O-Subject: [RHEL-8 qemu-kvm PATCH 16/44] block: Allow AIO_WAIT_WHILE with NULL ctx
26ba25
Bugzilla: 1637976
26ba25
RH-Acked-by: Max Reitz <mreitz@redhat.com>
26ba25
RH-Acked-by: John Snow <jsnow@redhat.com>
26ba25
RH-Acked-by: Thomas Huth <thuth@redhat.com>
26ba25
26ba25
bdrv_drain_all() wants to have a single polling loop for draining the
26ba25
in-flight requests of all nodes. This means that the AIO_WAIT_WHILE()
26ba25
condition relies on activity in multiple AioContexts, which is polled
26ba25
from the mainloop context. We must therefore call AIO_WAIT_WHILE() from
26ba25
the mainloop thread and use the AioWait notification mechanism.
26ba25
26ba25
Just randomly picking the AioContext of any non-mainloop thread would
26ba25
work, but instead of bothering to find such a context in the caller, we
26ba25
can just as well accept NULL for ctx.
26ba25
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
(cherry picked from commit 4d22bbf4ef72583eefdf44db6bf9fc7683fbc4c2)
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
26ba25
---
26ba25
 include/block/aio-wait.h | 13 +++++++++----
26ba25
 1 file changed, 9 insertions(+), 4 deletions(-)
26ba25
26ba25
diff --git a/include/block/aio-wait.h b/include/block/aio-wait.h
26ba25
index 783d367..c85a62f 100644
26ba25
--- a/include/block/aio-wait.h
26ba25
+++ b/include/block/aio-wait.h
26ba25
@@ -57,7 +57,8 @@ typedef struct {
26ba25
 /**
26ba25
  * AIO_WAIT_WHILE:
26ba25
  * @wait: the aio wait object
26ba25
- * @ctx: the aio context
26ba25
+ * @ctx: the aio context, or NULL if multiple aio contexts (for which the
26ba25
+ *       caller does not hold a lock) are involved in the polling condition.
26ba25
  * @cond: wait while this conditional expression is true
26ba25
  *
26ba25
  * Wait while a condition is true.  Use this to implement synchronous
26ba25
@@ -75,7 +76,7 @@ typedef struct {
26ba25
     bool waited_ = false;                                          \
26ba25
     AioWait *wait_ = (wait);                                       \
26ba25
     AioContext *ctx_ = (ctx);                                      \
26ba25
-    if (in_aio_context_home_thread(ctx_)) {                        \
26ba25
+    if (ctx_ && in_aio_context_home_thread(ctx_)) {                \
26ba25
         while ((cond)) {                                           \
26ba25
             aio_poll(ctx_, true);                                  \
26ba25
             waited_ = true;                                        \
26ba25
@@ -86,9 +87,13 @@ typedef struct {
26ba25
         /* Increment wait_->num_waiters before evaluating cond. */ \
26ba25
         atomic_inc(&wait_->num_waiters);                           \
26ba25
         while ((cond)) {                                           \
26ba25
-            aio_context_release(ctx_);                             \
26ba25
+            if (ctx_) {                                            \
26ba25
+                aio_context_release(ctx_);                         \
26ba25
+            }                                                      \
26ba25
             aio_poll(qemu_get_aio_context(), true);                \
26ba25
-            aio_context_acquire(ctx_);                             \
26ba25
+            if (ctx_) {                                            \
26ba25
+                aio_context_acquire(ctx_);                         \
26ba25
+            }                                                      \
26ba25
             waited_ = true;                                        \
26ba25
         }                                                          \
26ba25
         atomic_dec(&wait_->num_waiters);                           \
26ba25
-- 
26ba25
1.8.3.1
26ba25