qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>, qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 7/9] block: Avoid bs->blk in bdrv_next()
Date: Tue, 29 Mar 2016 20:50:28 +0200	[thread overview]
Message-ID: <56FACE74.7000708@redhat.com> (raw)
In-Reply-To: <1458675397-24956-8-git-send-email-kwolf@redhat.com>


[-- Attachment #1.1: Type: text/plain, Size: 3239 bytes --]

On 22.03.2016 20:36, Kevin Wolf wrote:
> We need to introduce a separate BdrvNextIterator struct that can keep
> more state than just the current BDS in order to avoid using the bs->blk
> pointer.
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  block.c                        | 34 +++++++++-----------------------
>  block/block-backend.c          | 44 +++++++++++++++++++++++++++---------------
>  block/io.c                     | 13 +++++++------
>  block/snapshot.c               | 30 ++++++++++++++++------------
>  blockdev.c                     |  3 ++-
>  include/block/block.h          |  3 ++-
>  include/sysemu/block-backend.h |  1 -
>  migration/block.c              |  4 +++-
>  monitor.c                      |  6 ++++--
>  qmp.c                          |  5 ++++-
>  10 files changed, 77 insertions(+), 66 deletions(-)

The connection with patch 5 is a bit funny. I see why you have two
patches for this issue (because the first one introduces
bdrv_has_blk()), but I think it would be better to clear up their
relationship in the first patch's commit message.

[...]

> diff --git a/block/block-backend.c b/block/block-backend.c
> index fdd1727..b71b822 100644
> --- a/block/block-backend.c
> +++ b/block/block-backend.c
> @@ -325,28 +325,40 @@ BlockBackend *blk_next(BlockBackend *blk)
>                 : QTAILQ_FIRST(&monitor_block_backends);
>  }
>  
> -/*
> - * Iterates over all BlockDriverStates which are attached to a BlockBackend.
> - * This function is for use by bdrv_next().
> - *
> - * @bs must be NULL or a BDS that is attached to a BB.
> - */
> -BlockDriverState *blk_next_root_bs(BlockDriverState *bs)
> -{
> +struct BdrvNextIterator {
> +    int phase;

A verbose enum would have been nicer.

>      BlockBackend *blk;
> +    BlockDriverState *bs;
> +};
>  
> -    if (bs) {
> -        assert(bs->blk);
> -        blk = bs->blk;
> -    } else {
> -        blk = NULL;
> +/* Iterates over all top-level BlockDriverStates, i.e. BDSs that are owned by
> + * the monitor or attached to a BlockBackend */
> +BdrvNextIterator *bdrv_next(BdrvNextIterator *it, BlockDriverState **bs)
> +{
> +    if (!it) {
> +        it = g_new0(BdrvNextIterator, 1);
> +    }
> +
> +    if (it->phase == 0) {
> +        do {
> +            it->blk = blk_all_next(it->blk);
> +            *bs = it->blk ? blk_bs(it->blk) : NULL;
> +        } while (it->blk && *bs == NULL);

This will be interesting with multiple BBs per BDS. I guess we can do
something like only take the BDS if the BB is the first one in its
parent list.

> +
> +        if (*bs) {
> +            return it;

:-)

> +        }
> +        it->phase = 1;
>      }
>  
> +    /* Ignore all BDSs that are attached to a BlockBackend here; they have been
> +     * handled by the above block already */
>      do {
> -        blk = blk_all_next(blk);
> -    } while (blk && !blk->root);
> +        it->bs = bdrv_next_monitor_owned(it->bs);
> +        *bs = it->bs;
> +    } while (*bs && bdrv_has_blk(*bs));
>  
> -    return blk ? blk->root->bs : NULL;
> +    return *bs ? it : NULL;
>  }
>  
>  /*

Reviewed-by: Max Reitz <mreitz@redhat.com>

[...]


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

  reply	other threads:[~2016-03-29 18:50 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-22 19:36 [Qemu-devel] [PATCH 0/9] block: Remove BlockDriverState.blk Kevin Wolf
2016-03-22 19:36 ` [Qemu-devel] [PATCH 1/9] block: Use BdrvChild callbacks for change_media/resize Kevin Wolf
2016-03-29 17:36   ` Max Reitz
2016-03-22 19:36 ` [Qemu-devel] [PATCH 2/9] block: User BdrvChild callback for device name Kevin Wolf
2016-03-29 17:43   ` Max Reitz
2016-03-22 19:36 ` [Qemu-devel] [PATCH 3/9] block jobs: Use BdrvChild callbacks for iostatus operations Kevin Wolf
2016-03-29 18:15   ` Max Reitz
2016-03-22 19:36 ` [Qemu-devel] [PATCH 4/9] block: Remove bdrv_aio_multiwrite() Kevin Wolf
2016-03-29 18:22   ` Max Reitz
2016-03-22 19:36 ` [Qemu-devel] [PATCH 5/9] block: Avoid BDS.blk in bdrv_next() Kevin Wolf
2016-03-29 18:26   ` Max Reitz
2016-03-22 19:36 ` [Qemu-devel] [PATCH 6/9] block: Remove bdrv_move_feature_fields() Kevin Wolf
2016-03-29 18:28   ` Max Reitz
2016-03-22 19:36 ` [Qemu-devel] [PATCH 7/9] block: Avoid bs->blk in bdrv_next() Kevin Wolf
2016-03-29 18:50   ` Max Reitz [this message]
2016-03-22 19:36 ` [Qemu-devel] [PATCH 8/9] block: Don't return throttling info in query-named-block-nodes Kevin Wolf
2016-03-29 18:53   ` Max Reitz
2016-03-22 19:36 ` [Qemu-devel] [PATCH 9/9] block: Remove BlockDriverState.blk Kevin Wolf
2016-03-29 18:59   ` Max Reitz
2016-03-22 21:34 ` [Qemu-devel] [PATCH 0/9] " 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=56FACE74.7000708@redhat.com \
    --to=mreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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).