|
|
357786 |
From e776fb3350daea9851190d6445b4786f4b1f493f Mon Sep 17 00:00:00 2001
|
|
|
357786 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Date: Fri, 14 Sep 2018 10:55:14 +0200
|
|
|
357786 |
Subject: [PATCH 23/49] block: Allow AIO_WAIT_WHILE with NULL ctx
|
|
|
357786 |
|
|
|
357786 |
RH-Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Message-id: <20180914105540.18077-17-kwolf@redhat.com>
|
|
|
357786 |
Patchwork-id: 82168
|
|
|
357786 |
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 16/42] block: Allow AIO_WAIT_WHILE with NULL ctx
|
|
|
357786 |
Bugzilla: 1601212
|
|
|
357786 |
RH-Acked-by: John Snow <jsnow@redhat.com>
|
|
|
357786 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
357786 |
|
|
|
357786 |
bdrv_drain_all() wants to have a single polling loop for draining the
|
|
|
357786 |
in-flight requests of all nodes. This means that the AIO_WAIT_WHILE()
|
|
|
357786 |
condition relies on activity in multiple AioContexts, which is polled
|
|
|
357786 |
from the mainloop context. We must therefore call AIO_WAIT_WHILE() from
|
|
|
357786 |
the mainloop thread and use the AioWait notification mechanism.
|
|
|
357786 |
|
|
|
357786 |
Just randomly picking the AioContext of any non-mainloop thread would
|
|
|
357786 |
work, but instead of bothering to find such a context in the caller, we
|
|
|
357786 |
can just as well accept NULL for ctx.
|
|
|
357786 |
|
|
|
357786 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
(cherry picked from commit 4d22bbf4ef72583eefdf44db6bf9fc7683fbc4c2)
|
|
|
357786 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
357786 |
---
|
|
|
357786 |
include/block/aio-wait.h | 13 +++++++++----
|
|
|
357786 |
1 file changed, 9 insertions(+), 4 deletions(-)
|
|
|
357786 |
|
|
|
357786 |
diff --git a/include/block/aio-wait.h b/include/block/aio-wait.h
|
|
|
357786 |
index 783d367..c85a62f 100644
|
|
|
357786 |
--- a/include/block/aio-wait.h
|
|
|
357786 |
+++ b/include/block/aio-wait.h
|
|
|
357786 |
@@ -57,7 +57,8 @@ typedef struct {
|
|
|
357786 |
/**
|
|
|
357786 |
* AIO_WAIT_WHILE:
|
|
|
357786 |
* @wait: the aio wait object
|
|
|
357786 |
- * @ctx: the aio context
|
|
|
357786 |
+ * @ctx: the aio context, or NULL if multiple aio contexts (for which the
|
|
|
357786 |
+ * caller does not hold a lock) are involved in the polling condition.
|
|
|
357786 |
* @cond: wait while this conditional expression is true
|
|
|
357786 |
*
|
|
|
357786 |
* Wait while a condition is true. Use this to implement synchronous
|
|
|
357786 |
@@ -75,7 +76,7 @@ typedef struct {
|
|
|
357786 |
bool waited_ = false; \
|
|
|
357786 |
AioWait *wait_ = (wait); \
|
|
|
357786 |
AioContext *ctx_ = (ctx); \
|
|
|
357786 |
- if (in_aio_context_home_thread(ctx_)) { \
|
|
|
357786 |
+ if (ctx_ && in_aio_context_home_thread(ctx_)) { \
|
|
|
357786 |
while ((cond)) { \
|
|
|
357786 |
aio_poll(ctx_, true); \
|
|
|
357786 |
waited_ = true; \
|
|
|
357786 |
@@ -86,9 +87,13 @@ typedef struct {
|
|
|
357786 |
/* Increment wait_->num_waiters before evaluating cond. */ \
|
|
|
357786 |
atomic_inc(&wait_->num_waiters); \
|
|
|
357786 |
while ((cond)) { \
|
|
|
357786 |
- aio_context_release(ctx_); \
|
|
|
357786 |
+ if (ctx_) { \
|
|
|
357786 |
+ aio_context_release(ctx_); \
|
|
|
357786 |
+ } \
|
|
|
357786 |
aio_poll(qemu_get_aio_context(), true); \
|
|
|
357786 |
- aio_context_acquire(ctx_); \
|
|
|
357786 |
+ if (ctx_) { \
|
|
|
357786 |
+ aio_context_acquire(ctx_); \
|
|
|
357786 |
+ } \
|
|
|
357786 |
waited_ = true; \
|
|
|
357786 |
} \
|
|
|
357786 |
atomic_dec(&wait_->num_waiters); \
|
|
|
357786 |
--
|
|
|
357786 |
1.8.3.1
|
|
|
357786 |
|