All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
To: Pavel Hrdina <phrdina@redhat.com>
Cc: kwolf@redhat.com, lcapitulino@redhat.com, qemu-devel@nongnu.org,
	armbru@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 02/12] block: update error reporting for bdrv_snapshot_delete() and related functions
Date: Thu, 25 Apr 2013 11:19:41 +0800	[thread overview]
Message-ID: <5178A0CD.7060400@linux.vnet.ibm.com> (raw)
In-Reply-To: <8b6851c3a59103d7dd55ae400be90e6d7431ab0b.1366817130.git.phrdina@redhat.com>

  bdrv_snapshot_delete() do not return error number now, and I checked
original caller code, they used it only for error reporting, so it is
safe to change.

Reviewed-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>


> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>   block.c                   | 21 +++++++++++++--------
>   block/qcow2-snapshot.c    | 19 +++++++++++++------
>   block/qcow2.h             |  4 +++-
>   block/rbd.c               | 10 +++++++---
>   block/sheepdog.c          |  6 ++++--
>   include/block/block.h     |  4 +++-
>   include/block/block_int.h |  4 +++-
>   qemu-img.c                |  8 +++-----
>   savevm.c                  | 32 ++++++++++++++++----------------
>   9 files changed, 65 insertions(+), 43 deletions(-)
> 
> diff --git a/block.c b/block.c
> index aa9a533..3f7ee38 100644
> --- a/block.c
> +++ b/block.c
> @@ -3438,16 +3438,21 @@ int bdrv_snapshot_goto(BlockDriverState *bs,
>       return -ENOTSUP;
>   }
> 
> -int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
> +void bdrv_snapshot_delete(BlockDriverState *bs,
> +                          const char *snapshot_id,
> +                          Error **errp)
>   {
>       BlockDriver *drv = bs->drv;
> -    if (!drv)
> -        return -ENOMEDIUM;
> -    if (drv->bdrv_snapshot_delete)
> -        return drv->bdrv_snapshot_delete(bs, snapshot_id);
> -    if (bs->file)
> -        return bdrv_snapshot_delete(bs->file, snapshot_id);
> -    return -ENOTSUP;
> +
> +    if (!drv) {
> +        error_setg(errp, "Device has no medium");
> +    } else if (drv->bdrv_snapshot_delete) {
> +        drv->bdrv_snapshot_delete(bs, snapshot_id, errp);
> +    } else if (bs->file) {
> +        bdrv_snapshot_delete(bs->file, snapshot_id, errp);
> +    } else {
> +        error_setg(errp, "Snapshots are not supported");
> +    }
>   }
> 
>   int bdrv_snapshot_list(BlockDriverState *bs,
> diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
> index 992a5c8..fd0e231 100644
> --- a/block/qcow2-snapshot.c
> +++ b/block/qcow2-snapshot.c
> @@ -530,7 +530,9 @@ fail:
>       return ret;
>   }
> 
> -int qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
> +void qcow2_snapshot_delete(BlockDriverState *bs,
> +                           const char *snapshot_id,
> +                           Error **errp)
>   {
>       BDRVQcowState *s = bs->opaque;
>       QCowSnapshot sn;
> @@ -539,7 +541,9 @@ int qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
>       /* Search the snapshot */
>       snapshot_index = find_snapshot_by_id_or_name(bs, snapshot_id);
>       if (snapshot_index < 0) {
> -        return -ENOENT;
> +        error_setg(errp, "Failed to find snapshot '%s' by id or name",
> +                   snapshot_id);
> +        return;
>       }
>       sn = s->snapshots[snapshot_index];
> 
> @@ -550,7 +554,9 @@ int qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
>       s->nb_snapshots--;
>       ret = qcow2_write_snapshots(bs);
>       if (ret < 0) {
> -        return ret;
> +        error_setg_errno(errp, -ret, "Failed to remove snapshot '%s' from "
> +                         "snapshot list", sn.name);
> +        return;
>       }
> 
>       /*
> @@ -567,14 +573,16 @@ int qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
>       ret = qcow2_update_snapshot_refcount(bs, sn.l1_table_offset,
>                                            sn.l1_size, -1);
>       if (ret < 0) {
> -        return ret;
> +        error_setg_errno(errp, -ret, "Failed to update refcounts");
> +        return;
>       }
>       qcow2_free_clusters(bs, sn.l1_table_offset, sn.l1_size * sizeof(uint64_t));
> 
>       /* must update the copied flag on the current cluster offsets */
>       ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 0);
>       if (ret < 0) {
> -        return ret;
> +        error_setg_errno(errp, -ret, "Failed to update cluster flags");
> +        return;
>       }
> 
>   #ifdef DEBUG_ALLOC
> @@ -583,7 +591,6 @@ int qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
>           qcow2_check_refcounts(bs, &result, 0);
>       }
>   #endif
> -    return 0;
>   }
> 
>   int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
> diff --git a/block/qcow2.h b/block/qcow2.h
> index 9421843..dbd332d 100644
> --- a/block/qcow2.h
> +++ b/block/qcow2.h
> @@ -384,7 +384,9 @@ int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors);
>   /* qcow2-snapshot.c functions */
>   int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info);
>   int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id);
> -int qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id);
> +void qcow2_snapshot_delete(BlockDriverState *bs,
> +                           const char *snapshot_id,
> +                           Error **errp);
>   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 1826411..1e54c55 100644
> --- a/block/rbd.c
> +++ b/block/rbd.c
> @@ -899,14 +899,18 @@ static int qemu_rbd_snap_create(BlockDriverState *bs,
>       return 0;
>   }
> 
> -static int qemu_rbd_snap_remove(BlockDriverState *bs,
> -                                const char *snapshot_name)
> +static void qemu_rbd_snap_remove(BlockDriverState *bs,
> +                                 const char *snapshot_name,
> +                                 Error **errp)
>   {
>       BDRVRBDState *s = bs->opaque;
>       int r;
> 
>       r = rbd_snap_remove(s->image, snapshot_name);
> -    return r;
> +    if (r < 0) {
> +        error_setg_errno(errp, -r, "Failed to remove snapshot '%s'",
> +                         snapshot_name);
> +    }
>   }
> 
>   static int qemu_rbd_snap_rollback(BlockDriverState *bs,
> diff --git a/block/sheepdog.c b/block/sheepdog.c
> index 20b5d06..7e0610f 100644
> --- a/block/sheepdog.c
> +++ b/block/sheepdog.c
> @@ -1937,10 +1937,12 @@ out:
>       return ret;
>   }
> 
> -static int sd_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
> +static void sd_snapshot_delete(BlockDriverState *bs,
> +                               const char *snapshot_id,
> +                               Error **errp)
>   {
>       /* FIXME: Delete specified snapshot id.  */
> -    return 0;
> +    error_setg(errp, "Deleting snapshot is not supported");
>   }
> 
>   static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
> diff --git a/include/block/block.h b/include/block/block.h
> index 1251c5c..abb636d 100644
> --- a/include/block/block.h
> +++ b/include/block/block.h
> @@ -337,7 +337,9 @@ int bdrv_snapshot_create(BlockDriverState *bs,
>                            QEMUSnapshotInfo *sn_info);
>   int bdrv_snapshot_goto(BlockDriverState *bs,
>                          const char *snapshot_id);
> -int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id);
> +void bdrv_snapshot_delete(BlockDriverState *bs,
> +                          const char *snapshot_id,
> +                          Error **errp);
>   int bdrv_snapshot_list(BlockDriverState *bs,
>                          QEMUSnapshotInfo **psn_info);
>   int bdrv_snapshot_load_tmp(BlockDriverState *bs,
> diff --git a/include/block/block_int.h b/include/block/block_int.h
> index 6078dd3..c3f67c3 100644
> --- a/include/block/block_int.h
> +++ b/include/block/block_int.h
> @@ -156,7 +156,9 @@ struct BlockDriver {
>                                   QEMUSnapshotInfo *sn_info);
>       int (*bdrv_snapshot_goto)(BlockDriverState *bs,
>                                 const char *snapshot_id);
> -    int (*bdrv_snapshot_delete)(BlockDriverState *bs, const char *snapshot_id);
> +    void (*bdrv_snapshot_delete)(BlockDriverState *bs,
> +                                 const char *snapshot_id,
> +                                 Error **errp);
>       int (*bdrv_snapshot_list)(BlockDriverState *bs,
>                                 QEMUSnapshotInfo **psn_info);
>       int (*bdrv_snapshot_load_tmp)(BlockDriverState *bs,
> diff --git a/qemu-img.c b/qemu-img.c
> index ab83fbe..9cf3467 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -1932,6 +1932,7 @@ static int img_snapshot(int argc, char **argv)
>   {
>       BlockDriverState *bs;
>       QEMUSnapshotInfo sn;
> +    Error *local_err = NULL;
>       char *filename, *snapshot_name = NULL;
>       int c, ret = 0, bdrv_oflags;
>       int action = 0;
> @@ -2029,11 +2030,8 @@ static int img_snapshot(int argc, char **argv)
>           break;
> 
>       case SNAPSHOT_DELETE:
> -        ret = bdrv_snapshot_delete(bs, snapshot_name);
> -        if (ret) {
> -            error_report("Could not delete snapshot '%s': %d (%s)",
> -                snapshot_name, ret, strerror(-ret));
> -        }
> +        bdrv_snapshot_delete(bs, snapshot_name, &local_err);
> +        ret = qemu_img_handle_error(local_err);
>           break;
>       }
> 
> diff --git a/savevm.c b/savevm.c
> index 31dcce9..ba97c41 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -2291,18 +2291,20 @@ static int del_existing_snapshots(Monitor *mon, const char *name)
>   {
>       BlockDriverState *bs;
>       QEMUSnapshotInfo sn1, *snapshot = &sn1;
> -    int ret;
> +    Error *local_err = NULL;
> 
>       bs = NULL;
>       while ((bs = bdrv_next(bs))) {
>           if (bdrv_can_snapshot(bs) &&
>               bdrv_snapshot_find(bs, snapshot, name) >= 0)
>           {
> -            ret = bdrv_snapshot_delete(bs, name);
> -            if (ret < 0) {
> -                monitor_printf(mon,
> -                               "Error while deleting snapshot on '%s'\n",
> -                               bdrv_get_device_name(bs));
> +            bdrv_snapshot_delete(bs, name, &local_err);
> +            if (error_is_set(&local_err)) {
> +                qerror_report(ERROR_CLASS_GENERIC_ERROR, "Failed to delete "
> +                              "old snapshot on device '%s': %s",
> +                              bdrv_get_device_name(bs),
> +                              error_get_pretty(local_err));
> +                error_free(local_err);
>                   return -1;
>               }
>           }
> @@ -2516,7 +2518,7 @@ int load_vmstate(const char *name)
>   void do_delvm(Monitor *mon, const QDict *qdict)
>   {
>       BlockDriverState *bs, *bs1;
> -    int ret;
> +    Error *local_err = NULL;
>       const char *name = qdict_get_str(qdict, "name");
> 
>       bs = bdrv_snapshots();
> @@ -2528,15 +2530,13 @@ void do_delvm(Monitor *mon, const QDict *qdict)
>       bs1 = NULL;
>       while ((bs1 = bdrv_next(bs1))) {
>           if (bdrv_can_snapshot(bs1)) {
> -            ret = bdrv_snapshot_delete(bs1, name);
> -            if (ret < 0) {
> -                if (ret == -ENOTSUP)
> -                    monitor_printf(mon,
> -                                   "Snapshots not supported on device '%s'\n",
> -                                   bdrv_get_device_name(bs1));
> -                else
> -                    monitor_printf(mon, "Error %d while deleting snapshot on "
> -                                   "'%s'\n", ret, bdrv_get_device_name(bs1));
> +            bdrv_snapshot_delete(bs1, name, &local_err);
> +            if (error_is_set(&local_err)) {
> +                qerror_report(ERROR_CLASS_GENERIC_ERROR, "Failed to delete "
> +                              "old snapshot on device '%s': %s",
> +                              bdrv_get_device_name(bs),
> +                              error_get_pretty(local_err));
> +                error_free(local_err);
>               }
>           }
>       }
> 


-- 
Best Regards

Wenchao Xia

  parent reply	other threads:[~2013-04-25  3:21 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-24 15:31 [Qemu-devel] [PATCH v2 00/12] covert savevm, loadvm and delvm into qapi Pavel Hrdina
2013-04-24 15:31 ` [Qemu-devel] [PATCH v2 01/12] qemu-img: introduce qemu_img_handle_error() Pavel Hrdina
2013-04-24 16:44   ` Eric Blake
2013-04-25  2:53     ` Wenchao Xia
2013-04-25  3:00       ` Eric Blake
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 02/12] block: update error reporting for bdrv_snapshot_delete() and related functions Pavel Hrdina
2013-04-24 20:05   ` Eric Blake
2013-04-25  3:19   ` Wenchao Xia [this message]
2013-04-25 13:42   ` Stefan Hajnoczi
2013-05-03  9:53   ` Kevin Wolf
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 03/12] savevm: update bdrv_snapshot_find() to find snapshot by id or name and add error parameter Pavel Hrdina
2013-04-24 21:26   ` Eric Blake
2013-04-25  6:46     ` Pavel Hrdina
2013-04-25  8:18       ` Pavel Hrdina
2013-04-25  6:31   ` Wenchao Xia
2013-04-25  6:52     ` Pavel Hrdina
2013-04-25 12:16     ` Eric Blake
2013-04-26  2:37       ` Wenchao Xia
2013-05-03 10:24   ` Kevin Wolf
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 04/12] qapi: Convert delvm Pavel Hrdina
2013-04-24 22:54   ` Eric Blake
2013-04-25  6:58     ` Wenchao Xia
2013-04-25 12:21       ` Eric Blake
2013-04-26  2:39         ` Wenchao Xia
2013-05-03 10:50   ` Kevin Wolf
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 05/12] block: update error reporting for bdrv_snapshot_goto() and related functions Pavel Hrdina
2013-04-25 17:06   ` Eric Blake
2013-05-03 11:03   ` Kevin Wolf
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 06/12] block: update error reporting for bdrv_snapshot_list() " Pavel Hrdina
2013-04-25 18:55   ` Eric Blake
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 07/12] savevm: update error reporting for qemu_loadvm_state() Pavel Hrdina
2013-05-03 11:17   ` Kevin Wolf
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 08/12] qapi: Convert loadvm Pavel Hrdina
2013-05-03 11:31   ` Kevin Wolf
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 09/12] block: update error reporting for bdrv_snapshot_create() and related functions Pavel Hrdina
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 10/12] savevm: update error reporting of qemu_savevm_state() " Pavel Hrdina
2013-05-03 12:40   ` Kevin Wolf
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 11/12] qapi: Convert savevm Pavel Hrdina
2013-05-03 12:52   ` Kevin Wolf
2013-04-24 15:32 ` [Qemu-devel] [PATCH v2 12/12] savevm: remove backward compatibility from bdrv_snapshot_find() Pavel Hrdina
2013-05-03 12:55   ` Kevin Wolf
2013-04-24 16:15 ` [Qemu-devel] [PATCH v2 00/12] covert savevm, loadvm and delvm into qapi Eric Blake
2013-04-24 17:12   ` Luiz Capitulino
2013-04-25 13:34 ` Stefan Hajnoczi

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=5178A0CD.7060400@linux.vnet.ibm.com \
    --to=xiawenc@linux.vnet.ibm.com \
    --cc=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=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 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.