[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v2 16/20] block: Allow AIO_WAIT_WHILE with NULL ctx
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PATCH v2 16/20] block: Allow AIO_WAIT_WHILE with NULL ctx |
Date: |
Tue, 29 May 2018 19:21:52 +0200 |
bdrv_drain_all() wants to have a single polling loop for draining the
in-flight requests of all nodes. This means that the AIO_WAIT_WHILE()
condition relies on activity in multiple AioContexts, which is polled
from the mainloop context. We must therefore call AIO_WAIT_WHILE() from
the mainloop thread and use the AioWait notification mechanism.
Just randomly picking the AioContext of any non-mainloop thread would
work, but instead of bothering to find such a context in the caller, we
can just as well accept NULL for ctx.
Signed-off-by: Kevin Wolf <address@hidden>
---
include/block/aio-wait.h | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/include/block/aio-wait.h b/include/block/aio-wait.h
index 783d3678dd..c85a62f798 100644
--- a/include/block/aio-wait.h
+++ b/include/block/aio-wait.h
@@ -57,7 +57,8 @@ typedef struct {
/**
* AIO_WAIT_WHILE:
* @wait: the aio wait object
- * @ctx: the aio context
+ * @ctx: the aio context, or NULL if multiple aio contexts (for which the
+ * caller does not hold a lock) are involved in the polling condition.
* @cond: wait while this conditional expression is true
*
* Wait while a condition is true. Use this to implement synchronous
@@ -75,7 +76,7 @@ typedef struct {
bool waited_ = false; \
AioWait *wait_ = (wait); \
AioContext *ctx_ = (ctx); \
- if (in_aio_context_home_thread(ctx_)) { \
+ if (ctx_ && in_aio_context_home_thread(ctx_)) { \
while ((cond)) { \
aio_poll(ctx_, true); \
waited_ = true; \
@@ -86,9 +87,13 @@ typedef struct {
/* Increment wait_->num_waiters before evaluating cond. */ \
atomic_inc(&wait_->num_waiters); \
while ((cond)) { \
- aio_context_release(ctx_); \
+ if (ctx_) { \
+ aio_context_release(ctx_); \
+ } \
aio_poll(qemu_get_aio_context(), true); \
- aio_context_acquire(ctx_); \
+ if (ctx_) { \
+ aio_context_acquire(ctx_); \
+ } \
waited_ = true; \
} \
atomic_dec(&wait_->num_waiters); \
--
2.13.6
- [Qemu-block] [PATCH v2 05/20] tests/test-bdrv-drain: bdrv_drain_all() works in coroutines now, (continued)
- [Qemu-block] [PATCH v2 05/20] tests/test-bdrv-drain: bdrv_drain_all() works in coroutines now, Kevin Wolf, 2018/05/29
- [Qemu-block] [PATCH v2 06/20] block: Avoid unnecessary aio_poll() in AIO_WAIT_WHILE(), Kevin Wolf, 2018/05/29
- [Qemu-block] [PATCH v2 07/20] block: Really pause block jobs on drain, Kevin Wolf, 2018/05/29
- [Qemu-block] [PATCH v2 08/20] block: Remove bdrv_drain_recurse(), Kevin Wolf, 2018/05/29
- [Qemu-block] [PATCH v2 09/20] test-bdrv-drain: Add test for node deletion, Kevin Wolf, 2018/05/29
- [Qemu-block] [PATCH v2 11/20] test-bdrv-drain: Test node deletion in subtree recursion, Kevin Wolf, 2018/05/29
- [Qemu-block] [PATCH v2 12/20] block: Don't poll in parent drain callbacks, Kevin Wolf, 2018/05/29
- [Qemu-block] [PATCH v2 10/20] block: Drain recursively with a single BDRV_POLL_WHILE(), Kevin Wolf, 2018/05/29
- [Qemu-block] [PATCH v2 13/20] test-bdrv-drain: Graph change through parent callback, Kevin Wolf, 2018/05/29
- [Qemu-block] [PATCH v2 14/20] block: Defer .bdrv_drain_begin callback to polling phase, Kevin Wolf, 2018/05/29
- [Qemu-block] [PATCH v2 16/20] block: Allow AIO_WAIT_WHILE with NULL ctx,
Kevin Wolf <=
- [Qemu-block] [PATCH v2 15/20] test-bdrv-drain: Test that bdrv_drain_invoke() doesn't poll, Kevin Wolf, 2018/05/29
- [Qemu-block] [PATCH v2 17/20] block: Move bdrv_drain_all_begin() out of coroutine context, Kevin Wolf, 2018/05/29
- [Qemu-block] [PATCH v2 19/20] block: Allow graph changes in bdrv_drain_all_begin/end sections, Kevin Wolf, 2018/05/29
- [Qemu-block] [PATCH v2 18/20] block: ignore_bds_parents parameter for drain functions, Kevin Wolf, 2018/05/29
- [Qemu-block] [PATCH v2 20/20] test-bdrv-drain: Test graph changes in drain_all section, Kevin Wolf, 2018/05/29
- Re: [Qemu-block] [Qemu-devel] [PATCH v2 00/20] Drain fixes and cleanups, part 3, no-reply, 2018/05/29