All of lore.kernel.org
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>, qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
	"Daniel P . Berrangé" <berrange@redhat.com>,
	qemu-block@nongnu.org, "Juan Quintela" <quintela@redhat.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"Pavel Dovgalyuk" <pavel.dovgaluk@ispras.ru>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Subject: Re: [PATCH 1/3] block: push error reporting into bdrv_all_*_snapshot functions
Date: Mon, 12 Oct 2020 12:07:03 +0200	[thread overview]
Message-ID: <8f2e2439-4100-a64d-b52e-c03d439cb743@redhat.com> (raw)
In-Reply-To: <20201008174803.2696619-2-philmd@redhat.com>

On 08.10.20 19:48, Philippe Mathieu-Daudé wrote:
> From: Daniel P. Berrangé <berrange@redhat.com>
> 
> The bdrv_all_*_snapshot functions return a BlockDriverState pointer
> for the invalid backend, which the callers then use to report an
> error message. In some cases multiple callers are reporting the
> same error message, but with slightly different text. In the future
> there will be more error scenarios for some of these methods, which
> will benefit from fine grained error message reporting. So it is
> helpful to push error reporting down a level.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  include/block/snapshot.h       | 14 +++----
>  block/monitor/block-hmp-cmds.c |  7 ++--
>  block/snapshot.c               | 77 +++++++++++++++++-----------------
>  migration/savevm.c             | 37 +++++-----------
>  monitor/hmp-cmds.c             |  7 +---
>  replay/replay-debugging.c      |  4 +-
>  tests/qemu-iotests/267.out     | 10 ++---
>  7 files changed, 67 insertions(+), 89 deletions(-)

Looks good overall to me, but for some reason this patch pulls in the
@ok and @ret variables from the top scope of all concerned functions
into the inner scopes of the BDS loops, and drops their initialization.
 That’s wrong, because we only call the respective snapshotting
functions on some BDSs, so the return value stays uninitialized for all
other BDSs:

