[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 14/33] snapshot: new function bdrv_snapshot_find_by_i
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 14/33] snapshot: new function bdrv_snapshot_find_by_id_and_name() |
Date: |
Fri, 13 Sep 2013 13:50:44 +0200 |
From: Wenchao Xia <address@hidden>
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 <address@hidden>
Signed-off-by: Pavel Hrdina <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/snapshot.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++
include/block/snapshot.h | 6 ++++
2 files changed, 79 insertions(+)
diff --git a/block/snapshot.c b/block/snapshot.c
index 8f61cc0..a923b38 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.8.1.4
- [Qemu-devel] [PULL 02/33] qcow2: Discard VM state in active L1 after creating snapshot, (continued)
- [Qemu-devel] [PULL 02/33] qcow2: Discard VM state in active L1 after creating snapshot, Kevin Wolf, 2013/09/13
- [Qemu-devel] [PULL 11/33] qemu-iotests: add infrastructure of fd passing via SCM, Kevin Wolf, 2013/09/13
- [Qemu-devel] [PULL 10/33] qemu-iotests: add unix socket help program, Kevin Wolf, 2013/09/13
- [Qemu-devel] [PULL 09/33] qemu-iotest: qcow2 image option amendment, Kevin Wolf, 2013/09/13
- [Qemu-devel] [PULL 08/33] qcow2: Implement bdrv_amend_options, Kevin Wolf, 2013/09/13
- [Qemu-devel] [PULL 12/33] qemu-iotests: add tests for runtime fd passing via SCM rights, Kevin Wolf, 2013/09/13
- [Qemu-devel] [PULL 13/33] qemu-iotests: New test case in 061, Kevin Wolf, 2013/09/13
- [Qemu-devel] [PULL 15/33] snapshot: distinguish id and name in snapshot delete, Kevin Wolf, 2013/09/13
- [Qemu-devel] [PULL 14/33] snapshot: new function bdrv_snapshot_find_by_id_and_name(),
Kevin Wolf <=
- [Qemu-devel] [PULL 16/33] qmp: add internal snapshot support in qmp_transaction, Kevin Wolf, 2013/09/13
- [Qemu-devel] [PULL 17/33] qmp: add interface blockdev-snapshot-internal-sync, Kevin Wolf, 2013/09/13
- [Qemu-devel] [PULL 18/33] qmp: add interface blockdev-snapshot-delete-internal-sync, Kevin Wolf, 2013/09/13
- [Qemu-devel] [PULL 19/33] hmp: add interface hmp_snapshot_blkdev_internal, Kevin Wolf, 2013/09/13
- [Qemu-devel] [PULL 20/33] hmp: add interface hmp_snapshot_delete_blkdev_internal, Kevin Wolf, 2013/09/13
- [Qemu-devel] [PULL 21/33] qemu-iotests: add 057 internal snapshot for block device test case, Kevin Wolf, 2013/09/13
- [Qemu-devel] [PULL 22/33] bdrv: Use "Error" for opening images, Kevin Wolf, 2013/09/13
- [Qemu-devel] [PULL 23/33] bdrv: Use "Error" for creating images, Kevin Wolf, 2013/09/13
- [Qemu-devel] [PULL 26/33] qemu-img create: Emit filename on error, Kevin Wolf, 2013/09/13
- [Qemu-devel] [PULL 24/33] block: Error parameter for open functions, Kevin Wolf, 2013/09/13