qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: Pavel Hrdina <phrdina@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 03/17] block: add error parameter to bdrv_snapshot_goto() and related functions
Date: Fri, 14 Dec 2012 14:30:59 -0200	[thread overview]
Message-ID: <20121214143059.6bb278c0@doriath.home> (raw)
In-Reply-To: <b190773b701003cc1a1e859a70d6cf4d11edfae8.1355404685.git.phrdina@redhat.com>

On Thu, 13 Dec 2012 16:40:37 +0100
Pavel Hrdina <phrdina@redhat.com> wrote:

> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>

The same comments I made in the previous patch apply here: you're
keeping the error code and converting callers to propagate error
in the same patch (which makes this difficult to review).

> ---
>  block.c                | 27 ++++++++++++++++-----------
>  block.h                |  3 ++-
>  block/qcow2-snapshot.c | 15 ++++++++++++---
>  block/qcow2.h          |  4 +++-
>  block/rbd.c            |  6 +++++-
>  block/sheepdog.c       | 14 +++++++-------
>  block_int.h            |  3 ++-
>  qemu-img.c             |  6 +-----
>  savevm.c               |  2 +-
>  9 files changed, 49 insertions(+), 31 deletions(-)
> 
> diff --git a/block.c b/block.c
> index fea429b..d012b0e 100644
> --- a/block.c
> +++ b/block.c
> @@ -3098,29 +3098,34 @@ int bdrv_snapshot_create(BlockDriverState *bs,
>  }
>  
>  int bdrv_snapshot_goto(BlockDriverState *bs,
> -                       const char *snapshot_id)
> +                       const char *snapshot_id,
> +                       Error **errp)
>  {
>      BlockDriver *drv = bs->drv;
>      int ret, open_ret;
>  
> -    if (!drv)
> -        return -ENOMEDIUM;
> -    if (drv->bdrv_snapshot_goto)
> -        return drv->bdrv_snapshot_goto(bs, snapshot_id);
> -
> -    if (bs->file) {
> +    if (!drv) {
> +        error_setg(errp, "Device '%s' has no medium.",
> +                   bdrv_get_device_name(bs));
> +        ret = -ENOMEDIUM;
> +    } else if (drv->bdrv_snapshot_goto) {
> +        ret = drv->bdrv_snapshot_goto(bs, snapshot_id, errp);
> +    } else if (bs->file) {
>          drv->bdrv_close(bs);
> -        ret = bdrv_snapshot_goto(bs->file, snapshot_id);
> +        ret = bdrv_snapshot_goto(bs->file, snapshot_id, errp);
>          open_ret = drv->bdrv_open(bs, bs->open_flags);
>          if (open_ret < 0) {
>              bdrv_delete(bs->file);
>              bs->drv = NULL;
> -            return open_ret;
> +            error_setg(errp, "Failed to open '%s'.", bdrv_get_device_name(bs));
> +            ret = open_ret;
>          }
> -        return ret;
> +    } else {
> +        error_setg(errp, "Not supported.");
> +        ret = -ENOTSUP;
>      }
>  
> -    return -ENOTSUP;
> +    return ret;
>  }
>  
>  int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
> diff --git a/block.h b/block.h
> index 6abb687..31642c2 100644
> --- a/block.h
> +++ b/block.h
> @@ -324,7 +324,8 @@ int bdrv_snapshot_create(BlockDriverState *bs,
>                           QEMUSnapshotInfo *sn_info,
>                           Error **errp);
>  int bdrv_snapshot_goto(BlockDriverState *bs,
> -                       const char *snapshot_id);
> +                       const char *snapshot_id,
> +                       Error **errp);
>  int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id);
>  int bdrv_snapshot_list(BlockDriverState *bs,
>                         QEMUSnapshotInfo **psn_info);
> diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
> index 3fd8aff..e07f9ac 100644
> --- a/block/qcow2-snapshot.c
> +++ b/block/qcow2-snapshot.c
> @@ -428,7 +428,9 @@ fail:
>  }
>  
>  /* copy the snapshot 'snapshot_name' into the current disk image */
> -int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
> +int qcow2_snapshot_goto(BlockDriverState *bs,
> +                        const char *snapshot_id,
> +                        Error **errp)
>  {
>      BDRVQcowState *s = bs->opaque;
>      QCowSnapshot *sn;
> @@ -440,13 +442,14 @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
>      /* Search the snapshot */
>      snapshot_index = find_snapshot_by_id_or_name(bs, snapshot_id);
>      if (snapshot_index < 0) {
> +        error_setg(errp, "Failed to find snapshot '%s' by id or name.",
> +                   snapshot_id);
>          return -ENOENT;
>      }
>      sn = &s->snapshots[snapshot_index];
>  
>      if (sn->disk_size != bs->total_sectors * BDRV_SECTOR_SIZE) {
> -        error_report("qcow2: Loading snapshots with different disk "
> -            "size is not implemented");
> +        error_setg(errp, "Not supported.");
>          ret = -ENOTSUP;
>          goto fail;
>      }
> @@ -458,6 +461,7 @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
>       */
>      ret = qcow2_grow_l1_table(bs, sn->l1_size, true);
>      if (ret < 0) {
> +        error_setg(errp, "Failed to grow L1 table.");
>          goto fail;
>      }
>  
> @@ -476,18 +480,21 @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
>  
>      ret = bdrv_pread(bs->file, sn->l1_table_offset, sn_l1_table, sn_l1_bytes);
>      if (ret < 0) {
> +        error_setg(errp, "Failed to load data into L1 table.");
>          goto fail;
>      }
>  
>      ret = qcow2_update_snapshot_refcount(bs, sn->l1_table_offset,
>                                           sn->l1_size, 1);
>      if (ret < 0) {
> +        error_setg(errp, "Failed to update snapshot refcount.");
>          goto fail;
>      }
>  
>      ret = bdrv_pwrite_sync(bs->file, s->l1_table_offset, sn_l1_table,
>                             cur_l1_bytes);
>      if (ret < 0) {
> +        error_setg(errp, "Failed to save L1 table.");
>          goto fail;
>      }
>  
> @@ -513,6 +520,7 @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
>      }
>  
>      if (ret < 0) {
> +        error_setg(errp, "Failed to update snapshot refcount.");
>          goto fail;
>      }
>  
> @@ -525,6 +533,7 @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
>       */
>      ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 0);
>      if (ret < 0) {
> +        error_setg(errp, "Failed to update snapshot refcount.");
>          goto fail;
>      }
>  
> diff --git a/block/qcow2.h b/block/qcow2.h
> index 854bd12..6babb56 100644
> --- a/block/qcow2.h
> +++ b/block/qcow2.h
> @@ -311,7 +311,9 @@ int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors);
>  int qcow2_snapshot_create(BlockDriverState *bs,
>                            QEMUSnapshotInfo *sn_info,
>                            Error **errp);
> -int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id);
> +int qcow2_snapshot_goto(BlockDriverState *bs,
> +                        const char *snapshot_id,
> +                        Error **errp);
>  int qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id);
>  int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab);
>  int qcow2_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name);
> diff --git a/block/rbd.c b/block/rbd.c
> index cb5acf8..3e789c6 100644
> --- a/block/rbd.c
> +++ b/block/rbd.c
> @@ -858,12 +858,16 @@ static int qemu_rbd_snap_remove(BlockDriverState *bs,
>  }
>  
>  static int qemu_rbd_snap_rollback(BlockDriverState *bs,
> -                                  const char *snapshot_name)
> +                                  const char *snapshot_name,
> +                                  Error **errp)
>  {
>      BDRVRBDState *s = bs->opaque;
>      int r;
>  
>      r = rbd_snap_rollback(s->image, snapshot_name);
> +    if (r < 0) {
> +        error_setg(errp, "Failed to rollback snapshot.");
> +    }
>      return r;
>  }
>  
> diff --git a/block/sheepdog.c b/block/sheepdog.c
> index 094634a..34ef75c 100644
> --- a/block/sheepdog.c
> +++ b/block/sheepdog.c
> @@ -1808,7 +1808,9 @@ cleanup:
>      return ret;
>  }
>  
> -static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
> +static int sd_snapshot_goto(BlockDriverState *bs,
> +                            const char *snapshot_id,
> +                            Error **errp)
>  {
>      BDRVSheepdogState *s = bs->opaque;
>      BDRVSheepdogState *old_s;
> @@ -1833,14 +1835,14 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
>  
>      ret = find_vdi_name(s, vdi, snapid, tag, &vid, 1);
>      if (ret) {
> -        error_report("Failed to find_vdi_name");
> +        error_setg(errp, "Failed to find VDI snapshot '%s'.", vdi);
>          goto out;
>      }
>  
>      fd = connect_to_sdog(s->addr, s->port);
>      if (fd < 0) {
> -        error_report("failed to connect");
>          ret = fd;
> +        error_setg(errp, "Failed to connect to sdog.");
>          goto out;
>      }
>  
> @@ -1851,13 +1853,14 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
>      closesocket(fd);
>  
>      if (ret) {
> +        error_setg(errp, "Failed to open '%s'.", vdi);
>          goto out;
>      }
>  
>      memcpy(&s->inode, buf, sizeof(s->inode));
>  
>      if (!s->inode.vm_state_size) {
> -        error_report("Invalid snapshot");
> +        error_setg(errp, "Invalid snapshot '%s'.", snapshot_id);
>          ret = -ENOENT;
>          goto out;
>      }
> @@ -1873,9 +1876,6 @@ out:
>      memcpy(s, old_s, sizeof(BDRVSheepdogState));
>      g_free(buf);
>      g_free(old_s);
> -
> -    error_report("failed to open. recover old bdrv_sd_state.");
> -
>      return ret;
>  }
>  
> diff --git a/block_int.h b/block_int.h
> index 976ea1f..016782c 100644
> --- a/block_int.h
> +++ b/block_int.h
> @@ -150,7 +150,8 @@ struct BlockDriver {
>                                  QEMUSnapshotInfo *sn_info,
>                                  Error **errp);
>      int (*bdrv_snapshot_goto)(BlockDriverState *bs,
> -                              const char *snapshot_id);
> +                              const char *snapshot_id,
> +                              Error **errp);
>      int (*bdrv_snapshot_delete)(BlockDriverState *bs, const char *snapshot_id);
>      int (*bdrv_snapshot_list)(BlockDriverState *bs,
>                                QEMUSnapshotInfo **psn_info);
> diff --git a/qemu-img.c b/qemu-img.c
> index 93e4022..91671a8 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -1564,11 +1564,7 @@ static int img_snapshot(int argc, char **argv)
>          break;
>  
>      case SNAPSHOT_APPLY:
> -        ret = bdrv_snapshot_goto(bs, snapshot_name);
> -        if (ret) {
> -            error_report("Could not apply snapshot '%s': %d (%s)",
> -                snapshot_name, ret, strerror(-ret));
> -        }
> +        ret = bdrv_snapshot_goto(bs, snapshot_name, &err);
>          break;
>  
>      case SNAPSHOT_DELETE:
> diff --git a/savevm.c b/savevm.c
> index ef2f305..29e41fc 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -2301,7 +2301,7 @@ int load_vmstate(const char *name)
>      bs = NULL;
>      while ((bs = bdrv_next(bs))) {
>          if (bdrv_can_snapshot(bs)) {
> -            ret = bdrv_snapshot_goto(bs, name);
> +            ret = bdrv_snapshot_goto(bs, name, NULL);
>              if (ret < 0) {
>                  error_report("Error %d while activating snapshot '%s' on '%s'",
>                               ret, name, bdrv_get_device_name(bs));

  reply	other threads:[~2012-12-14 16:31 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-13 15:40 [Qemu-devel] [PATCH v2 00/17] qapi: Convert savevm, loadvm, delvm and info snapshots Pavel Hrdina
2012-12-13 15:40 ` [Qemu-devel] [PATCH v2 01/17] error: introduce handle_error Pavel Hrdina
2012-12-14  0:52   ` Eric Blake
2012-12-14 16:00   ` Luiz Capitulino
2012-12-13 15:40 ` [Qemu-devel] [PATCH v2 02/17] block: add error parameter to bdrv_snapshot_create() and related functions Pavel Hrdina
2012-12-14 16:29   ` Luiz Capitulino
2012-12-14 16:31   ` Luiz Capitulino
2012-12-13 15:40 ` [Qemu-devel] [PATCH v2 03/17] block: add error parameter to bdrv_snapshot_goto() " Pavel Hrdina
2012-12-14 16:30   ` Luiz Capitulino [this message]
2012-12-13 15:40 ` [Qemu-devel] [PATCH v2 04/17] block: add error parameter to bdrv_snapshot_delete() " Pavel Hrdina
2012-12-13 15:40 ` [Qemu-devel] [PATCH v2 05/17] block: add error parameter to bdrv_snapshot_list() " Pavel Hrdina
2012-12-13 15:40 ` [Qemu-devel] [PATCH v2 06/17] block: add error parameter to bdrv_snapshot_find() Pavel Hrdina
2012-12-13 15:40 ` [Qemu-devel] [PATCH v2 07/17] block: add error parameter to del_existing_snapshots() Pavel Hrdina
2012-12-14 16:42   ` Luiz Capitulino
2012-12-13 15:40 ` [Qemu-devel] [PATCH v2 08/17] savevm: add error parameter to qemu_savevm_state_begin() Pavel Hrdina
2012-12-14 16:45   ` Luiz Capitulino
2012-12-13 15:40 ` [Qemu-devel] [PATCH v2 09/17] savevm: add error parameter to qemu_savevm_state_iterate() Pavel Hrdina
2012-12-13 15:40 ` [Qemu-devel] [PATCH v2 10/17] savevm: add error parameter to qemu_savevm_state_complete() Pavel Hrdina
2012-12-13 15:40 ` [Qemu-devel] [PATCH v2 11/17] savevm: add error parameter to qemu_savevm_state() Pavel Hrdina
2012-12-13 15:40 ` [Qemu-devel] [PATCH v2 12/17] savevm: add error parameter to qemu_loadvm_state() Pavel Hrdina
2012-12-14 16:52   ` Luiz Capitulino
2012-12-13 15:40 ` [Qemu-devel] [PATCH v2 13/17] qapi: Convert savevm Pavel Hrdina
2012-12-14 16:57   ` Luiz Capitulino
2012-12-14 17:09     ` Eric Blake
2012-12-13 15:40 ` [Qemu-devel] [PATCH v2 14/17] qapi: Convert loadvm Pavel Hrdina
2012-12-14 18:30   ` Eric Blake
2012-12-13 15:40 ` [Qemu-devel] [PATCH v2 15/17] qapi: Convert delvm Pavel Hrdina
2012-12-14 18:39   ` Eric Blake
2012-12-13 15:40 ` [Qemu-devel] [PATCH v2 16/17] qapi: Convert info snapshots Pavel Hrdina
2012-12-14 17:18   ` Luiz Capitulino
2012-12-13 15:40 ` [Qemu-devel] [PATCH v2 17/17] vm-snapshot-save: add force parameter Pavel Hrdina
2012-12-14 17:24 ` [Qemu-devel] [PATCH v2 00/17] qapi: Convert savevm, loadvm, delvm and info snapshots Luiz Capitulino
2012-12-20  2:27 ` Wenchao Xia

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=20121214143059.6bb278c0@doriath.home \
    --to=lcapitulino@redhat.com \
    --cc=phrdina@redhat.com \
    --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).