> diff --git a/block/snapshot.c b/block/snapshot.c
> index a2bf3a54eb..50e35bb9fa 100644
> --- a/block/snapshot.c
> +++ b/block/snapshot.c
> @@ -462,14 +462,14 @@ static bool bdrv_all_snapshots_includes_bs(BlockDriverState *bs)
>   * These functions will properly handle dataplane (take aio_context_acquire
>   * when appropriate for appropriate block drivers) */
>  
> -bool bdrv_all_can_snapshot(BlockDriverState **first_bad_bs)
> +bool bdrv_all_can_snapshot(Error **errp)
>  {
> -    bool ok = true;
>      BlockDriverState *bs;
>      BdrvNextIterator it;
>  
>      for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
>          AioContext *ctx = bdrv_get_aio_context(bs);
> +        bool ok;

So I think @ok must be initialized.

>  
>          aio_context_acquire(ctx);
>          if (bdrv_all_snapshots_includes_bs(bs)) {
> @@ -477,26 +477,25 @@ bool bdrv_all_can_snapshot(BlockDriverState **first_bad_bs)
>          }
>          aio_context_release(ctx);
>          if (!ok) {
> +            error_setg(errp, "Device '%s' is writable but does not support "
> +                       "snapshots", bdrv_get_device_or_node_name(bs));
>              bdrv_next_cleanup(&it);
> -            goto fail;
> +            return false;
>          }
>      }
>  
> -fail:
> -    *first_bad_bs = bs;
> -    return ok;
> +    return true;
>  }
>  
> -int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bad_bs,
> -                             Error **errp)
> +int bdrv_all_delete_snapshot(const char *name, Error **errp)
>  {
> -    int ret = 0;
>      BlockDriverState *bs;
>      BdrvNextIterator it;
>      QEMUSnapshotInfo sn1, *snapshot = &sn1;
>  
>      for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
>          AioContext *ctx = bdrv_get_aio_context(bs);
> +        int ret;

Same here, @ret must be initialized.

>  
>          aio_context_acquire(ctx);
>          if (bdrv_all_snapshots_includes_bs(bs) &&
> @@ -507,26 +506,25 @@ int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bad_bs,
>          }
>          aio_context_release(ctx);
>          if (ret < 0) {
> +            error_prepend(errp, "Could not delete snapshot '%s' on '%s': ",
> +                          name, bdrv_get_device_or_node_name(bs));
>              bdrv_next_cleanup(&it);
> -            goto fail;
> +            return -1;
>          }
>      }
>  
> -fail:
> -    *first_bad_bs = bs;
> -    return ret;
> +    return 0;
>  }
>  
>  
> -int bdrv_all_goto_snapshot(const char *name, BlockDriverState **first_bad_bs,
> -                           Error **errp)
> +int bdrv_all_goto_snapshot(const char *name, Error **errp)
>  {
> -    int ret = 0;
>      BlockDriverState *bs;
>      BdrvNextIterator it;
>  
>      for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
>          AioContext *ctx = bdrv_get_aio_context(bs);
> +        int ret;

And again.

>  
>          aio_context_acquire(ctx);
>          if (bdrv_all_snapshots_includes_bs(bs)) {
> @@ -534,75 +532,75 @@ int bdrv_all_goto_snapshot(const char *name, BlockDriverState **first_bad_bs,
>          }
>          aio_context_release(ctx);
>          if (ret < 0) {
> +            error_prepend(errp, "Could not load snapshot '%s' on '%s': ",
> +                          name, bdrv_get_device_or_node_name(bs));
>              bdrv_next_cleanup(&it);
> -            goto fail;
> +            return -1;
>          }
>      }
>  
> -fail:
> -    *first_bad_bs = bs;
> -    return ret;
> +    return 0;
>  }
>  
> -int bdrv_all_find_snapshot(const char *name, BlockDriverState **first_bad_bs)
> +int bdrv_all_find_snapshot(const char *name, Error **errp)
>  {
>      QEMUSnapshotInfo sn;
> -    int err = 0;
>      BlockDriverState *bs;
>      BdrvNextIterator it;
>  
>      for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
>          AioContext *ctx = bdrv_get_aio_context(bs);
> +        int ret;

Again.

>  
>          aio_context_acquire(ctx);
>          if (bdrv_all_snapshots_includes_bs(bs)) {
> -            err = bdrv_snapshot_find(bs, &sn, name);
> +            ret = bdrv_snapshot_find(bs, &sn, name);
>          }
>          aio_context_release(ctx);
> -        if (err < 0) {
> +        if (ret < 0) {
> +            error_setg(errp, "Could not find snapshot '%s' on '%s'",
> +                       name, bdrv_get_device_or_node_name(bs));
>              bdrv_next_cleanup(&it);
> -            goto fail;
> +            return -1;
>          }
>      }
>  
> -fail:
> -    *first_bad_bs = bs;
> -    return err;
> +    return 0;
>  }
>  
>  int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn,
>                               BlockDriverState *vm_state_bs,
>                               uint64_t vm_state_size,
> -                             BlockDriverState **first_bad_bs)
> +                             Error **errp)
>  {
> -    int err = 0;
>      BlockDriverState *bs;
>      BdrvNextIterator it;
>  
>      for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
>          AioContext *ctx = bdrv_get_aio_context(bs);
> +        int ret;

And one final time.

Max

>          aio_context_acquire(ctx);
>          if (bs == vm_state_bs) {
>              sn->vm_state_size = vm_state_size;
> -            err = bdrv_snapshot_create(bs, sn);
> +            ret = bdrv_snapshot_create(bs, sn);
>          } else if (bdrv_all_snapshots_includes_bs(bs)) {
>              sn->vm_state_size = 0;
> -            err = bdrv_snapshot_create(bs, sn);
> +            ret = bdrv_snapshot_create(bs, sn);
>          }
>          aio_context_release(ctx);
> -        if (err < 0) {
> +        if (ret < 0) {
> +            error_setg(errp, "Could not create snapshot '%s' on '%s'",
> +                       sn->name, bdrv_get_device_or_node_name(bs));
>              bdrv_next_cleanup(&it);
> -            goto fail;
> +            return -1;
>          }
>      }



  reply	other threads:[~2020-10-12 10:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-08 17:48 [PATCH 0/3] migration: Make save/load_snapshot() return boolean Philippe Mathieu-Daudé
2020-10-08 17:48 ` [PATCH 1/3] block: push error reporting into bdrv_all_*_snapshot functions Philippe Mathieu-Daudé
2020-10-12 10:07   ` Max Reitz [this message]
2020-10-12 10:16     ` Philippe Mathieu-Daudé
2020-10-12 11:09       ` Max Reitz
2020-10-12 11:56         ` Philippe Mathieu-Daudé
2020-10-08 17:48 ` [PATCH 2/3] migration: Make save_snapshot() return bool, not 0/-1 Philippe Mathieu-Daudé
2020-10-09 12:09   ` Pavel Dovgalyuk
2020-10-09 13:57   ` Philippe Mathieu-Daudé
2020-10-08 17:48 ` [PATCH 3/3] migration: stop returning errno from load_snapshot() Philippe Mathieu-Daudé
2020-10-09 12:10   ` Pavel Dovgalyuk

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=8f2e2439-4100-a64d-b52e-c03d439cb743@redhat.com \
    --to=mreitz@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pavel.dovgaluk@ispras.ru \
    --cc=pbonzini@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.