[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 29/42] job: Use AIO_WAIT_WHILE() in job_finish_sync()
From: |
Max Reitz |
Subject: |
[Qemu-block] [PULL 29/42] job: Use AIO_WAIT_WHILE() in job_finish_sync() |
Date: |
Tue, 25 Sep 2018 17:15:28 +0200 |
From: Kevin Wolf <address@hidden>
job_finish_sync() needs to release the AioContext lock of the job before
calling aio_poll(). Otherwise, callbacks called by aio_poll() would
possibly take the lock a second time and run into a deadlock with a
nested AIO_WAIT_WHILE() call.
Also, job_drain() without aio_poll() isn't necessarily enough to make
progress on a job, it could depend on bottom halves to be executed.
Combine both open-coded while loops into a single AIO_WAIT_WHILE() call
that solves both of these problems.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Fam Zheng <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
job.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/job.c b/job.c
index 4812962fb5..7ec8c3b969 100644
--- a/job.c
+++ b/job.c
@@ -29,6 +29,7 @@
#include "qemu/job.h"
#include "qemu/id.h"
#include "qemu/main-loop.h"
+#include "block/aio-wait.h"
#include "trace-root.h"
#include "qapi/qapi-events-job.h"
@@ -962,6 +963,7 @@ void job_complete(Job *job, Error **errp)
int job_finish_sync(Job *job, void (*finish)(Job *, Error **errp), Error
**errp)
{
Error *local_err = NULL;
+ AioWait dummy_wait = {};
int ret;
job_ref(job);
@@ -974,14 +976,10 @@ int job_finish_sync(Job *job, void (*finish)(Job *, Error
**errp), Error **errp)
job_unref(job);
return -EBUSY;
}
- /* job_drain calls job_enter, and it should be enough to induce progress
- * until the job completes or moves to the main thread. */
- while (!job->deferred_to_main_loop && !job_is_completed(job)) {
- job_drain(job);
- }
- while (!job_is_completed(job)) {
- aio_poll(qemu_get_aio_context(), true);
- }
+
+ AIO_WAIT_WHILE(&dummy_wait, job->aio_context,
+ (job_drain(job), !job_is_completed(job)));
+
ret = (job_is_cancelled(job) && job->ret == 0) ? -ECANCELED : job->ret;
job_unref(job);
return ret;
--
2.17.1
- [Qemu-block] [PULL 18/42] qemu-iotests: Test commit with top-node/base-node, (continued)
- [Qemu-block] [PULL 18/42] qemu-iotests: Test commit with top-node/base-node, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 20/42] block: Fix use after free error in bdrv_open_inherit(), Max Reitz, 2018/09/25
- [Qemu-block] [PULL 21/42] qemu-iotests: Test snapshot=on with nonexistent TMPDIR, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 22/42] util/async: use qemu_aio_coroutine_enter in co_schedule_bh_cb, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 25/42] blockjob: Wake up BDS when job becomes idle, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 24/42] job: Fix missing locking due to mismerge, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 23/42] job: Fix nested aio_poll() hanging in job_txn_apply, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 26/42] aio-wait: Increase num_waiters even in home thread, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 27/42] test-bdrv-drain: Drain with block jobs in an I/O thread, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 28/42] test-blockjob: Acquire AioContext around job_cancel_sync(), Max Reitz, 2018/09/25
- [Qemu-block] [PULL 29/42] job: Use AIO_WAIT_WHILE() in job_finish_sync(),
Max Reitz <=
- [Qemu-block] [PULL 30/42] test-bdrv-drain: Test AIO_WAIT_WHILE() in completion callback, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 31/42] block: Add missing locking in bdrv_co_drain_bh_cb(), Max Reitz, 2018/09/25
- [Qemu-block] [PULL 32/42] block-backend: Add .drained_poll callback, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 34/42] block-backend: Decrease in_flight only after callback, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 33/42] block-backend: Fix potential double blk_delete(), Max Reitz, 2018/09/25
- [Qemu-block] [PULL 35/42] blockjob: Lie better in child_job_drained_poll(), Max Reitz, 2018/09/25
- [Qemu-block] [PULL 36/42] block: Remove aio_poll() in bdrv_drain_poll variants, Max Reitz, 2018/09/25
- [Qemu-block] [PULL 38/42] job: Avoid deadlocks in job_completed_txn_abort(), Max Reitz, 2018/09/25
- [Qemu-block] [PULL 37/42] test-bdrv-drain: Test nested poll in bdrv_drain_poll_top_level(), Max Reitz, 2018/09/25
- [Qemu-block] [PULL 39/42] test-bdrv-drain: AIO_WAIT_WHILE() in job .commit/.abort, Max Reitz, 2018/09/25