From: Paolo Bonzini <pbonzini@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>, qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PULL 21/31] block: Avoid bs->blk in bdrv_next()
Date: Fri, 20 May 2016 09:54:09 +0200 [thread overview]
Message-ID: <6e34bd03-65d6-ceab-be3b-0e24450ed006@redhat.com> (raw)
In-Reply-To: <1463671329-22655-22-git-send-email-kwolf@redhat.com>
On 19/05/2016 17:21, 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>
> Reviewed-by: Max Reitz <mreitz@redhat.com>
> ---
> block.c | 40 +++++++----------------
> block/block-backend.c | 72 +++++++++++++++++++++++++++++-------------
> 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, 102 insertions(+), 75 deletions(-)
>
> diff --git a/block.c b/block.c
> index fd4cf81..91bf431 100644
> --- a/block.c
> +++ b/block.c
> @@ -2870,25 +2870,6 @@ BlockDriverState *bdrv_next_node(BlockDriverState *bs)
> return QTAILQ_NEXT(bs, node_list);
> }
>
> -/* Iterates over all top-level BlockDriverStates, i.e. BDSs that are owned by
> - * the monitor or attached to a BlockBackend */
> -BlockDriverState *bdrv_next(BlockDriverState *bs)
> -{
> - if (!bs || bs->blk) {
> - bs = blk_next_root_bs(bs);
> - if (bs) {
> - return bs;
> - }
> - }
> -
> - /* Ignore all BDSs that are attached to a BlockBackend here; they have been
> - * handled by the above block already */
> - do {
> - bs = bdrv_next_monitor_owned(bs);
> - } while (bs && bs->blk);
> - return bs;
> -}
> -
> const char *bdrv_get_node_name(const BlockDriverState *bs)
> {
> return bs->node_name;
> @@ -3220,10 +3201,11 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
>
> void bdrv_invalidate_cache_all(Error **errp)
> {
> - BlockDriverState *bs = NULL;
> + BlockDriverState *bs;
> Error *local_err = NULL;
> + BdrvNextIterator *it = NULL;
>
> - while ((bs = bdrv_next(bs)) != NULL) {
> + while ((it = bdrv_next(it, &bs)) != NULL) {
> AioContext *aio_context = bdrv_get_aio_context(bs);
>
> aio_context_acquire(aio_context);
> @@ -3265,10 +3247,11 @@ static int bdrv_inactivate_recurse(BlockDriverState *bs,
> int bdrv_inactivate_all(void)
> {
> BlockDriverState *bs = NULL;
> + BdrvNextIterator *it = NULL;
> int ret = 0;
> int pass;
>
> - while ((bs = bdrv_next(bs)) != NULL) {
> + while ((it = bdrv_next(it, &bs)) != NULL) {
> aio_context_acquire(bdrv_get_aio_context(bs));
> }
>
> @@ -3277,8 +3260,8 @@ int bdrv_inactivate_all(void)
> * the second pass sets the BDRV_O_INACTIVE flag so that no further write
> * is allowed. */
> for (pass = 0; pass < 2; pass++) {
> - bs = NULL;
> - while ((bs = bdrv_next(bs)) != NULL) {
> + it = NULL;
> + while ((it = bdrv_next(it, &bs)) != NULL) {
> ret = bdrv_inactivate_recurse(bs, pass);
> if (ret < 0) {
> goto out;
> @@ -3287,8 +3270,8 @@ int bdrv_inactivate_all(void)
> }
>
> out:
> - bs = NULL;
> - while ((bs = bdrv_next(bs)) != NULL) {
> + it = NULL;
> + while ((it = bdrv_next(it, &bs)) != NULL) {
> aio_context_release(bdrv_get_aio_context(bs));
> }
>
> @@ -3781,10 +3764,11 @@ bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs,
> */
> bool bdrv_is_first_non_filter(BlockDriverState *candidate)
> {
> - BlockDriverState *bs = NULL;
> + BlockDriverState *bs;
> + BdrvNextIterator *it = NULL;
>
> /* walk down the bs forest recursively */
> - while ((bs = bdrv_next(bs)) != NULL) {
> + while ((it = bdrv_next(it, &bs)) != NULL) {
> bool perm;
>
> /* try to recurse in this top level bs */
> diff --git a/block/block-backend.c b/block/block-backend.c
> index 9dcac97..7f2eeb0 100644
> --- a/block/block-backend.c
> +++ b/block/block-backend.c
> @@ -75,6 +75,7 @@ static const AIOCBInfo block_backend_aiocb_info = {
> };
>
> static void drive_info_del(DriveInfo *dinfo);
> +static BlockBackend *bdrv_first_blk(BlockDriverState *bs);
>
> /* All BlockBackends */
> static QTAILQ_HEAD(, BlockBackend) block_backends =
> @@ -286,28 +287,50 @@ 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 {
> + enum {
> + BDRV_NEXT_BACKEND_ROOTS,
> + BDRV_NEXT_MONITOR_OWNED,
> + } phase;
> 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_new(BdrvNextIterator, 1);
Hmm, who frees it? (Especially if the caller exits the loop
prematurely, which means you cannot just free it before returning NULL).
I think it's better to:
- allocate the iterator on the stack and make bdrv_next return a BDS *
- and add a bdrv_first function that does this:
> + *it = (BdrvNextIterator) {
> + .phase = BDRV_NEXT_BACKEND_ROOTS,
> + };
and then returns bdrv_next(it);
- if desirable add a macro that abstracts the calls to bdrv_first and
bdrv_next.
Thanks,
Paolo
next prev parent reply other threads:[~2016-05-20 7:54 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-19 15:21 [Qemu-devel] [PULL 00/31] Block layer patches Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 01/31] block: Make sure throttled BDSes always have a BB Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 02/31] block: Introduce BlockBackendPublic Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 03/31] block: throttle-groups: Use BlockBackend pointers internally Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 04/31] block: Convert throttle_group_get_name() to BlockBackend Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 05/31] block: Move throttling fields from BDS to BB Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 06/31] block: Move actual I/O throttling to BlockBackend Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 07/31] block: Move I/O throttling configuration functions " Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 08/31] block: Introduce BdrvChild.opaque Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 09/31] block: Drain throttling queue with BdrvChild callback Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 10/31] block/io: Quiesce parents between drained_begin/end Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 11/31] block: Decouple throttling from BlockDriverState Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 12/31] block: Remove bdrv_move_feature_fields() Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 13/31] Revert "block: Forbid I/O throttling on nodes with multiple parents for 2.6" Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 14/31] block: Don't check throttled reqs in bdrv_requests_pending() Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 15/31] block: Use BdrvChild callbacks for change_media/resize Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 16/31] block: User BdrvChild callback for device name Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 17/31] blockjob: Don't set iostatus of target Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 18/31] blockjob: Don't touch BDS iostatus Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 19/31] block: Remove bdrv_aio_multiwrite() Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 20/31] block: Add bdrv_has_blk() Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 21/31] block: Avoid bs->blk in bdrv_next() Kevin Wolf
2016-05-20 7:54 ` Paolo Bonzini [this message]
2016-05-20 8:05 ` Kevin Wolf
2016-05-20 8:10 ` Kevin Wolf
2016-05-20 9:39 ` Paolo Bonzini
2016-05-20 10:26 ` Kevin Wolf
2016-05-20 10:46 ` Paolo Bonzini
2016-05-19 15:22 ` [Qemu-devel] [PULL 22/31] block: Don't return throttling info in query-named-block-nodes Kevin Wolf
2016-05-19 15:22 ` [Qemu-devel] [PULL 23/31] block: Remove BlockDriverState.blk Kevin Wolf
2016-05-19 15:22 ` [Qemu-devel] [PULL 24/31] block: Propagate AioContext change to all children Kevin Wolf
2016-05-19 15:22 ` [Qemu-devel] [PULL 25/31] qcow2: fix condition in is_zero_cluster Kevin Wolf
2016-05-19 15:22 ` [Qemu-devel] [PULL 26/31] qcow2: Fix write_zeroes with partially allocated backing file cluster Kevin Wolf
2016-05-19 15:22 ` [Qemu-devel] [PULL 27/31] qemu-iotests: Some more write_zeroes tests Kevin Wolf
2016-05-19 15:22 ` [Qemu-devel] [PULL 28/31] block: clarify error message for qmp-eject Kevin Wolf
2016-05-19 15:22 ` [Qemu-devel] [PULL 29/31] qemu-io: Fix recent UI updates Kevin Wolf
2016-05-19 15:22 ` [Qemu-devel] [PULL 30/31] qemu-iotests: Simplify 109 with unaligned qemu-img compare Kevin Wolf
2016-05-19 15:22 ` [Qemu-devel] [PULL 31/31] qemu-iotests: Fix regression in 136 on aio_read invalid Kevin Wolf
2016-05-19 16:40 ` [Qemu-devel] [PULL 00/31] Block layer patches Peter Maydell
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=6e34bd03-65d6-ceab-be3b-0e24450ed006@redhat.com \
--to=pbonzini@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).