aboutsummaryrefslogtreecommitdiff
path: root/include/block/aio-wait.h
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2018-09-25 16:47:35 +0100
committerPeter Maydell <peter.maydell@linaro.org>2018-09-25 16:47:35 +0100
commitc5e4e49258e9b89cb34c085a419dd9f862935c48 (patch)
treeaa7547e348af2bf5070321c329e2dbe3daf6290a /include/block/aio-wait.h
parent0a736f7ab83df26dbe5421bb3d1f7892def05dee (diff)
parent9c76ff9c16be890e70fce30754b096ff9950d1ee (diff)
Merge remote-tracking branch 'remotes/xanclic/tags/pull-block-2018-09-25' into staging
Block layer patches: - Drain fixes - node-name parameters for block-commit - Refactor block jobs to use transactional callbacks for exiting # gpg: Signature made Tue 25 Sep 2018 16:12:44 BST # gpg: using RSA key F407DB0061D5CF40 # gpg: Good signature from "Max Reitz <mreitz@redhat.com>" # Primary key fingerprint: 91BE B60A 30DB 3E88 57D1 1829 F407 DB00 61D5 CF40 * remotes/xanclic/tags/pull-block-2018-09-25: (42 commits) test-bdrv-drain: Test draining job source child and parent block: Use a single global AioWait test-bdrv-drain: Fix outdated comments test-bdrv-drain: AIO_WAIT_WHILE() in job .commit/.abort job: Avoid deadlocks in job_completed_txn_abort() test-bdrv-drain: Test nested poll in bdrv_drain_poll_top_level() block: Remove aio_poll() in bdrv_drain_poll variants blockjob: Lie better in child_job_drained_poll() block-backend: Decrease in_flight only after callback block-backend: Fix potential double blk_delete() block-backend: Add .drained_poll callback block: Add missing locking in bdrv_co_drain_bh_cb() test-bdrv-drain: Test AIO_WAIT_WHILE() in completion callback job: Use AIO_WAIT_WHILE() in job_finish_sync() test-blockjob: Acquire AioContext around job_cancel_sync() test-bdrv-drain: Drain with block jobs in an I/O thread aio-wait: Increase num_waiters even in home thread blockjob: Wake up BDS when job becomes idle job: Fix missing locking due to mismerge job: Fix nested aio_poll() hanging in job_txn_apply ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'include/block/aio-wait.h')
-rw-r--r--include/block/aio-wait.h28
1 files changed, 14 insertions, 14 deletions
diff --git a/include/block/aio-wait.h b/include/block/aio-wait.h
index c85a62f798..afd0ff7eb8 100644
--- a/include/block/aio-wait.h
+++ b/include/block/aio-wait.h
@@ -30,14 +30,15 @@
/**
* AioWait:
*
- * An object that facilitates synchronous waiting on a condition. The main
- * loop can wait on an operation running in an IOThread as follows:
+ * An object that facilitates synchronous waiting on a condition. A single
+ * global AioWait object (global_aio_wait) is used internally.
+ *
+ * The main loop can wait on an operation running in an IOThread as follows:
*
- * AioWait *wait = ...;
* AioContext *ctx = ...;
* MyWork work = { .done = false };
* schedule_my_work_in_iothread(ctx, &work);
- * AIO_WAIT_WHILE(wait, ctx, !work.done);
+ * AIO_WAIT_WHILE(ctx, !work.done);
*
* The IOThread must call aio_wait_kick() to notify the main loop when
* work.done changes:
@@ -46,7 +47,7 @@
* {
* ...
* work.done = true;
- * aio_wait_kick(wait);
+ * aio_wait_kick();
* }
*/
typedef struct {
@@ -54,9 +55,10 @@ typedef struct {
unsigned num_waiters;
} AioWait;
+extern AioWait global_aio_wait;
+
/**
* AIO_WAIT_WHILE:
- * @wait: the aio wait object
* @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
@@ -72,10 +74,12 @@ typedef struct {
* wait on conditions between two IOThreads since that could lead to deadlock,
* go via the main loop instead.
*/
-#define AIO_WAIT_WHILE(wait, ctx, cond) ({ \
+#define AIO_WAIT_WHILE(ctx, cond) ({ \
bool waited_ = false; \
- AioWait *wait_ = (wait); \
+ AioWait *wait_ = &global_aio_wait; \
AioContext *ctx_ = (ctx); \
+ /* Increment wait_->num_waiters before evaluating cond. */ \
+ atomic_inc(&wait_->num_waiters); \
if (ctx_ && in_aio_context_home_thread(ctx_)) { \
while ((cond)) { \
aio_poll(ctx_, true); \
@@ -84,8 +88,6 @@ typedef struct {
} else { \
assert(qemu_get_current_aio_context() == \
qemu_get_aio_context()); \
- /* Increment wait_->num_waiters before evaluating cond. */ \
- atomic_inc(&wait_->num_waiters); \
while ((cond)) { \
if (ctx_) { \
aio_context_release(ctx_); \
@@ -96,20 +98,18 @@ typedef struct {
} \
waited_ = true; \
} \
- atomic_dec(&wait_->num_waiters); \
} \
+ atomic_dec(&wait_->num_waiters); \
waited_; })
/**
* aio_wait_kick:
- * @wait: the aio wait object that should re-evaluate its condition
- *
* Wake up the main thread if it is waiting on AIO_WAIT_WHILE(). During
* synchronous operations performed in an IOThread, the main thread lets the
* IOThread's event loop run, waiting for the operation to complete. A
* aio_wait_kick() call will wake up the main thread.
*/
-void aio_wait_kick(AioWait *wait);
+void aio_wait_kick(void);
/**
* aio_wait_bh_oneshot: