[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC v2 09/15] Add a synchronous wrapper bdrv_sync_rwco
From: |
Charlie Shepherd |
Subject: |
[Qemu-devel] [RFC v2 09/15] Add a synchronous wrapper bdrv_sync_rwco |
Date: |
Fri, 9 Aug 2013 19:43:59 +0200 |
A number of functions in block.c pass an RwCo struct to a coroutine entry point
in order to
synchronise an asynchronous function. This patch factors this pattern out into
a function.
Signed-off-by: Charlie Shepherd <address@hidden>
---
block.c | 37 +++++++++++++++++--------------------
1 file changed, 17 insertions(+), 20 deletions(-)
diff --git a/block.c b/block.c
index 51a6649..25edb44 100644
--- a/block.c
+++ b/block.c
@@ -2171,6 +2171,17 @@ typedef struct RwCo {
BdrvRequestFlags flags;
} RwCo;
+static int bdrv_sync_rwco(void coroutine_fn (*co_fn)(void *), RwCo *rwco)
+{
+ Coroutine *co;
+ co = qemu_coroutine_create(co_fn);
+ qemu_coroutine_enter(co, rwco);
+ while (rwco->ret == NOT_DONE) {
+ qemu_aio_wait();
+ }
+ return rwco->ret;
+}
+
static void coroutine_fn bdrv_rw_co_entry(void *opaque)
{
RwCo *rwco = opaque;
@@ -2219,14 +2230,10 @@ static int bdrv_rwv_co(BlockDriverState *bs, int64_t
sector_num,
if (qemu_in_coroutine()) {
/* Fast-path if already in coroutine context */
bdrv_rw_co_entry(&rwco);
+ return rwco.ret;
} else {
- co = qemu_coroutine_create(bdrv_rw_co_entry);
- qemu_coroutine_enter(co, &rwco);
- while (rwco.ret == NOT_DONE) {
- qemu_aio_wait();
- }
+ return bdrv_sync_rwco(bdrv_rw_co_entry, &rwco);
}
- return rwco.ret;
}
/*
@@ -4144,15 +4151,10 @@ int bdrv_flush(BlockDriverState *bs)
if (qemu_in_coroutine()) {
/* Fast-path if already in coroutine context */
bdrv_flush_co_entry(&rwco);
+ return rwco.ret;
} else {
- co = qemu_coroutine_create(bdrv_flush_co_entry);
- qemu_coroutine_enter(co, &rwco);
- while (rwco.ret == NOT_DONE) {
- qemu_aio_wait();
- }
+ return bdrv_sync_rwco(bdrv_flush_co_entry, &rwco);
}
-
- return rwco.ret;
}
static void coroutine_fn bdrv_discard_co_entry(void *opaque)
@@ -4216,15 +4218,10 @@ int bdrv_discard(BlockDriverState *bs, int64_t
sector_num, int nb_sectors)
if (qemu_in_coroutine()) {
/* Fast-path if already in coroutine context */
bdrv_discard_co_entry(&rwco);
+ return rwco.ret;
} else {
- co = qemu_coroutine_create(bdrv_discard_co_entry);
- qemu_coroutine_enter(co, &rwco);
- while (rwco.ret == NOT_DONE) {
- qemu_aio_wait();
- }
+ return bdrv_sync_rwco(bdrv_discard_co_entry, &rwco);
}
-
- return rwco.ret;
}
/**************************************************************/
--
1.8.3.2
- Re: [Qemu-devel] [RFC v2 05/15] Make qcow2_open synchronous, (continued)
- [Qemu-devel] [RFC v2 04/15] Convert .bdrv_open and .bdrv_file_open to coroutine_fn, Charlie Shepherd, 2013/08/09
- [Qemu-devel] [RFC v2 07/15] Call bdrv->open via a synchronous wrapper in block/snapshot.c, Charlie Shepherd, 2013/08/09
- [Qemu-devel] [RFC v2 06/15] Explicitly mark BlockDriver functions .bdrv_write and .bdrv_read as coroutine functions, Charlie Shepherd, 2013/08/09
- [Qemu-devel] [RFC v2 08/15] Convert bdrv_create and associated functions to be coroutine_fn, Charlie Shepherd, 2013/08/09
- [Qemu-devel] [RFC v2 09/15] Add a synchronous wrapper bdrv_sync_rwco,
Charlie Shepherd <=
- [Qemu-devel] [RFC v2 11/15] Make bdrv_discard coroutine only and add bdrv_sync_discard, Charlie Shepherd, 2013/08/09
- [Qemu-devel] [RFC v2 12/15] Make bdrv_flush coroutine only and add bdrv_sync_flush, Charlie Shepherd, 2013/08/09
- [Qemu-devel] [RFC v2 10/15] Convert bdrv_read, bdrv_write and associated functions to coroutine functions, Charlie Shepherd, 2013/08/09
- [Qemu-devel] [RFC v2 13/15] Introduce a run_handler function in qemu-img.c, Charlie Shepherd, 2013/08/09
- [Qemu-devel] [RFC v2 15/15] Add coroutine_fn annotations to nbd_co_* functions., Charlie Shepherd, 2013/08/09
- [Qemu-devel] [RFC v2 14/15] Add coroutine annotations for qemu_co_rwlock_rdlock and qemu_co_rwlock_wrlock, Charlie Shepherd, 2013/08/09
- Re: [Qemu-devel] [RFC v2 01/15] Add an explanation of when a function should be marked coroutine_fn, Stefan Hajnoczi, 2013/08/14
- Re: [Qemu-devel] [RFC v2 01/15] Add an explanation of when a function should be marked coroutine_fn, Stefan Hajnoczi, 2013/08/29