qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, stefanha@gmail.com, armbru@redhat.com,
	lcapitulino@redhat.com, pbonzini@redhat.com,
	Wenchao Xia <xiawenc@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH V9 02/14] block: distinguish id and name in bdrv_find_snapshot()
Date: Mon, 11 Mar 2013 19:23:04 +0800	[thread overview]
Message-ID: <1363000996-13221-3-git-send-email-xiawenc@linux.vnet.ibm.com> (raw)
In-Reply-To: <1363000996-13221-1-git-send-email-xiawenc@linux.vnet.ibm.com>

  To make it clear about id and name in searching, the API is changed
a bit to distinguish them, and caller can choose to search by id or name.
Searching will be done with higher priority of id. This function also
returns negative value from bdrv_snapshot_list() instead of -ENOENT on
error now.

Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 block/snapshot.c         |   46 ++++++++++++++++++++++++++++++++++++++--------
 include/block/snapshot.h |    2 +-
 savevm.c                 |   10 +++++-----
 3 files changed, 44 insertions(+), 14 deletions(-)

diff --git a/block/snapshot.c b/block/snapshot.c
index 8de73b4..1449b3d 100644
--- a/block/snapshot.c
+++ b/block/snapshot.c
@@ -13,8 +13,20 @@
 
 #include "block/snapshot.h"
 
+/*
+ * Try find an internal snapshot with @id or @name, @id have higher priority
+ * in searching.
+ *
+ * @bs: block device to search on, must not be NULL.
+ * @sn_info: snapshot information to be filled in, must not be NULL.
+ * @id: snapshot id to search with, can be NULL.
+ * @name: snapshot name to search with, can be NULL.
+ *
+ * returns 0 and @sn_info is filled with related information if found,
+ * otherwise it returns negative value.
+ */
 int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
-                       const char *name)
+                       const char *id, const char *name)
 {
     QEMUSnapshotInfo *sn_tab, *sn;
     int nb_sns, i, ret;
@@ -22,16 +34,34 @@ int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
     ret = -ENOENT;
     nb_sns = bdrv_snapshot_list(bs, &sn_tab);
     if (nb_sns < 0) {
-        return ret;
+        return nb_sns;
     }
-    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;
+
+    /* search by id */
+    if (id) {
+        for (i = 0; i < nb_sns; i++) {
+            sn = &sn_tab[i];
+            if (!strcmp(sn->id_str, id)) {
+                *sn_info = *sn;
+                ret = 0;
+                goto out;
+            }
         }
     }
+
+    /* search by name */
+    if (name) {
+        for (i = 0; i < nb_sns; i++) {
+            sn = &sn_tab[i];
+            if (!strcmp(sn->name, name)) {
+                *sn_info = *sn;
+                ret = 0;
+                goto out;
+            }
+        }
+    }
+
+ out:
     g_free(sn_tab);
     return ret;
 }
diff --git a/include/block/snapshot.h b/include/block/snapshot.h
index 86891d1..fc9be7b 100644
--- a/include/block/snapshot.h
+++ b/include/block/snapshot.h
@@ -22,5 +22,5 @@
 #include "block.h"
 
 int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
-                       const char *name);
+                       const char *id, const char *name);
 #endif
