From 14e9559f4624e704a53d0789124b6f9ea9ebb5ca Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Sat, 8 Apr 2017 11:34:45 +0800 Subject: block: Make bdrv_parent_drained_begin/end public Signed-off-by: Fam Zheng Reviewed-by: Stefan Hajnoczi Acked-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf --- include/block/block.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'include') diff --git a/include/block/block.h b/include/block/block.h index 3e09222f5f..488a07ed67 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -572,6 +572,22 @@ int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo); void bdrv_io_plug(BlockDriverState *bs); void bdrv_io_unplug(BlockDriverState *bs); +/** + * bdrv_parent_drained_begin: + * + * Begin a quiesced section of all users of @bs. This is part of + * bdrv_drained_begin. + */ +void bdrv_parent_drained_begin(BlockDriverState *bs); + +/** + * bdrv_parent_drained_end: + * + * End a quiesced section of all users of @bs. This is part of + * bdrv_drained_end. + */ +void bdrv_parent_drained_end(BlockDriverState *bs); + /** * bdrv_drained_begin: * -- cgit v1.2.3-55-g7522 From ba9e75ceef93000e624ae55faf2e498f96be2ec7 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Mon, 10 Apr 2017 20:06:12 +0800 Subject: coroutine: Extract qemu_aio_coroutine_enter It's a variant of qemu_coroutine_enter with an explicit AioContext parameter. Signed-off-by: Fam Zheng Acked-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf --- include/qemu/coroutine.h | 5 +++++ util/qemu-coroutine.c | 11 ++++++++--- util/trace-events | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index e60beaff81..a4509bd977 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -76,6 +76,11 @@ void qemu_coroutine_enter(Coroutine *coroutine); */ void qemu_coroutine_enter_if_inactive(Coroutine *co); +/** + * Transfer control to a coroutine and associate it with ctx + */ +void qemu_aio_coroutine_enter(AioContext *ctx, Coroutine *co); + /** * Transfer control back to a coroutine's caller * diff --git a/util/qemu-coroutine.c b/util/qemu-coroutine.c index 72412e5649..486af9a622 100644 --- a/util/qemu-coroutine.c +++ b/util/qemu-coroutine.c @@ -102,12 +102,12 @@ static void coroutine_delete(Coroutine *co) qemu_coroutine_delete(co); } -void qemu_coroutine_enter(Coroutine *co) +void qemu_aio_coroutine_enter(AioContext *ctx, Coroutine *co) { Coroutine *self = qemu_coroutine_self(); CoroutineAction ret; - trace_qemu_coroutine_enter(self, co, co->entry_arg); + trace_qemu_aio_coroutine_enter(ctx, self, co, co->entry_arg); if (co->caller) { fprintf(stderr, "Co-routine re-entered recursively\n"); @@ -115,7 +115,7 @@ void qemu_coroutine_enter(Coroutine *co) } co->caller = self; - co->ctx = qemu_get_current_aio_context(); + co->ctx = ctx; /* Store co->ctx before anything that stores co. Matches * barrier in aio_co_wake and qemu_co_mutex_wake. @@ -139,6 +139,11 @@ void qemu_coroutine_enter(Coroutine *co) } } +void qemu_coroutine_enter(Coroutine *co) +{ + qemu_aio_coroutine_enter(qemu_get_current_aio_context(), co); +} + void qemu_coroutine_enter_if_inactive(Coroutine *co) { if (!qemu_coroutine_entered(co)) { diff --git a/util/trace-events b/util/trace-events index ac27d94a97..b44ef4f895 100644 --- a/util/trace-events +++ b/util/trace-events @@ -22,7 +22,7 @@ buffer_move(const char *buf, size_t len, const char *from) "%s: %zd bytes from % buffer_free(const char *buf, size_t len) "%s: capacity %zd" # util/qemu-coroutine.c -qemu_coroutine_enter(void *from, void *to, void *opaque) "from %p to %p opaque %p" +qemu_aio_coroutine_enter(void *ctx, void *from, void *to, void *opaque) "ctx %p from %p to %p opaque %p" qemu_coroutine_yield(void *from, void *to) "from %p to %p" qemu_coroutine_terminate(void *co) "self %p" -- cgit v1.2.3-55-g7522 From 8865852e00557925f60eb6e26d797833422ee86d Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Mon, 10 Apr 2017 20:07:35 +0800 Subject: async: Introduce aio_co_enter They start the coroutine on the specified context. Signed-off-by: Fam Zheng Acked-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf --- include/block/aio.h | 9 +++++++++ util/async.c | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/block/aio.h b/include/block/aio.h index 677b6ffc25..406e32305a 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -510,6 +510,15 @@ void aio_co_schedule(AioContext *ctx, struct Coroutine *co); */ void aio_co_wake(struct Coroutine *co); +/** + * aio_co_enter: + * @ctx: the context to run the coroutine + * @co: the coroutine to run + * + * Enter a coroutine in the specified AioContext. + */ +void aio_co_enter(AioContext *ctx, struct Coroutine *co); + /** * Return the AioContext whose event loop runs in the current thread. * diff --git a/util/async.c b/util/async.c index 663e297e1f..355af73ee7 100644 --- a/util/async.c +++ b/util/async.c @@ -453,6 +453,11 @@ void aio_co_wake(struct Coroutine *co) smp_read_barrier_depends(); ctx = atomic_read(&co->ctx); + aio_co_enter(ctx, co); +} + +void aio_co_enter(AioContext *ctx, struct Coroutine *co) +{ if (ctx != qemu_get_current_aio_context()) { aio_co_schedule(ctx, co); return; @@ -464,7 +469,7 @@ void aio_co_wake(struct Coroutine *co) QSIMPLEQ_INSERT_TAIL(&self->co_queue_wakeup, co, co_queue_next); } else { aio_context_acquire(ctx); - qemu_coroutine_enter(co); + qemu_aio_coroutine_enter(ctx, co); aio_context_release(ctx); } } -- cgit v1.2.3-55-g7522 From 052a75721fb38b9aa0e71ea6420b462c0e356e74 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Mon, 10 Apr 2017 20:09:25 +0800 Subject: block: Introduce bdrv_coroutine_enter Signed-off-by: Fam Zheng Acked-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf --- block.c | 5 +++++ include/block/block.h | 5 +++++ 2 files changed, 10 insertions(+) (limited to 'include') diff --git a/block.c b/block.c index a995a8ec00..086a12df97 100644 --- a/block.c +++ b/block.c @@ -4324,6 +4324,11 @@ AioContext *bdrv_get_aio_context(BlockDriverState *bs) return bs->aio_context; } +void bdrv_coroutine_enter(BlockDriverState *bs, Coroutine *co) +{ + aio_co_enter(bdrv_get_aio_context(bs), co); +} + static void bdrv_do_remove_aio_context_notifier(BdrvAioNotifier *ban) { QLIST_REMOVE(ban, list); diff --git a/include/block/block.h b/include/block/block.h index 488a07ed67..97d4330292 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -557,6 +557,11 @@ bool bdrv_debug_is_suspended(BlockDriverState *bs, const char *tag); */ AioContext *bdrv_get_aio_context(BlockDriverState *bs); +/** + * Transfer control to @co in the aio context of @bs + */ +void bdrv_coroutine_enter(BlockDriverState *bs, Coroutine *co); + /** * bdrv_set_aio_context: * -- cgit v1.2.3-55-g7522