From: Stefan Hajnoczi <stefanha@gmail.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-block@nongnu.org, pbonzini@redhat.com,
qemu-devel@nongnu.org, stefanha@redhat.com, mreitz@redhat.com
Subject: Re: [Qemu-devel] [Qemu-block] [PATCH 25/29] qed: Implement .bdrv_co_readv/writev
Date: Wed, 31 May 2017 13:49:08 +0100 [thread overview]
Message-ID: <20170531124908.GZ16733@stefanha-x1.localdomain> (raw)
In-Reply-To: <1495830130-30611-26-git-send-email-kwolf@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 6574 bytes --]
On Fri, May 26, 2017 at 10:22:06PM +0200, Kevin Wolf wrote:
> Most of the qed code is now synchronous and matches the coroutine model.
> One notable exception is the serialisation between requests which can
> still schedule a callback. Before we can replace this with coroutine
> locks, let's convert the driver's external interfaces to the coroutine
> versions.
>
> We need to be careful to handle both requests that call the completion
> callback directly from the calling coroutine (i.e. fully synchronous
> code) and requests that involve some callback, so that we need to yield
> and wait for the completion callback coming from outside the coroutine.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
> block/qed.c | 94 +++++++++++++++++++++++++------------------------------------
> 1 file changed, 39 insertions(+), 55 deletions(-)
>
> diff --git a/block/qed.c b/block/qed.c
> index 6a83df2..29c3dc5 100644
> --- a/block/qed.c
> +++ b/block/qed.c
> @@ -1326,16 +1326,31 @@ static void qed_aio_next_io(QEDAIOCB *acb)
> }
> }
>
> -static BlockAIOCB *qed_aio_setup(BlockDriverState *bs,
> - int64_t sector_num,
> - QEMUIOVector *qiov, int nb_sectors,
> - BlockCompletionFunc *cb,
> - void *opaque, int flags)
> +typedef struct QEDRequestCo {
> + Coroutine *co;
> + bool done;
> + int ret;
> +} QEDRequestCo;
> +
> +static void coroutine_fn qed_co_request_cb(void *opaque, int ret)
> +{
> + QEDRequestCo *co = opaque;
> +
> + co->done = true;
> + co->ret = ret;
> + qemu_coroutine_enter_if_inactive(co->co);
> +}
> +
> +static int qed_co_request(BlockDriverState *bs, int64_t sector_num,
> + QEMUIOVector *qiov, int nb_sectors, int flags)
Missing coroutine_fn.
> {
> - QEDAIOCB *acb = qemu_aio_get(&qed_aiocb_info, bs, cb, opaque);
> + QEDRequestCo co = {
> + .co = qemu_coroutine_self(),
> + .done = false,
> + };
> + QEDAIOCB *acb = qemu_aio_get(&qed_aiocb_info, bs, qed_co_request_cb, &co);
>
> - trace_qed_aio_setup(bs->opaque, acb, sector_num, nb_sectors,
> - opaque, flags);
> + trace_qed_aio_setup(bs->opaque, acb, sector_num, nb_sectors, &co, flags);
>
> acb->flags = flags;
> acb->qiov = qiov;
> @@ -1348,43 +1363,24 @@ static BlockAIOCB *qed_aio_setup(BlockDriverState *bs,
>
> /* Start request */
> qed_aio_start_io(acb);
> - return &acb->common;
> -}
>
> -static BlockAIOCB *bdrv_qed_aio_readv(BlockDriverState *bs,
> - int64_t sector_num,
> - QEMUIOVector *qiov, int nb_sectors,
> - BlockCompletionFunc *cb,
> - void *opaque)
> -{
> - return qed_aio_setup(bs, sector_num, qiov, nb_sectors, cb, opaque, 0);
> + if (!co.done) {
> + qemu_coroutine_yield();
> + }
> +
> + return co.ret;
> }
>
> -static BlockAIOCB *bdrv_qed_aio_writev(BlockDriverState *bs,
> - int64_t sector_num,
> - QEMUIOVector *qiov, int nb_sectors,
> - BlockCompletionFunc *cb,
> - void *opaque)
> +static int bdrv_qed_co_readv(BlockDriverState *bs, int64_t sector_num,
> + int nb_sectors, QEMUIOVector *qiov)
Missing coroutine_fn. More below.
> {
> - return qed_aio_setup(bs, sector_num, qiov, nb_sectors, cb,
> - opaque, QED_AIOCB_WRITE);
> + return qed_co_request(bs, sector_num, qiov, nb_sectors, 0);
> }
>
> -typedef struct {
> - Coroutine *co;
> - int ret;
> - bool done;
> -} QEDWriteZeroesCB;
> -
> -static void coroutine_fn qed_co_pwrite_zeroes_cb(void *opaque, int ret)
> +static int bdrv_qed_co_writev(BlockDriverState *bs, int64_t sector_num,
> + int nb_sectors, QEMUIOVector *qiov)
> {
> - QEDWriteZeroesCB *cb = opaque;
> -
> - cb->done = true;
> - cb->ret = ret;
> - if (cb->co) {
> - aio_co_wake(cb->co);
> - }
> + return qed_co_request(bs, sector_num, qiov, nb_sectors, QED_AIOCB_WRITE);
> }
>
> static int coroutine_fn bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs,
> @@ -1392,9 +1388,7 @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs,
> int count,
> BdrvRequestFlags flags)
> {
> - BlockAIOCB *blockacb;
> BDRVQEDState *s = bs->opaque;
> - QEDWriteZeroesCB cb = { .done = false };
> QEMUIOVector qiov;
> struct iovec iov;
>
> @@ -1411,19 +1405,9 @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs,
> iov.iov_len = count;
>
> qemu_iovec_init_external(&qiov, &iov, 1);
> - blockacb = qed_aio_setup(bs, offset >> BDRV_SECTOR_BITS, &qiov,
> - count >> BDRV_SECTOR_BITS,
> - qed_co_pwrite_zeroes_cb, &cb,
> - QED_AIOCB_WRITE | QED_AIOCB_ZERO);
> - if (!blockacb) {
> - return -EIO;
> - }
> - if (!cb.done) {
> - cb.co = qemu_coroutine_self();
> - qemu_coroutine_yield();
> - }
> - assert(cb.done);
> - return cb.ret;
> + return qed_co_request(bs, offset >> BDRV_SECTOR_BITS, &qiov,
> + count >> BDRV_SECTOR_BITS,
> + QED_AIOCB_WRITE | QED_AIOCB_ZERO);
> }
>
> static int bdrv_qed_truncate(BlockDriverState *bs, int64_t offset, Error **errp)
> @@ -1619,8 +1603,8 @@ static BlockDriver bdrv_qed = {
> .bdrv_create = bdrv_qed_create,
> .bdrv_has_zero_init = bdrv_has_zero_init_1,
> .bdrv_co_get_block_status = bdrv_qed_co_get_block_status,
> - .bdrv_aio_readv = bdrv_qed_aio_readv,
> - .bdrv_aio_writev = bdrv_qed_aio_writev,
> + .bdrv_co_readv = bdrv_qed_co_readv,
> + .bdrv_co_writev = bdrv_qed_co_writev,
> .bdrv_co_pwrite_zeroes = bdrv_qed_co_pwrite_zeroes,
> .bdrv_truncate = bdrv_qed_truncate,
> .bdrv_getlength = bdrv_qed_getlength,
> --
> 1.8.3.1
>
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
next prev parent reply other threads:[~2017-05-31 12:49 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-26 20:21 [Qemu-devel] [PATCH 00/29] qed: Convert to coroutines Kevin Wolf
2017-05-26 20:21 ` [Qemu-devel] [PATCH 01/29] qed: Use bottom half to resume waiting requests Kevin Wolf
2017-05-26 20:40 ` Eric Blake
2017-05-31 12:16 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 02/29] qed: Make qed_read_table() synchronous Kevin Wolf
2017-05-26 21:04 ` Eric Blake
2017-05-31 12:16 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 03/29] qed: Remove callback from qed_read_table() Kevin Wolf
2017-05-26 21:10 ` Eric Blake
2017-05-31 12:18 ` Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 04/29] qed: Remove callback from qed_read_l2_table() Kevin Wolf
2017-05-26 21:16 ` Eric Blake
2017-05-31 12:20 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 05/29] qed: Remove callback from qed_find_cluster() Kevin Wolf
2017-05-26 21:31 ` Eric Blake
2017-05-31 12:24 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 06/29] qed: Make qed_read_backing_file() synchronous Kevin Wolf
2017-05-26 21:33 ` Eric Blake
2017-05-31 12:25 ` Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 07/29] qed: Make qed_copy_from_backing_file() synchronous Kevin Wolf
2017-05-26 21:41 ` Eric Blake
2017-05-31 12:26 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 08/29] qed: Remove callback from qed_copy_from_backing_file() Kevin Wolf
2017-05-26 21:51 ` Eric Blake
2017-05-31 12:29 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 09/29] qed: Make qed_write_header() synchronous Kevin Wolf
2017-05-26 21:53 ` Eric Blake
2017-05-31 12:30 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 10/29] qed: Remove callback from qed_write_header() Kevin Wolf
2017-05-31 12:32 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-06-01 15:59 ` Kevin Wolf
2017-06-01 16:04 ` Paolo Bonzini
2017-06-02 16:03 ` Stefan Hajnoczi
2017-06-02 16:04 ` Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 11/29] qed: Make qed_write_table() synchronous Kevin Wolf
2017-05-31 12:35 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 12/29] qed: Remove GenericCB Kevin Wolf
2017-05-31 12:35 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 13/29] qed: Remove callback from qed_write_table() Kevin Wolf
2017-05-31 12:36 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 14/29] qed: Make qed_aio_read_data() synchronous Kevin Wolf
2017-05-31 12:36 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 15/29] qed: Make qed_aio_write_main() synchronous Kevin Wolf
2017-05-31 12:38 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 16/29] qed: Inline qed_commit_l2_update() Kevin Wolf
2017-05-31 12:38 ` Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 17/29] qed: Add return value to qed_aio_write_l1_update() Kevin Wolf
2017-05-31 12:40 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:21 ` [Qemu-devel] [PATCH 18/29] qed: Add return value to qed_aio_write_l2_update() Kevin Wolf
2017-05-31 12:40 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:22 ` [Qemu-devel] [PATCH 19/29] qed: Add return value to qed_aio_write_main() Kevin Wolf
2017-05-31 12:41 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:22 ` [Qemu-devel] [PATCH 20/29] qed: Add return value to qed_aio_write_cow() Kevin Wolf
2017-05-31 12:42 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:22 ` [Qemu-devel] [PATCH 21/29] qed: Add return value to qed_aio_write_inplace/alloc() Kevin Wolf
2017-05-31 12:43 ` Stefan Hajnoczi
2017-05-26 20:22 ` [Qemu-devel] [PATCH 22/29] qed: Add return value to qed_aio_read/write_data() Kevin Wolf
2017-05-31 12:45 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:22 ` [Qemu-devel] [PATCH 23/29] qed: Remove ret argument from qed_aio_next_io() Kevin Wolf
2017-05-31 12:45 ` Stefan Hajnoczi
2017-05-26 20:22 ` [Qemu-devel] [PATCH 24/29] qed: Remove recursion in qed_aio_next_io() Kevin Wolf
2017-05-31 12:46 ` Stefan Hajnoczi
2017-05-26 20:22 ` [Qemu-devel] [PATCH 25/29] qed: Implement .bdrv_co_readv/writev Kevin Wolf
2017-05-31 12:49 ` Stefan Hajnoczi [this message]
2017-05-26 20:22 ` [Qemu-devel] [PATCH 26/29] qed: Use CoQueue for serialising allocations Kevin Wolf
2017-05-31 12:53 ` Stefan Hajnoczi
2017-05-26 20:22 ` [Qemu-devel] [PATCH 27/29] qed: Simplify request handling Kevin Wolf
2017-05-31 12:54 ` Stefan Hajnoczi
2017-05-26 20:22 ` [Qemu-devel] [PATCH 28/29] qed: Use a coroutine for need_check_timer Kevin Wolf
2017-05-31 12:56 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-05-26 20:22 ` [Qemu-devel] [PATCH 29/29] block: Remove bdrv_aio_readv/writev_flush() Kevin Wolf
2017-05-31 12:57 ` Stefan Hajnoczi
2017-05-29 11:22 ` [Qemu-devel] [Qemu-block] [PATCH 00/29] qed: Convert to coroutines Paolo Bonzini
2017-06-01 16:28 ` Kevin Wolf
2017-06-01 16:40 ` Paolo Bonzini
2017-06-01 17:08 ` Kevin Wolf
2017-06-02 8:06 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170531124908.GZ16733@stefanha-x1.localdomain \
--to=stefanha@gmail.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).