[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 10/10] coroutine: add qemu_coroutine_run() wrapp
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH 10/10] coroutine: add qemu_coroutine_run() wrapper |
Date: |
Tue, 03 Apr 2012 13:33:28 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120329 Thunderbird/11.0.1 |
Il 03/04/2012 10:38, Lai Jiangshan ha scritto:
> Wrapper for qemu_coroutine_create()+qemu_coroutine_enter()
>
> Signed-off-by: Lai Jiangshan <address@hidden>
> ---
> block.c | 28 +++++++---------------------
> hw/9pfs/virtio-9p.c | 4 +---
> nbd.c | 2 +-
> qemu-coroutine.h | 12 ++++++++++++
> qemu-io.c | 4 +---
> 5 files changed, 22 insertions(+), 28 deletions(-)
>
> diff --git a/block.c b/block.c
> index b88ee90..adf2010 100644
> --- a/block.c
> +++ b/block.c
> @@ -1451,7 +1451,6 @@ static int bdrv_rw_co(BlockDriverState *bs, int64_t
> sector_num, uint8_t *buf,
> .iov_base = (void *)buf,
> .iov_len = nb_sectors * BDRV_SECTOR_SIZE,
> };
> - Coroutine *co;
> RwCo rwco = {
> .bs = bs,
> .sector_num = sector_num,
> @@ -1467,8 +1466,7 @@ static int bdrv_rw_co(BlockDriverState *bs, int64_t
> sector_num, uint8_t *buf,
> /* Fast-path if already in coroutine context */
> bdrv_rw_co_entry(&rwco);
> } else {
> - co = qemu_coroutine_create(bdrv_rw_co_entry);
> - qemu_coroutine_enter(co, &rwco);
> + qemu_coroutine_run(bdrv_rw_co_entry, &rwco);
> while (rwco.ret == NOT_DONE) {
> qemu_aio_wait();
> }
> @@ -2414,7 +2412,6 @@ static void coroutine_fn
> bdrv_is_allocated_co_entry(void *opaque)
> int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int
> nb_sectors,
> int *pnum)
> {
> - Coroutine *co;
> BdrvCoIsAllocatedData data = {
> .bs = bs,
> .sector_num = sector_num,
> @@ -2423,8 +2420,7 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t
> sector_num, int nb_sectors,
> .done = false,
> };
>
> - co = qemu_coroutine_create(bdrv_is_allocated_co_entry);
> - qemu_coroutine_enter(co, &data);
> + qemu_coroutine_run(bdrv_is_allocated_co_entry, &data);
> while (!data.done) {
> qemu_aio_wait();
> }
> @@ -3348,7 +3344,6 @@ static BlockDriverAIOCB
> *bdrv_co_aio_rw_vector(BlockDriverState *bs,
> void *opaque,
> bool is_write)
> {
> - Coroutine *co;
> BlockDriverAIOCBCoroutine *acb;
>
> acb = qemu_aio_get(&bdrv_em_co_aio_pool, bs, cb, opaque);
> @@ -3357,8 +3352,7 @@ static BlockDriverAIOCB
> *bdrv_co_aio_rw_vector(BlockDriverState *bs,
> acb->req.qiov = qiov;
> acb->is_write = is_write;
>
> - co = qemu_coroutine_create(bdrv_co_do_rw);
> - qemu_coroutine_enter(co, acb);
> + qemu_coroutine_run(bdrv_co_do_rw, acb);
>
> return &acb->common;
> }
> @@ -3378,12 +3372,10 @@ BlockDriverAIOCB *bdrv_aio_flush(BlockDriverState *bs,
> {
> trace_bdrv_aio_flush(bs, opaque);
>
> - Coroutine *co;
> BlockDriverAIOCBCoroutine *acb;
>
> acb = qemu_aio_get(&bdrv_em_co_aio_pool, bs, cb, opaque);
> - co = qemu_coroutine_create(bdrv_aio_flush_co_entry);
> - qemu_coroutine_enter(co, acb);
> + qemu_coroutine_run(bdrv_aio_flush_co_entry, acb);
>
> return &acb->common;
> }
> @@ -3402,7 +3394,6 @@ BlockDriverAIOCB *bdrv_aio_discard(BlockDriverState *bs,
> int64_t sector_num, int nb_sectors,
> BlockDriverCompletionFunc *cb, void *opaque)
> {
> - Coroutine *co;
> BlockDriverAIOCBCoroutine *acb;
>
> trace_bdrv_aio_discard(bs, sector_num, nb_sectors, opaque);
> @@ -3410,8 +3401,7 @@ BlockDriverAIOCB *bdrv_aio_discard(BlockDriverState *bs,
> acb = qemu_aio_get(&bdrv_em_co_aio_pool, bs, cb, opaque);
> acb->req.sector = sector_num;
> acb->req.nb_sectors = nb_sectors;
> - co = qemu_coroutine_create(bdrv_aio_discard_co_entry);
> - qemu_coroutine_enter(co, acb);
> + qemu_coroutine_run(bdrv_aio_discard_co_entry, acb);
>
> return &acb->common;
> }
> @@ -3586,7 +3576,6 @@ void bdrv_invalidate_cache_all(void)
>
> int bdrv_flush(BlockDriverState *bs)
> {
> - Coroutine *co;
> RwCo rwco = {
> .bs = bs,
> .ret = NOT_DONE,
> @@ -3596,8 +3585,7 @@ int bdrv_flush(BlockDriverState *bs)
> /* Fast-path if already in coroutine context */
> bdrv_flush_co_entry(&rwco);
> } else {
> - co = qemu_coroutine_create(bdrv_flush_co_entry);
> - qemu_coroutine_enter(co, &rwco);
> + qemu_coroutine_run(bdrv_flush_co_entry, &rwco);
> while (rwco.ret == NOT_DONE) {
> qemu_aio_wait();
> }
> @@ -3645,7 +3633,6 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs,
> int64_t sector_num,
>
> int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
> {
> - Coroutine *co;
> RwCo rwco = {
> .bs = bs,
> .sector_num = sector_num,
> @@ -3657,8 +3644,7 @@ int bdrv_discard(BlockDriverState *bs, int64_t
> sector_num, int nb_sectors)
> /* Fast-path if already in coroutine context */
> bdrv_discard_co_entry(&rwco);
> } else {
> - co = qemu_coroutine_create(bdrv_discard_co_entry);
> - qemu_coroutine_enter(co, &rwco);
> + qemu_coroutine_run(bdrv_discard_co_entry, &rwco);
> while (rwco.ret == NOT_DONE) {
> qemu_aio_wait();
> }
> diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
> index c633fb9..e2f384e 100644
> --- a/hw/9pfs/virtio-9p.c
> +++ b/hw/9pfs/virtio-9p.c
> @@ -3230,7 +3230,6 @@ static inline bool is_read_only_op(V9fsPDU *pdu)
>
> static void submit_pdu(V9fsState *s, V9fsPDU *pdu)
> {
> - Coroutine *co;
> CoroutineEntry *handler;
>
> if (pdu->id >= ARRAY_SIZE(pdu_co_handlers) ||
> @@ -3243,8 +3242,7 @@ static void submit_pdu(V9fsState *s, V9fsPDU *pdu)
> if (is_ro_export(&s->ctx) && !is_read_only_op(pdu)) {
> handler = v9fs_fs_ro;
> }
> - co = qemu_coroutine_create(handler);
> - qemu_coroutine_enter(co, pdu);
> + qemu_coroutine_run(handler, pdu);
> }
>
> void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)
> diff --git a/nbd.c b/nbd.c
> index 567e94e..14ede03 100644
> --- a/nbd.c
> +++ b/nbd.c
> @@ -926,7 +926,7 @@ static void nbd_read(void *opaque)
> if (client->recv_coroutine) {
> qemu_coroutine_enter(client->recv_coroutine, NULL);
> } else {
> - qemu_coroutine_enter(qemu_coroutine_create(nbd_trip), client);
> + qemu_coroutine_run(nbd_trip, client);
> }
> }
>
> diff --git a/qemu-coroutine.h b/qemu-coroutine.h
> index 82a7e5c..572013a 100644
> --- a/qemu-coroutine.h
> +++ b/qemu-coroutine.h
> @@ -74,6 +74,18 @@ Coroutine *qemu_coroutine_create(CoroutineEntry *entry);
> void qemu_coroutine_enter(Coroutine *coroutine, void *opaque);
>
> /**
> + * Create a new coroutine and transfer control to it
> + *
> + * Wrapper for qemu_coroutine_create()+qemu_coroutine_enter()
> + */
> +static inline void qemu_coroutine_run(CoroutineEntry *entry, void *opaque)
> +{
> + Coroutine *co = qemu_coroutine_create(entry);
> +
> + qemu_coroutine_enter(co, opaque);
> +}
> +
> +/**
> * Transfer control back to a coroutine's caller
> *
> * This function does not return until the coroutine is re-entered using
> diff --git a/qemu-io.c b/qemu-io.c
> index 3189530..75e9ac5 100644
> --- a/qemu-io.c
> +++ b/qemu-io.c
> @@ -243,7 +243,6 @@ static void coroutine_fn co_write_zeroes_entry(void
> *opaque)
>
> static int do_co_write_zeroes(int64_t offset, int count, int *total)
> {
> - Coroutine *co;
> CoWriteZeroes data = {
> .offset = offset,
> .count = count,
> @@ -251,8 +250,7 @@ static int do_co_write_zeroes(int64_t offset, int count,
> int *total)
> .done = false,
> };
>
> - co = qemu_coroutine_create(co_write_zeroes_entry);
> - qemu_coroutine_enter(co, &data);
> + qemu_coroutine_run(co_write_zeroes_entry, &data);
> while (!data.done) {
> qemu_aio_wait();
> }
Reviewed-by: Paolo Bonzini <address@hidden>
- [Qemu-devel] [PATCH 05/10] coroutine: add qemu_co_runnable_schedule(), (continued)
- [Qemu-devel] [PATCH 05/10] coroutine: add qemu_co_runnable_schedule(), Lai Jiangshan, 2012/04/03
- [Qemu-devel] [PATCH 02/10] coroutine: rename unlock_bh_queue to co_runnable_queue, Lai Jiangshan, 2012/04/03
- [Qemu-devel] [PATCH 04/10] coroutine: init co_runnable_bh during boot, Lai Jiangshan, 2012/04/03
- [Qemu-devel] [PATCH 03/10] coroutine: rename qemu_co_queue_next_bh() to qemu_co_process_runnable(), Lai Jiangshan, 2012/04/03
- [Qemu-devel] [PATCH 10/10] coroutine: add qemu_coroutine_run() wrapper, Lai Jiangshan, 2012/04/03
- Re: [Qemu-devel] [PATCH 10/10] coroutine: add qemu_coroutine_run() wrapper,
Paolo Bonzini <=
- [Qemu-devel] [PATCH 07/10] coroutine: split qemu-coroutine-lock.c, Lai Jiangshan, 2012/04/03
- [Qemu-devel] [PATCH 08/10] coroutine: process the coroutines woken by child when child yield, Lai Jiangshan, 2012/04/03
- Re: [Qemu-devel] [PATCH 01/10] coroutine: use qemu_coroutine_switch() directly, Paolo Bonzini, 2012/04/03