From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, phrdina@redhat.com, famz@redhat.com,
Wenchao Xia <xiawenc@linux.vnet.ibm.com>,
armbru@redhat.com, lcapitulino@redhat.com, stefanha@redhat.com,
pbonzini@redhat.com, dietmar@proxmox.com
Subject: [Qemu-devel] [PATCH V4 1/9] snapshot: new function bdrv_snapshot_find_by_id_and_name()
Date: Mon, 8 Jul 2013 16:00:43 +0800 [thread overview]
Message-ID: <1373270451-18436-2-git-send-email-xiawenc@linux.vnet.ibm.com> (raw)
In-Reply-To: <1373270451-18436-1-git-send-email-xiawenc@linux.vnet.ibm.com>
To make it clear about id and name in searching, add this API
to distinguish them. Caller can choose to search by id or name,
*errp will be set only for exception.
Some code are modified based on Pavel's patch.
Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
block/snapshot.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++
include/block/snapshot.h | 6 ++++
2 files changed, 79 insertions(+), 0 deletions(-)
diff --git a/block/snapshot.c b/block/snapshot.c
index 6c6d9de..481a3ee 100644
--- a/block/snapshot.c
+++ b/block/snapshot.c
@@ -48,6 +48,79 @@ int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
return ret;
}
+/**
+ * Look up an internal snapshot by @id and @name.
+ * @bs: block device to search
+ * @id: unique snapshot ID, or NULL
+ * @name: snapshot name, or NULL
+ * @sn_info: location to store information on the snapshot found
+ * @errp: location to store error, will be set only for exception
+ *
+ * This function will traverse snapshot list in @bs to search the matching
+ * one, @id and @name are the matching condition:
+ * If both @id and @name are specified, find the first one with id @id and
+ * name @name.
+ * If only @id is specified, find the first one with id @id.
+ * If only @name is specified, find the first one with name @name.
+ * if none is specified, abort().
+ *
+ * Returns: true when a snapshot is found and @sn_info will be filled, false
+ * when error or not found. If all operation succeed but no matching one is
+ * found, @errp will NOT be set.
+ */
+bool bdrv_snapshot_find_by_id_and_name(BlockDriverState *bs,
+ const char *id,
+ const char *name,
+ QEMUSnapshotInfo *sn_info,
+ Error **errp)
+{
+ QEMUSnapshotInfo *sn_tab, *sn;
+ int nb_sns, i;
+ bool ret = false;
+
+ assert(id || name);
+
+ nb_sns = bdrv_snapshot_list(bs, &sn_tab);
+ if (nb_sns < 0) {
+ error_setg_errno(errp, -nb_sns, "Failed to get a snapshot list");
+ return false;
+ } else if (nb_sns == 0) {
+ return false;
+ }
+
+ if (id && name) {
+ for (i = 0; i < nb_sns; i++) {
+ sn = &sn_tab[i];
+ if (!strcmp(sn->id_str, id) && !strcmp(sn->name, name)) {
+ *sn_info = *sn;
+ ret = true;
+ break;
+ }
+ }
+ } else if (id) {
+ for (i = 0; i < nb_sns; i++) {
+ sn = &sn_tab[i];
+ if (!strcmp(sn->id_str, id)) {
+ *sn_info = *sn;
+ ret = true;
+ break;
+ }
+ }
+ } else if (name) {
+ for (i = 0; i < nb_sns; i++) {
+ sn = &sn_tab[i];
+ if (!strcmp(sn->name, name)) {
+ *sn_info = *sn;
+ ret = true;
+ break;
+ }
+ }
+ }
+
+ g_free(sn_tab);
+ return ret;
+}
+
int bdrv_can_snapshot(BlockDriverState *bs)
{
BlockDriver *drv = bs->drv;
diff --git a/include/block/snapshot.h b/include/block/snapshot.h
index eaf61f0..9d06dc1 100644
--- a/include/block/snapshot.h
+++ b/include/block/snapshot.h
@@ -26,6 +26,7 @@
#define SNAPSHOT_H
#include "qemu-common.h"
+#include "qapi/error.h"
typedef struct QEMUSnapshotInfo {
char id_str[128]; /* unique snapshot id */
@@ -40,6 +41,11 @@ typedef struct QEMUSnapshotInfo {
int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
const char *name);
+bool bdrv_snapshot_find_by_id_and_name(BlockDriverState *bs,
+ const char *id,
+ const char *name,
+ QEMUSnapshotInfo *sn_info,
+ Error **errp);
int bdrv_can_snapshot(BlockDriverState *bs);
int bdrv_snapshot_create(BlockDriverState *bs,
QEMUSnapshotInfo *sn_info);
--
1.7.1
next prev parent reply other threads:[~2013-07-08 8:04 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-08 8:00 [Qemu-devel] [PATCH V4 0/9] add internal snapshot support at block device level Wenchao Xia
2013-07-08 8:00 ` Wenchao Xia [this message]
2013-07-08 8:00 ` [Qemu-devel] [PATCH V4 2/9] snapshot: add paired functions for internal snapshot id and name Wenchao Xia
2013-07-10 13:10 ` Kevin Wolf
2013-07-10 13:54 ` Wenchao Xia
2013-07-10 14:22 ` Kevin Wolf
2013-07-10 14:43 ` Wenchao Xia
2013-07-10 14:49 ` Kevin Wolf
2013-07-10 15:17 ` Wenchao Xia
2013-07-08 8:00 ` [Qemu-devel] [PATCH V4 3/9] snapshot: distinguish id and name in snapshot delete Wenchao Xia
2013-07-08 8:00 ` [Qemu-devel] [PATCH V4 4/9] qmp: add internal snapshot support in qmp_transaction Wenchao Xia
2013-07-08 8:00 ` [Qemu-devel] [PATCH V4 5/9] qmp: add interface blockdev-snapshot-internal-sync Wenchao Xia
2013-07-08 8:00 ` [Qemu-devel] [PATCH V4 6/9] qmp: add interface blockdev-snapshot-delete-internal-sync Wenchao Xia
2013-07-08 8:00 ` [Qemu-devel] [PATCH V4 7/9] hmp: add interface hmp_snapshot_blkdev_internal Wenchao Xia
2013-07-08 8:00 ` [Qemu-devel] [PATCH V4 8/9] hmp: add interface hmp_snapshot_delete_blkdev_internal Wenchao Xia
2013-07-08 8:00 ` [Qemu-devel] [PATCH V4 9/9] qemu-iotests: add 056 internal snapshot for block device test case 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=1373270451-18436-2-git-send-email-xiawenc@linux.vnet.ibm.com \
--to=xiawenc@linux.vnet.ibm.com \
--cc=armbru@redhat.com \
--cc=dietmar@proxmox.com \
--cc=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=pbonzini@redhat.com \
--cc=phrdina@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@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 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).