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