|
|
9ae3a8 |
From 94c066bcc75fa2e57d1bc861a7a65f21891425fe Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Date: Mon, 4 Nov 2013 22:31:53 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 02/87] block: move snapshot code in block.c to block/snapshot.c
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1383604354-12743-3-git-send-email-mreitz@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 55302
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.0 qemu-kvm PATCH 02/43] block: move snapshot code in block.c to block/snapshot.c
|
|
|
9ae3a8 |
Bugzilla: 1026524
|
|
|
9ae3a8 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
BZ: 1026524
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
All snapshot related code, except bdrv_snapshot_dump() and
|
|
|
9ae3a8 |
bdrv_is_snapshot(), is moved to block/snapshot.c. bdrv_snapshot_dump()
|
|
|
9ae3a8 |
will be moved to another file later. bdrv_is_snapshot() is not related
|
|
|
9ae3a8 |
with internal snapshot. It also fixes small code style errors reported
|
|
|
9ae3a8 |
by check script.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit de08c606f9ddafe647b6843e2b10a6d6030b0fc0)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block.c | 100 ------------------------------
|
|
|
9ae3a8 |
block/Makefile.objs | 1 +
|
|
|
9ae3a8 |
block/snapshot.c | 157 +++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
9ae3a8 |
include/block/block.h | 26 ++------
|
|
|
9ae3a8 |
include/block/snapshot.h | 53 ++++++++++++++++
|
|
|
9ae3a8 |
savevm.c | 23 +------
|
|
|
9ae3a8 |
6 files changed, 217 insertions(+), 143 deletions(-)
|
|
|
9ae3a8 |
create mode 100644 block/snapshot.c
|
|
|
9ae3a8 |
create mode 100644 include/block/snapshot.h
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block.c | 100 -----------------------------
|
|
|
9ae3a8 |
block/Makefile.objs | 1 +
|
|
|
9ae3a8 |
block/snapshot.c | 157 ++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
9ae3a8 |
include/block/block.h | 26 ++------
|
|
|
9ae3a8 |
include/block/snapshot.h | 53 ++++++++++++++++
|
|
|
9ae3a8 |
savevm.c | 23 +-------
|
|
|
9ae3a8 |
6 files changed, 217 insertions(+), 143 deletions(-)
|
|
|
9ae3a8 |
create mode 100644 block/snapshot.c
|
|
|
9ae3a8 |
create mode 100644 include/block/snapshot.h
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block.c b/block.c
|
|
|
9ae3a8 |
index 84a3a8d..69b70d0 100644
|
|
|
9ae3a8 |
--- a/block.c
|
|
|
9ae3a8 |
+++ b/block.c
|
|
|
9ae3a8 |
@@ -3458,111 +3458,11 @@ bool bdrv_debug_is_suspended(BlockDriverState *bs, const char *tag)
|
|
|
9ae3a8 |
return false;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-/**************************************************************/
|
|
|
9ae3a8 |
-/* handling of snapshots */
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-int bdrv_can_snapshot(BlockDriverState *bs)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- BlockDriver *drv = bs->drv;
|
|
|
9ae3a8 |
- if (!drv || !bdrv_is_inserted(bs) || bdrv_is_read_only(bs)) {
|
|
|
9ae3a8 |
- return 0;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (!drv->bdrv_snapshot_create) {
|
|
|
9ae3a8 |
- if (bs->file != NULL) {
|
|
|
9ae3a8 |
- return bdrv_can_snapshot(bs->file);
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- return 0;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- return 1;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
int bdrv_is_snapshot(BlockDriverState *bs)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
return !!(bs->open_flags & BDRV_O_SNAPSHOT);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-int bdrv_snapshot_create(BlockDriverState *bs,
|
|
|
9ae3a8 |
- QEMUSnapshotInfo *sn_info)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- BlockDriver *drv = bs->drv;
|
|
|
9ae3a8 |
- if (!drv)
|
|
|
9ae3a8 |
- return -ENOMEDIUM;
|
|
|
9ae3a8 |
- if (drv->bdrv_snapshot_create)
|
|
|
9ae3a8 |
- return drv->bdrv_snapshot_create(bs, sn_info);
|
|
|
9ae3a8 |
- if (bs->file)
|
|
|
9ae3a8 |
- return bdrv_snapshot_create(bs->file, sn_info);
|
|
|
9ae3a8 |
- return -ENOTSUP;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-int bdrv_snapshot_goto(BlockDriverState *bs,
|
|
|
9ae3a8 |
- const char *snapshot_id)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- BlockDriver *drv = bs->drv;
|
|
|
9ae3a8 |
- int ret, open_ret;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (!drv)
|
|
|
9ae3a8 |
- return -ENOMEDIUM;
|
|
|
9ae3a8 |
- if (drv->bdrv_snapshot_goto)
|
|
|
9ae3a8 |
- return drv->bdrv_snapshot_goto(bs, snapshot_id);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (bs->file) {
|
|
|
9ae3a8 |
- drv->bdrv_close(bs);
|
|
|
9ae3a8 |
- ret = bdrv_snapshot_goto(bs->file, snapshot_id);
|
|
|
9ae3a8 |
- open_ret = drv->bdrv_open(bs, NULL, bs->open_flags);
|
|
|
9ae3a8 |
- if (open_ret < 0) {
|
|
|
9ae3a8 |
- bdrv_delete(bs->file);
|
|
|
9ae3a8 |
- bs->drv = NULL;
|
|
|
9ae3a8 |
- return open_ret;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- return -ENOTSUP;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- BlockDriver *drv = bs->drv;
|
|
|
9ae3a8 |
- if (!drv)
|
|
|
9ae3a8 |
- return -ENOMEDIUM;
|
|
|
9ae3a8 |
- if (drv->bdrv_snapshot_delete)
|
|
|
9ae3a8 |
- return drv->bdrv_snapshot_delete(bs, snapshot_id);
|
|
|
9ae3a8 |
- if (bs->file)
|
|
|
9ae3a8 |
- return bdrv_snapshot_delete(bs->file, snapshot_id);
|
|
|
9ae3a8 |
- return -ENOTSUP;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-int bdrv_snapshot_list(BlockDriverState *bs,
|
|
|
9ae3a8 |
- QEMUSnapshotInfo **psn_info)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- BlockDriver *drv = bs->drv;
|
|
|
9ae3a8 |
- if (!drv)
|
|
|
9ae3a8 |
- return -ENOMEDIUM;
|
|
|
9ae3a8 |
- if (drv->bdrv_snapshot_list)
|
|
|
9ae3a8 |
- return drv->bdrv_snapshot_list(bs, psn_info);
|
|
|
9ae3a8 |
- if (bs->file)
|
|
|
9ae3a8 |
- return bdrv_snapshot_list(bs->file, psn_info);
|
|
|
9ae3a8 |
- return -ENOTSUP;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-int bdrv_snapshot_load_tmp(BlockDriverState *bs,
|
|
|
9ae3a8 |
- const char *snapshot_name)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- BlockDriver *drv = bs->drv;
|
|
|
9ae3a8 |
- if (!drv) {
|
|
|
9ae3a8 |
- return -ENOMEDIUM;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- if (!bs->read_only) {
|
|
|
9ae3a8 |
- return -EINVAL;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- if (drv->bdrv_snapshot_load_tmp) {
|
|
|
9ae3a8 |
- return drv->bdrv_snapshot_load_tmp(bs, snapshot_name);
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- return -ENOTSUP;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
/* backing_file can either be relative, or absolute, or a protocol. If it is
|
|
|
9ae3a8 |
* relative, it must be relative to the chain. So, passing in bs->filename
|
|
|
9ae3a8 |
* from a BDS as backing_file should not be done, as that may be relative to
|
|
|
9ae3a8 |
diff --git a/block/Makefile.objs b/block/Makefile.objs
|
|
|
9ae3a8 |
index 41a284b..162f270 100644
|
|
|
9ae3a8 |
--- a/block/Makefile.objs
|
|
|
9ae3a8 |
+++ b/block/Makefile.objs
|
|
|
9ae3a8 |
@@ -4,6 +4,7 @@ block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
|
|
|
9ae3a8 |
block-obj-y += qed-check.o
|
|
|
9ae3a8 |
block-obj-y += vhdx.o
|
|
|
9ae3a8 |
block-obj-y += parallels.o blkdebug.o blkverify.o
|
|
|
9ae3a8 |
+block-obj-y += snapshot.o
|
|
|
9ae3a8 |
block-obj-$(CONFIG_WIN32) += raw-win32.o win32-aio.o
|
|
|
9ae3a8 |
block-obj-$(CONFIG_POSIX) += raw-posix.o
|
|
|
9ae3a8 |
block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
|
|
|
9ae3a8 |
diff --git a/block/snapshot.c b/block/snapshot.c
|
|
|
9ae3a8 |
new file mode 100644
|
|
|
9ae3a8 |
index 0000000..6c6d9de
|
|
|
9ae3a8 |
--- /dev/null
|
|
|
9ae3a8 |
+++ b/block/snapshot.c
|
|
|
9ae3a8 |
@@ -0,0 +1,157 @@
|
|
|
9ae3a8 |
+/*
|
|
|
9ae3a8 |
+ * Block layer snapshot related functions
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * Copyright (c) 2003-2008 Fabrice Bellard
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
9ae3a8 |
+ * of this software and associated documentation files (the "Software"), to deal
|
|
|
9ae3a8 |
+ * in the Software without restriction, including without limitation the rights
|
|
|
9ae3a8 |
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
9ae3a8 |
+ * copies of the Software, and to permit persons to whom the Software is
|
|
|
9ae3a8 |
+ * furnished to do so, subject to the following conditions:
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * The above copyright notice and this permission notice shall be included in
|
|
|
9ae3a8 |
+ * all copies or substantial portions of the Software.
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
9ae3a8 |
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
9ae3a8 |
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
9ae3a8 |
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
9ae3a8 |
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
9ae3a8 |
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
9ae3a8 |
+ * THE SOFTWARE.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#include "block/snapshot.h"
|
|
|
9ae3a8 |
+#include "block/block_int.h"
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
|
|
|
9ae3a8 |
+ const char *name)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ QEMUSnapshotInfo *sn_tab, *sn;
|
|
|
9ae3a8 |
+ int nb_sns, i, ret;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ ret = -ENOENT;
|
|
|
9ae3a8 |
+ nb_sns = bdrv_snapshot_list(bs, &sn_tab);
|
|
|
9ae3a8 |
+ if (nb_sns < 0) {
|
|
|
9ae3a8 |
+ return ret;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ for (i = 0; i < nb_sns; i++) {
|
|
|
9ae3a8 |
+ sn = &sn_tab[i];
|
|
|
9ae3a8 |
+ if (!strcmp(sn->id_str, name) || !strcmp(sn->name, name)) {
|
|
|
9ae3a8 |
+ *sn_info = *sn;
|
|
|
9ae3a8 |
+ ret = 0;
|
|
|
9ae3a8 |
+ break;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ g_free(sn_tab);
|
|
|
9ae3a8 |
+ return ret;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+int bdrv_can_snapshot(BlockDriverState *bs)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ BlockDriver *drv = bs->drv;
|
|
|
9ae3a8 |
+ if (!drv || !bdrv_is_inserted(bs) || bdrv_is_read_only(bs)) {
|
|
|
9ae3a8 |
+ return 0;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (!drv->bdrv_snapshot_create) {
|
|
|
9ae3a8 |
+ if (bs->file != NULL) {
|
|
|
9ae3a8 |
+ return bdrv_can_snapshot(bs->file);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ return 0;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ return 1;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+int bdrv_snapshot_create(BlockDriverState *bs,
|
|
|
9ae3a8 |
+ QEMUSnapshotInfo *sn_info)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ BlockDriver *drv = bs->drv;
|
|
|
9ae3a8 |
+ if (!drv) {
|
|
|
9ae3a8 |
+ return -ENOMEDIUM;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ if (drv->bdrv_snapshot_create) {
|
|
|
9ae3a8 |
+ return drv->bdrv_snapshot_create(bs, sn_info);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ if (bs->file) {
|
|
|
9ae3a8 |
+ return bdrv_snapshot_create(bs->file, sn_info);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ return -ENOTSUP;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+int bdrv_snapshot_goto(BlockDriverState *bs,
|
|
|
9ae3a8 |
+ const char *snapshot_id)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ BlockDriver *drv = bs->drv;
|
|
|
9ae3a8 |
+ int ret, open_ret;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (!drv) {
|
|
|
9ae3a8 |
+ return -ENOMEDIUM;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ if (drv->bdrv_snapshot_goto) {
|
|
|
9ae3a8 |
+ return drv->bdrv_snapshot_goto(bs, snapshot_id);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (bs->file) {
|
|
|
9ae3a8 |
+ drv->bdrv_close(bs);
|
|
|
9ae3a8 |
+ ret = bdrv_snapshot_goto(bs->file, snapshot_id);
|
|
|
9ae3a8 |
+ open_ret = drv->bdrv_open(bs, NULL, bs->open_flags);
|
|
|
9ae3a8 |
+ if (open_ret < 0) {
|
|
|
9ae3a8 |
+ bdrv_delete(bs->file);
|
|
|
9ae3a8 |
+ bs->drv = NULL;
|
|
|
9ae3a8 |
+ return open_ret;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ return ret;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ return -ENOTSUP;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ BlockDriver *drv = bs->drv;
|
|
|
9ae3a8 |
+ if (!drv) {
|
|
|
9ae3a8 |
+ return -ENOMEDIUM;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ if (drv->bdrv_snapshot_delete) {
|
|
|
9ae3a8 |
+ return drv->bdrv_snapshot_delete(bs, snapshot_id);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ if (bs->file) {
|
|
|
9ae3a8 |
+ return bdrv_snapshot_delete(bs->file, snapshot_id);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ return -ENOTSUP;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+int bdrv_snapshot_list(BlockDriverState *bs,
|
|
|
9ae3a8 |
+ QEMUSnapshotInfo **psn_info)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ BlockDriver *drv = bs->drv;
|
|
|
9ae3a8 |
+ if (!drv) {
|
|
|
9ae3a8 |
+ return -ENOMEDIUM;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ if (drv->bdrv_snapshot_list) {
|
|
|
9ae3a8 |
+ return drv->bdrv_snapshot_list(bs, psn_info);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ if (bs->file) {
|
|
|
9ae3a8 |
+ return bdrv_snapshot_list(bs->file, psn_info);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ return -ENOTSUP;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+int bdrv_snapshot_load_tmp(BlockDriverState *bs,
|
|
|
9ae3a8 |
+ const char *snapshot_name)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ BlockDriver *drv = bs->drv;
|
|
|
9ae3a8 |
+ if (!drv) {
|
|
|
9ae3a8 |
+ return -ENOMEDIUM;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ if (!bs->read_only) {
|
|
|
9ae3a8 |
+ return -EINVAL;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ if (drv->bdrv_snapshot_load_tmp) {
|
|
|
9ae3a8 |
+ return drv->bdrv_snapshot_load_tmp(bs, snapshot_name);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ return -ENOTSUP;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
diff --git a/include/block/block.h b/include/block/block.h
|
|
|
9ae3a8 |
index 3b3f40e..03ebc47 100644
|
|
|
9ae3a8 |
--- a/include/block/block.h
|
|
|
9ae3a8 |
+++ b/include/block/block.h
|
|
|
9ae3a8 |
@@ -7,6 +7,11 @@
|
|
|
9ae3a8 |
#include "block/coroutine.h"
|
|
|
9ae3a8 |
#include "qapi/qmp/qobject.h"
|
|
|
9ae3a8 |
#include "qapi-types.h"
|
|
|
9ae3a8 |
+/*
|
|
|
9ae3a8 |
+ * snapshot.h is needed since bdrv_snapshot_dump(), it can be removed when the
|
|
|
9ae3a8 |
+ * function is moved to other file.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+#include "block/snapshot.h"
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* block.c */
|
|
|
9ae3a8 |
typedef struct BlockDriver BlockDriver;
|
|
|
9ae3a8 |
@@ -27,17 +32,6 @@ typedef struct BlockFragInfo {
|
|
|
9ae3a8 |
uint64_t compressed_clusters;
|
|
|
9ae3a8 |
} BlockFragInfo;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-typedef struct QEMUSnapshotInfo {
|
|
|
9ae3a8 |
- char id_str[128]; /* unique snapshot id */
|
|
|
9ae3a8 |
- /* the following fields are informative. They are not needed for
|
|
|
9ae3a8 |
- the consistency of the snapshot */
|
|
|
9ae3a8 |
- char name[256]; /* user chosen name */
|
|
|
9ae3a8 |
- uint64_t vm_state_size; /* VM state info size */
|
|
|
9ae3a8 |
- uint32_t date_sec; /* UTC date of the snapshot */
|
|
|
9ae3a8 |
- uint32_t date_nsec;
|
|
|
9ae3a8 |
- uint64_t vm_clock_nsec; /* VM clock relative to boot */
|
|
|
9ae3a8 |
-} QEMUSnapshotInfo;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
/* Callbacks for block device models */
|
|
|
9ae3a8 |
typedef struct BlockDevOps {
|
|
|
9ae3a8 |
/*
|
|
|
9ae3a8 |
@@ -360,17 +354,7 @@ void bdrv_get_full_backing_filename(BlockDriverState *bs,
|
|
|
9ae3a8 |
char *dest, size_t sz);
|
|
|
9ae3a8 |
BlockInfo *bdrv_query_info(BlockDriverState *s);
|
|
|
9ae3a8 |
BlockStats *bdrv_query_stats(const BlockDriverState *bs);
|
|
|
9ae3a8 |
-int bdrv_can_snapshot(BlockDriverState *bs);
|
|
|
9ae3a8 |
int bdrv_is_snapshot(BlockDriverState *bs);
|
|
|
9ae3a8 |
-int bdrv_snapshot_create(BlockDriverState *bs,
|
|
|
9ae3a8 |
- QEMUSnapshotInfo *sn_info);
|
|
|
9ae3a8 |
-int bdrv_snapshot_goto(BlockDriverState *bs,
|
|
|
9ae3a8 |
- const char *snapshot_id);
|
|
|
9ae3a8 |
-int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id);
|
|
|
9ae3a8 |
-int bdrv_snapshot_list(BlockDriverState *bs,
|
|
|
9ae3a8 |
- QEMUSnapshotInfo **psn_info);
|
|
|
9ae3a8 |
-int bdrv_snapshot_load_tmp(BlockDriverState *bs,
|
|
|
9ae3a8 |
- const char *snapshot_name);
|
|
|
9ae3a8 |
char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
char *get_human_readable_size(char *buf, int buf_size, int64_t size);
|
|
|
9ae3a8 |
diff --git a/include/block/snapshot.h b/include/block/snapshot.h
|
|
|
9ae3a8 |
new file mode 100644
|
|
|
9ae3a8 |
index 0000000..eaf61f0
|
|
|
9ae3a8 |
--- /dev/null
|
|
|
9ae3a8 |
+++ b/include/block/snapshot.h
|
|
|
9ae3a8 |
@@ -0,0 +1,53 @@
|
|
|
9ae3a8 |
+/*
|
|
|
9ae3a8 |
+ * Block layer snapshot related functions
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * Copyright (c) 2003-2008 Fabrice Bellard
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
9ae3a8 |
+ * of this software and associated documentation files (the "Software"), to deal
|
|
|
9ae3a8 |
+ * in the Software without restriction, including without limitation the rights
|
|
|
9ae3a8 |
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
9ae3a8 |
+ * copies of the Software, and to permit persons to whom the Software is
|
|
|
9ae3a8 |
+ * furnished to do so, subject to the following conditions:
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * The above copyright notice and this permission notice shall be included in
|
|
|
9ae3a8 |
+ * all copies or substantial portions of the Software.
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
9ae3a8 |
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
9ae3a8 |
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
9ae3a8 |
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
9ae3a8 |
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
9ae3a8 |
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
9ae3a8 |
+ * THE SOFTWARE.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#ifndef SNAPSHOT_H
|
|
|
9ae3a8 |
+#define SNAPSHOT_H
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#include "qemu-common.h"
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+typedef struct QEMUSnapshotInfo {
|
|
|
9ae3a8 |
+ char id_str[128]; /* unique snapshot id */
|
|
|
9ae3a8 |
+ /* the following fields are informative. They are not needed for
|
|
|
9ae3a8 |
+ the consistency of the snapshot */
|
|
|
9ae3a8 |
+ char name[256]; /* user chosen name */
|
|
|
9ae3a8 |
+ uint64_t vm_state_size; /* VM state info size */
|
|
|
9ae3a8 |
+ uint32_t date_sec; /* UTC date of the snapshot */
|
|
|
9ae3a8 |
+ uint32_t date_nsec;
|
|
|
9ae3a8 |
+ uint64_t vm_clock_nsec; /* VM clock relative to boot */
|
|
|
9ae3a8 |
+} QEMUSnapshotInfo;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
|
|
|
9ae3a8 |
+ const char *name);
|
|
|
9ae3a8 |
+int bdrv_can_snapshot(BlockDriverState *bs);
|
|
|
9ae3a8 |
+int bdrv_snapshot_create(BlockDriverState *bs,
|
|
|
9ae3a8 |
+ QEMUSnapshotInfo *sn_info);
|
|
|
9ae3a8 |
+int bdrv_snapshot_goto(BlockDriverState *bs,
|
|
|
9ae3a8 |
+ const char *snapshot_id);
|
|
|
9ae3a8 |
+int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id);
|
|
|
9ae3a8 |
+int bdrv_snapshot_list(BlockDriverState *bs,
|
|
|
9ae3a8 |
+ QEMUSnapshotInfo **psn_info);
|
|
|
9ae3a8 |
+int bdrv_snapshot_load_tmp(BlockDriverState *bs,
|
|
|
9ae3a8 |
+ const char *snapshot_name);
|
|
|
9ae3a8 |
+#endif
|
|
|
9ae3a8 |
diff --git a/savevm.c b/savevm.c
|
|
|
9ae3a8 |
index d9f3787..005bf35 100644
|
|
|
9ae3a8 |
--- a/savevm.c
|
|
|
9ae3a8 |
+++ b/savevm.c
|
|
|
9ae3a8 |
@@ -40,6 +40,7 @@
|
|
|
9ae3a8 |
#include "trace.h"
|
|
|
9ae3a8 |
#include "qemu/bitops.h"
|
|
|
9ae3a8 |
#include "qemu/iov.h"
|
|
|
9ae3a8 |
+#include "block/snapshot.h"
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
#define SELF_ANNOUNCE_ROUNDS 5
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -2273,28 +2274,6 @@ static BlockDriverState *find_vmstate_bs(void)
|
|
|
9ae3a8 |
return NULL;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
|
|
|
9ae3a8 |
- const char *name)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- QEMUSnapshotInfo *sn_tab, *sn;
|
|
|
9ae3a8 |
- int nb_sns, i, ret;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- ret = -ENOENT;
|
|
|
9ae3a8 |
- nb_sns = bdrv_snapshot_list(bs, &sn_tab);
|
|
|
9ae3a8 |
- if (nb_sns < 0)
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
- for(i = 0; i < nb_sns; i++) {
|
|
|
9ae3a8 |
- sn = &sn_tab[i];
|
|
|
9ae3a8 |
- if (!strcmp(sn->id_str, name) || !strcmp(sn->name, name)) {
|
|
|
9ae3a8 |
- *sn_info = *sn;
|
|
|
9ae3a8 |
- ret = 0;
|
|
|
9ae3a8 |
- break;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- g_free(sn_tab);
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
/*
|
|
|
9ae3a8 |
* Deletes snapshots of a given name in all opened images.
|
|
|
9ae3a8 |
*/
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|