diff --git a/savevm.c b/savevm.c
index 95f19ca..6557750 100644
--- a/savevm.c
+++ b/savevm.c
@@ -2073,7 +2073,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, name) >= 0)
         {
             ret = bdrv_snapshot_delete(bs, name);
             if (ret < 0) {
@@ -2133,7 +2133,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);
+        ret = bdrv_snapshot_find(bs, old_sn, name, name);
         if (ret >= 0) {
             pstrcpy(sn->name, sizeof(sn->name), old_sn->name);
             pstrcpy(sn->id_str, sizeof(sn->id_str), old_sn->id_str);
@@ -2224,7 +2224,7 @@ int load_vmstate(const char *name)
     }
 
     /* Don't even try to load empty VM states */
-    ret = bdrv_snapshot_find(bs_vm_state, &sn, name);
+    ret = bdrv_snapshot_find(bs_vm_state, &sn, name, name);
     if (ret < 0) {
         return ret;
     } else if (sn.vm_state_size == 0) {
@@ -2248,7 +2248,7 @@ int load_vmstate(const char *name)
             return -ENOTSUP;
         }
 
-        ret = bdrv_snapshot_find(bs, &sn, name);
+        ret = bdrv_snapshot_find(bs, &sn, name, name);
         if (ret < 0) {
             error_report("Device '%s' does not have the requested snapshot '%s'",
                            bdrv_get_device_name(bs), name);
@@ -2354,7 +2354,7 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict)
 
         while ((bs1 = bdrv_next(bs1))) {
             if (bdrv_can_snapshot(bs1) && bs1 != bs) {
-                ret = bdrv_snapshot_find(bs1, sn_info, sn->id_str);
+                ret = bdrv_snapshot_find(bs1, sn_info, sn->id_str, NULL);
                 if (ret < 0) {
                     available = 0;
                     break;
-- 
1.7.1

  parent reply	other threads:[~2013-03-11 11:25 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-11 11:23 [Qemu-devel] [PATCH V9 00/14] qmp/hmp interfaces for internal snapshot info Wenchao Xia
2013-03-11 11:23 ` [Qemu-devel] [PATCH V9 01/14] block: move bdrv_snapshot_find() to block/snapshot.c Wenchao Xia
2013-03-11 17:49   ` Eric Blake
2013-03-12  5:01     ` Wenchao Xia
2013-03-12 16:15       ` Eric Blake
2013-03-12 16:22         ` Eric Blake
2013-03-13  1:57           ` Wenchao Xia
2013-03-13 12:41       ` Kevin Wolf
2013-03-13 18:19         ` Markus Armbruster
2013-03-13 20:28           ` Eric Blake
2013-03-14  9:01           ` Kevin Wolf
2013-03-14 12:10             ` Markus Armbruster
2013-03-14 12:53               ` Kevin Wolf
2013-03-15  6:23                 ` Wenchao Xia
2013-03-15  8:00                   ` Kevin Wolf
2013-03-13 18:08     ` Markus Armbruster
2013-03-11 11:23 ` Wenchao Xia [this message]
2013-03-11 11:23 ` [Qemu-devel] [PATCH V9 03/14] qemu-img: remove unused parameter in collect_image_info() Wenchao Xia
2013-03-11 11:23 ` [Qemu-devel] [PATCH V9 04/14] block: move collect_snapshots() and collect_image_info() to block/qapi.c Wenchao Xia
2013-03-12 19:41   ` Eric Blake
2013-03-13 20:34     ` Eric Blake
2013-03-11 11:23 ` [Qemu-devel] [PATCH V9 05/14] block: add snapshot info query function bdrv_query_snapshot_info_list() Wenchao Xia
2013-03-11 11:23 ` [Qemu-devel] [PATCH V9 06/14] block: add check for VM snapshot in bdrv_query_snapshot_info_list() Wenchao Xia
2013-03-12 19:45   ` Eric Blake
2013-03-11 11:23 ` [Qemu-devel] [PATCH V9 07/14] block: add image info query function bdrv_query_image_info() Wenchao Xia
2013-03-11 11:23 ` [Qemu-devel] [PATCH V9 08/14] qmp: add interface query-snapshots Wenchao Xia
2013-03-12 21:12   ` Eric Blake
2013-03-11 11:23 ` [Qemu-devel] [PATCH V9 09/14] qmp: add interface query-images Wenchao Xia
2013-03-12 21:24   ` Eric Blake
2013-03-11 11:23 ` [Qemu-devel] [PATCH V9 10/14] hmp: add function hmp_info_snapshots() Wenchao Xia
2013-03-11 11:23 ` [Qemu-devel] [PATCH V9 11/14] hmp: switch snapshot info function to qmp based one Wenchao Xia
2013-03-11 11:23 ` [Qemu-devel] [PATCH V9 12/14] block: move dump_human_image_info() to block/qapi.c Wenchao Xia
2013-03-13 20:38   ` Eric Blake
2013-03-11 11:23 ` [Qemu-devel] [PATCH V9 13/14] block: dump to buffer for bdrv_image_info_dump() Wenchao Xia
2013-03-11 11:23 ` [Qemu-devel] [PATCH V9 14/14] hmp: add command info images Wenchao Xia
2013-03-12 10:07 ` [Qemu-devel] [PATCH V9 00/14] qmp/hmp interfaces for internal snapshot info Stefan Hajnoczi
2013-03-12 16:16   ` Eric Blake
2013-03-13  2:54     ` Wenchao Xia
2013-03-13 11:34       ` Stefan Hajnoczi
2013-03-13 12:29         ` Eric Blake
2013-03-13 12:35           ` Kevin Wolf
2013-03-13 12:40           ` Stefan Hajnoczi
2013-03-15  6:07             ` Wenchao Xia
2013-03-15  8:07               ` Kevin Wolf
2013-03-18 10:30                 ` Wenchao Xia
2013-03-18 16:48                   ` Kevin Wolf
2013-03-15  8:44               ` 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=1363000996-13221-3-git-send-email-xiawenc@linux.vnet.ibm.com \
    --to=xiawenc@linux.vnet.ibm.com \
    --cc=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.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).