From fa9d18271580596e793d18987540146bdcf2e6a8 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 19 Sep 2012 13:09:51 +0200 Subject: [PATCH] snapshot: fix load/save state --- debian/patches/internal-snapshot.patch | 41 ++++++++++--------- debian/patches/load-state-from-blockdev.patch | 36 ++++++++++++---- debian/patches/move-bdrv-snapshot-find.patch | 14 +++---- 3 files changed, 56 insertions(+), 35 deletions(-) diff --git a/debian/patches/internal-snapshot.patch b/debian/patches/internal-snapshot.patch index 77f0338..20e73c6 100644 --- a/debian/patches/internal-snapshot.patch +++ b/debian/patches/internal-snapshot.patch @@ -1,7 +1,7 @@ Index: new/qapi-schema.json =================================================================== ---- new.orig/qapi-schema.json 2012-09-18 06:20:41.000000000 +0200 -+++ new/qapi-schema.json 2012-09-18 08:43:25.000000000 +0200 +--- new.orig/qapi-schema.json 2012-09-19 12:46:53.000000000 +0200 ++++ new/qapi-schema.json 2012-09-19 12:51:10.000000000 +0200 @@ -2493,3 +2493,12 @@ # Since: 1.2.0 ## @@ -17,9 +17,9 @@ Index: new/qapi-schema.json +{ 'command': 'snapshot-end' } Index: new/qmp.c =================================================================== ---- new.orig/qmp.c 2012-09-18 06:20:41.000000000 +0200 -+++ new/qmp.c 2012-09-18 08:54:54.000000000 +0200 -@@ -479,3 +479,193 @@ +--- new.orig/qmp.c 2012-09-19 12:46:53.000000000 +0200 ++++ new/qmp.c 2012-09-19 12:51:10.000000000 +0200 +@@ -479,3 +479,196 @@ return arch_query_cpu_definitions(errp); } @@ -33,6 +33,7 @@ Index: new/qmp.c + BlockDriverState *bs = NULL; + BlockDriver *drv = NULL; + int bdrv_oflags = BDRV_O_NOCACHE | BDRV_O_RDWR; ++ int64_t pos; + QEMUFile *f; + int ret; + @@ -69,7 +70,9 @@ Index: new/qmp.c + ret = qemu_savevm_state(f); + + // try to truncate, but ignore errors (will fail on block devices). -+ bdrv_truncate(bs, qemu_ftell(f)); ++ // note: bdrv_read() need whole blocks, so we round up ++ pos = qemu_ftell(f); ++ bdrv_truncate(bs, (pos + BDRV_SECTOR_SIZE) & BDRV_SECTOR_MASK); + + qemu_fclose(f); + @@ -215,8 +218,8 @@ Index: new/qmp.c +} Index: new/qmp-commands.hx =================================================================== ---- new.orig/qmp-commands.hx 2012-09-18 06:20:41.000000000 +0200 -+++ new/qmp-commands.hx 2012-09-18 08:43:25.000000000 +0200 +--- new.orig/qmp-commands.hx 2012-09-19 12:46:53.000000000 +0200 ++++ new/qmp-commands.hx 2012-09-19 12:51:10.000000000 +0200 @@ -2514,3 +2514,27 @@ .args_type = "", .mhandler.cmd_new = qmp_marshal_input_query_target, @@ -247,8 +250,8 @@ Index: new/qmp-commands.hx + }, Index: new/hmp.c =================================================================== ---- new.orig/hmp.c 2012-09-18 06:20:41.000000000 +0200 -+++ new/hmp.c 2012-09-18 08:43:25.000000000 +0200 +--- new.orig/hmp.c 2012-09-19 12:46:53.000000000 +0200 ++++ new/hmp.c 2012-09-19 12:51:10.000000000 +0200 @@ -1102,3 +1102,40 @@ qmp_closefd(fdname, &errp); hmp_handle_error(mon, &errp); @@ -292,8 +295,8 @@ Index: new/hmp.c +} Index: new/hmp.h =================================================================== ---- new.orig/hmp.h 2012-09-18 06:20:41.000000000 +0200 -+++ new/hmp.h 2012-09-18 08:43:25.000000000 +0200 +--- new.orig/hmp.h 2012-09-19 12:46:53.000000000 +0200 ++++ new/hmp.h 2012-09-19 12:51:10.000000000 +0200 @@ -71,5 +71,9 @@ void hmp_netdev_del(Monitor *mon, const QDict *qdict); void hmp_getfd(Monitor *mon, const QDict *qdict); @@ -306,8 +309,8 @@ Index: new/hmp.h #endif Index: new/hmp-commands.hx =================================================================== ---- new.orig/hmp-commands.hx 2012-09-18 06:20:41.000000000 +0200 -+++ new/hmp-commands.hx 2012-09-18 08:43:25.000000000 +0200 +--- new.orig/hmp-commands.hx 2012-09-19 12:46:53.000000000 +0200 ++++ new/hmp-commands.hx 2012-09-19 12:51:10.000000000 +0200 @@ -1494,3 +1494,35 @@ STEXI @end table @@ -346,8 +349,8 @@ Index: new/hmp-commands.hx + }, Index: new/sysemu.h =================================================================== ---- new.orig/sysemu.h 2012-09-18 07:35:53.000000000 +0200 -+++ new/sysemu.h 2012-09-18 08:43:25.000000000 +0200 +--- new.orig/sysemu.h 2012-09-19 12:46:53.000000000 +0200 ++++ new/sysemu.h 2012-09-19 12:51:10.000000000 +0200 @@ -84,6 +84,7 @@ int qemu_savevm_state_iterate(QEMUFile *f); int qemu_savevm_state_complete(QEMUFile *f); @@ -358,9 +361,9 @@ Index: new/sysemu.h /* SLIRP */ Index: new/savevm.c =================================================================== ---- new.orig/savevm.c 2012-09-18 08:53:28.000000000 +0200 -+++ new/savevm.c 2012-09-18 08:53:55.000000000 +0200 -@@ -1743,7 +1743,7 @@ +--- new.orig/savevm.c 2012-09-19 12:51:07.000000000 +0200 ++++ new/savevm.c 2012-09-19 12:51:10.000000000 +0200 +@@ -1754,7 +1754,7 @@ } } diff --git a/debian/patches/load-state-from-blockdev.patch b/debian/patches/load-state-from-blockdev.patch index 1c00c6c..66a4c8f 100644 --- a/debian/patches/load-state-from-blockdev.patch +++ b/debian/patches/load-state-from-blockdev.patch @@ -1,8 +1,26 @@ Index: new/savevm.c =================================================================== ---- new.orig/savevm.c 2012-09-18 07:20:45.000000000 +0200 -+++ new/savevm.c 2012-09-18 07:36:55.000000000 +0200 -@@ -2223,6 +2223,50 @@ +--- new.orig/savevm.c 2012-09-19 07:17:28.000000000 +0200 ++++ new/savevm.c 2012-09-19 12:53:58.000000000 +0200 +@@ -407,6 +407,17 @@ + + static int block_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size) + { ++ int ret; ++ int64_t maxlen = bdrv_getlength(opaque); ++ if (pos > maxlen) { ++ return -EIO; ++ } ++ if ((pos + size) > maxlen) { ++ size = maxlen - pos - 1; ++ } ++ if (size == 0) { ++ return 0; ++ } + return bdrv_pread(opaque, pos, buf, size); + } + +@@ -2223,6 +2234,50 @@ return; } @@ -55,8 +73,8 @@ Index: new/savevm.c BlockDriverState *bs, *bs_vm_state; Index: new/sysemu.h =================================================================== ---- new.orig/sysemu.h 2012-09-18 07:35:26.000000000 +0200 -+++ new/sysemu.h 2012-09-18 07:35:53.000000000 +0200 +--- new.orig/sysemu.h 2012-09-19 07:17:21.000000000 +0200 ++++ new/sysemu.h 2012-09-19 12:53:31.000000000 +0200 @@ -72,6 +72,7 @@ void do_savevm(Monitor *mon, const QDict *qdict); @@ -67,8 +85,8 @@ Index: new/sysemu.h Index: new/qemu-options.hx =================================================================== ---- new.orig/qemu-options.hx 2012-09-18 07:39:54.000000000 +0200 -+++ new/qemu-options.hx 2012-09-18 07:52:56.000000000 +0200 +--- new.orig/qemu-options.hx 2012-09-19 07:17:28.000000000 +0200 ++++ new/qemu-options.hx 2012-09-19 07:17:28.000000000 +0200 @@ -2477,6 +2477,19 @@ Start right away with a saved state (@code{loadvm} in monitor) ETEXI @@ -91,8 +109,8 @@ Index: new/qemu-options.hx "-daemonize daemonize QEMU after initializing\n", QEMU_ARCH_ALL) Index: new/vl.c =================================================================== ---- new.orig/vl.c 2012-09-18 07:53:19.000000000 +0200 -+++ new/vl.c 2012-09-18 07:55:47.000000000 +0200 +--- new.orig/vl.c 2012-09-19 07:17:28.000000000 +0200 ++++ new/vl.c 2012-09-19 07:17:28.000000000 +0200 @@ -2364,6 +2364,7 @@ int optind; const char *optarg; diff --git a/debian/patches/move-bdrv-snapshot-find.patch b/debian/patches/move-bdrv-snapshot-find.patch index 3f411e8..371a60e 100644 --- a/debian/patches/move-bdrv-snapshot-find.patch +++ b/debian/patches/move-bdrv-snapshot-find.patch @@ -1,7 +1,7 @@ Index: new/block.c =================================================================== ---- new.orig/block.c 2012-09-18 08:38:03.000000000 +0200 -+++ new/block.c 2012-09-18 08:39:00.000000000 +0200 +--- new.orig/block.c 2012-09-19 12:47:55.000000000 +0200 ++++ new/block.c 2012-09-19 12:51:07.000000000 +0200 @@ -2724,6 +2724,28 @@ return -ENOTSUP; } @@ -33,8 +33,8 @@ Index: new/block.c { Index: new/block.h =================================================================== ---- new.orig/block.h 2012-09-18 08:38:03.000000000 +0200 -+++ new/block.h 2012-09-18 08:39:42.000000000 +0200 +--- new.orig/block.h 2012-09-19 12:46:56.000000000 +0200 ++++ new/block.h 2012-09-19 12:51:07.000000000 +0200 @@ -302,6 +302,8 @@ int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id); int bdrv_snapshot_list(BlockDriverState *bs, @@ -46,9 +46,9 @@ Index: new/block.h char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn); Index: new/savevm.c =================================================================== ---- new.orig/savevm.c 2012-09-18 08:38:03.000000000 +0200 -+++ new/savevm.c 2012-09-18 08:39:05.000000000 +0200 -@@ -2034,28 +2034,6 @@ +--- new.orig/savevm.c 2012-09-19 12:50:39.000000000 +0200 ++++ new/savevm.c 2012-09-19 12:51:07.000000000 +0200 +@@ -2045,28 +2045,6 @@ return ret; } -- 2.39.2