[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 04/42] block: acquire AioContext in bdrv_drain_all()
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL 04/42] block: acquire AioContext in bdrv_drain_all() |
Date: |
Fri, 6 Jun 2014 18:13:25 +0200 |
Modify bdrv_drain_all() to take into account that BlockDriverState
instances may be running in different AioContexts.
This patch changes the implementation of bdrv_drain_all() while
preserving the semantics. Previously kicking throttled requests and
checking for pending requests were done across all BlockDriverState
instances in sequence. Now we process each BlockDriverState in turn,
making sure to acquire and release its AioContext.
This prevents race conditions between the thread executing
bdrv_drain_all() and the thread running the AioContext.
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
block.c | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/block.c b/block.c
index 7cccb84..87da79f 100644
--- a/block.c
+++ b/block.c
@@ -1885,17 +1885,6 @@ static bool bdrv_requests_pending(BlockDriverState *bs)
return false;
}
-static bool bdrv_requests_pending_all(void)
-{
- BlockDriverState *bs;
- QTAILQ_FOREACH(bs, &bdrv_states, device_list) {
- if (bdrv_requests_pending(bs)) {
- return true;
- }
- }
- return false;
-}
-
/*
* Wait for pending requests to complete across all BlockDriverStates
*
@@ -1915,12 +1904,20 @@ void bdrv_drain_all(void)
BlockDriverState *bs;
while (busy) {
+ busy = false;
+
QTAILQ_FOREACH(bs, &bdrv_states, device_list) {
+ AioContext *aio_context = bdrv_get_aio_context(bs);
+ bool bs_busy;
+
+ aio_context_acquire(aio_context);
bdrv_start_throttled_reqs(bs);
- }
+ bs_busy = bdrv_requests_pending(bs);
+ bs_busy |= aio_poll(aio_context, bs_busy);
+ aio_context_release(aio_context);
- busy = bdrv_requests_pending_all();
- busy |= aio_poll(qemu_get_aio_context(), busy);
+ busy |= bs_busy;
+ }
}
}
--
1.9.3
- [Qemu-devel] [PULL 00/42] Block patches, Stefan Hajnoczi, 2014/06/06
- [Qemu-devel] [PULL 01/42] aio: fix qemu_bh_schedule() bh->ctx race condition, Stefan Hajnoczi, 2014/06/06
- [Qemu-devel] [PULL 03/42] block: acquire AioContext in bdrv_*_all(), Stefan Hajnoczi, 2014/06/06
- [Qemu-devel] [PULL 02/42] block: use BlockDriverState AioContext, Stefan Hajnoczi, 2014/06/06
- [Qemu-devel] [PULL 04/42] block: acquire AioContext in bdrv_drain_all(),
Stefan Hajnoczi <=
- [Qemu-devel] [PULL 06/42] blkdebug: use BlockDriverState's AioContext, Stefan Hajnoczi, 2014/06/06
- [Qemu-devel] [PULL 08/42] curl: implement .bdrv_detach/attach_aio_context(), Stefan Hajnoczi, 2014/06/06
- [Qemu-devel] [PULL 07/42] blkverify: implement .bdrv_detach/attach_aio_context(), Stefan Hajnoczi, 2014/06/06
- [Qemu-devel] [PULL 05/42] block: add bdrv_set_aio_context(), Stefan Hajnoczi, 2014/06/06
- [Qemu-devel] [PULL 09/42] gluster: use BlockDriverState's AioContext, Stefan Hajnoczi, 2014/06/06
- [Qemu-devel] [PULL 11/42] nbd: implement .bdrv_detach/attach_aio_context(), Stefan Hajnoczi, 2014/06/06
- [Qemu-devel] [PULL 10/42] iscsi: implement .bdrv_detach/attach_aio_context(), Stefan Hajnoczi, 2014/06/06
- [Qemu-devel] [PULL 12/42] nfs: implement .bdrv_detach/attach_aio_context(), Stefan Hajnoczi, 2014/06/06
- [Qemu-devel] [PULL 14/42] quorum: implement .bdrv_detach/attach_aio_context(), Stefan Hajnoczi, 2014/06/06
- [Qemu-devel] [PULL 13/42] qed: use BlockDriverState's AioContext, Stefan Hajnoczi, 2014/06/06