aboutsummaryrefslogtreecommitdiff
path: root/block/io.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2016-10-27 12:48:55 +0200
committerFam Zheng <famz@redhat.com>2016-10-28 21:50:18 +0800
commit88b062c2036cfd05b5111147736a08ba05ea05a9 (patch)
treeb7018cd61ca309939b7197f7ad3ff729f9c0769d /block/io.c
parent6653a73d12fbac8c9b5c22bb21aef22759b28c1c (diff)
block: introduce BDRV_POLL_WHILE
We want the BDS event loop to run exclusively in the iothread that owns the BDS's AioContext. This macro will provide the synchronization between the two event loops; for now it just wraps the common idiom of a while loop around aio_poll. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Message-Id: <1477565348-5458-8-git-send-email-pbonzini@redhat.com> Signed-off-by: Fam Zheng <famz@redhat.com>
Diffstat (limited to 'block/io.c')
-rw-r--r--block/io.c37
1 files changed, 5 insertions, 32 deletions
diff --git a/block/io.c b/block/io.c
index afa53b10bc..6fc0145864 100644
--- a/block/io.c
+++ b/block/io.c
@@ -156,23 +156,12 @@ bool bdrv_requests_pending(BlockDriverState *bs)
return false;
}
-static bool bdrv_drain_poll(BlockDriverState *bs)
-{
- bool waited = false;
-
- while (atomic_read(&bs->in_flight) > 0) {
- aio_poll(bdrv_get_aio_context(bs), true);
- waited = true;
- }
- return waited;
-}
-
static bool bdrv_drain_recurse(BlockDriverState *bs)
{
BdrvChild *child;
bool waited;
- waited = bdrv_drain_poll(bs);
+ waited = BDRV_POLL_WHILE(bs, atomic_read(&bs->in_flight) > 0);
if (bs->drv && bs->drv->bdrv_drain) {
bs->drv->bdrv_drain(bs);
@@ -597,13 +586,9 @@ static int bdrv_prwv_co(BdrvChild *child, int64_t offset,
/* Fast-path if already in coroutine context */
bdrv_rw_co_entry(&rwco);
} else {
- AioContext *aio_context = bdrv_get_aio_context(child->bs);
-
co = qemu_coroutine_create(bdrv_rw_co_entry, &rwco);
qemu_coroutine_enter(co);
- while (rwco.ret == NOT_DONE) {
- aio_poll(aio_context, true);
- }
+ BDRV_POLL_WHILE(child->bs, rwco.ret == NOT_DONE);
}
return rwco.ret;
}
@@ -1845,14 +1830,10 @@ int64_t bdrv_get_block_status_above(BlockDriverState *bs,
/* Fast-path if already in coroutine context */
bdrv_get_block_status_above_co_entry(&data);
} else {
- AioContext *aio_context = bdrv_get_aio_context(bs);
-
co = qemu_coroutine_create(bdrv_get_block_status_above_co_entry,
&data);
qemu_coroutine_enter(co);
- while (!data.done) {
- aio_poll(aio_context, true);
- }
+ BDRV_POLL_WHILE(bs, !data.done);
}
return data.ret;
}
@@ -2379,13 +2360,9 @@ int bdrv_flush(BlockDriverState *bs)
/* Fast-path if already in coroutine context */
bdrv_flush_co_entry(&flush_co);
} else {
- AioContext *aio_context = bdrv_get_aio_context(bs);
-
co = qemu_coroutine_create(bdrv_flush_co_entry, &flush_co);
qemu_coroutine_enter(co);
- while (flush_co.ret == NOT_DONE) {
- aio_poll(aio_context, true);
- }
+ BDRV_POLL_WHILE(bs, flush_co.ret == NOT_DONE);
}
return flush_co.ret;
@@ -2511,13 +2488,9 @@ int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int count)
/* Fast-path if already in coroutine context */
bdrv_pdiscard_co_entry(&rwco);
} else {
- AioContext *aio_context = bdrv_get_aio_context(bs);
-
co = qemu_coroutine_create(bdrv_pdiscard_co_entry, &rwco);
qemu_coroutine_enter(co);
- while (rwco.ret == NOT_DONE) {
- aio_poll(aio_context, true);
- }
+ BDRV_POLL_WHILE(bs, rwco.ret == NOT_DONE);
}
return rwco.ret;