qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Pavel Hrdina <phrdina@redhat.com>
Cc: xiawenc@linux.vnet.ibm.com, lcapitulino@redhat.com,
	qemu-devel@nongnu.org, armbru@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 03/12] savevm: update bdrv_snapshot_find() to find snapshot by id or name and add error parameter
Date: Fri, 3 May 2013 12:24:18 +0200	[thread overview]
Message-ID: <20130503102418.GD3171@dhcp-200-207.str.redhat.com> (raw)
In-Reply-To: <bf08850cd61d5fb6b2ce3a0fee57b37336f36ac8.1366817130.git.phrdina@redhat.com>

Am 24.04.2013 um 17:32 hat Pavel Hrdina geschrieben:
> Finding snapshot by a name which could also be an id isn't best way
> how to do it. There will be rewrite of savevm, loadvm and delvm to
> improve the behavior of these commands. The savevm and loadvm will
> have their own patch series.
> 
> Now bdrv_snapshot_find takes more parameters. The name parameter will
> be matched only against the name of the snapshot and the same applies
> to id parameter.
> 
> There is one exception. If you set the last parameter, the name parameter
> will be matched against the name or the id of a snapshot. This exception
> is only for backward compatibility for other commands and it will be
> dropped after all commands will be rewritten.
> 
> We only need to know if that snapshot exists or not. We don't care
> about any error message. If snapshot exists it returns TRUE otherwise
> it returns FALSE.
> 
> There is also new Error parameter which will containt error messeage if
> something goes wrong.
> 
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>  savevm.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++------------------
>  1 file changed, 67 insertions(+), 26 deletions(-)
> 
> diff --git a/savevm.c b/savevm.c
> index ba97c41..1622c55 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -2262,26 +2262,66 @@ out:
>      return ret;
>  }
>  
> -static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
> -                              const char *name)
> +static bool bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
> +                               const char *name, const char *id, Error **errp,
> +                               bool old_match)
>  {
>      QEMUSnapshotInfo *sn_tab, *sn;
> -    int nb_sns, i, ret;
> +    int nb_sns, i;
> +    bool found = false;
> +
> +    assert(name || id);
>  
> -    ret = -ENOENT;
>      nb_sns = bdrv_snapshot_list(bs, &sn_tab);
> -    if (nb_sns < 0)
> -        return ret;
> -    for(i = 0; i < nb_sns; i++) {
> +    if (nb_sns < 0) {
> +        error_setg_errno(errp, -nb_sns, "Failed to get a snapshot list");
> +        return found;
> +    }
> +
> +    if (nb_sns == 0) {
> +        error_setg(errp, "Device has no snapshots");

This is not an error case, please remove the error_setg(). If the caller
indeed needs to have a snapshot, it can generate an error by himself. We
cannot assume here that every caller needs it.

> +        return found;
> +    }
> +
> +    for (i = 0; i < nb_sns; i++) {
>          sn = &sn_tab[i];
> -        if (!strcmp(sn->id_str, name) || !strcmp(sn->name, name)) {
> -            *sn_info = *sn;
> -            ret = 0;
> -            break;
> +        if (name && id) {
> +            if (!strcmp(sn->id_str, id) && !strcmp(sn->name, name)) {
> +                *sn_info = *sn;
> +                found = true;
> +                break;
> +            }
> +        } else if (name) {
> +            /* for compatibility for old bdrv_snapshot_find call
> +             * will be removed */
> +            if (old_match) {
> +                if (!strcmp(sn->id_str, name) || !strcmp(sn->name, name)) {
> +                    *sn_info = *sn;
> +                    found = true;
> +                    break;
> +                }
> +            } else {
> +                if (!strcmp(sn->name, name)) {
> +                    *sn_info = *sn;
> +                    found = true;
> +                    break;
> +                }
> +            }
> +        } else if (id) {
> +            if (!strcmp(sn->id_str, id)) {
> +                *sn_info = *sn;
> +                found = true;
> +                break;
> +            }
>          }
>      }
> +
> +    if (!found) {
> +        error_setg(errp, "Failed to find snapshot '%s'", name ? name : id);
> +    }

Same here.

> +
>      g_free(sn_tab);
> -    return ret;
> +    return found;
>  }
>  
>  /*
> @@ -2296,7 +2336,7 @@ static int del_existing_snapshots(Monitor *mon, const char *name)
>      bs = NULL;
>      while ((bs = bdrv_next(bs))) {
>          if (bdrv_can_snapshot(bs) &&
> -            bdrv_snapshot_find(bs, snapshot, name) >= 0)
> +            bdrv_snapshot_find(bs, snapshot, name, NULL, NULL, true))
>          {
>              bdrv_snapshot_delete(bs, name, &local_err);
>              if (error_is_set(&local_err)) {
> @@ -2358,8 +2398,7 @@ void do_savevm(Monitor *mon, const QDict *qdict)
>      sn->vm_clock_nsec = qemu_get_clock_ns(vm_clock);
>  
>      if (name) {
> -        ret = bdrv_snapshot_find(bs, old_sn, name);
> -        if (ret >= 0) {
> +        if (bdrv_snapshot_find(bs, old_sn, name, NULL, NULL, true)) {
>              pstrcpy(sn->name, sizeof(sn->name), old_sn->name);
>              pstrcpy(sn->id_str, sizeof(sn->id_str), old_sn->id_str);
>          } else {
> @@ -2440,6 +2479,7 @@ int load_vmstate(const char *name)
>      BlockDriverState *bs, *bs_vm_state;
>      QEMUSnapshotInfo sn;
>      QEMUFile *f;
> +    Error *local_err = NULL;
>      int ret;
>  
>      bs_vm_state = bdrv_snapshots();
> @@ -2449,9 +2489,10 @@ int load_vmstate(const char *name)
>      }
>  
>      /* Don't even try to load empty VM states */
> -    ret = bdrv_snapshot_find(bs_vm_state, &sn, name);
> -    if (ret < 0) {
> -        return ret;
> +    if (!bdrv_snapshot_find(bs_vm_state, &sn, name, NULL, &local_err, true)) {
> +        error_report("Snapshot doesn't exist: %s", error_get_pretty(local_err));

"Could not find snapshot" (it could just be an I/O error in reading the
snapshot list)

Or actually, this message is fine for the case where you don't find the
snapshot, but have no error in bdrv_snapshot_find().

Should the device name of bs_vm_state be mentioned in the error message?

> +        error_free(local_err);
> +        return -ENOENT;
>      } else if (sn.vm_state_size == 0) {
>          error_report("This is a disk-only snapshot. Revert to it offline "
>              "using qemu-img.");

Kevin

  parent reply	other threads:[~2013-05-03 10:24 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
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 [this message]
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=20130503102418.GD3171@dhcp-200-207.str.redhat.com \
    --to=kwolf@redhat.com \
    --cc=armbru@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=phrdina@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=xiawenc@linux.vnet.ibm.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 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).