Index: new/qapi-schema.json
===================================================================
---- new.orig/qapi-schema.json 2012-09-04 12:52:21.000000000 +0200
-+++ new/qapi-schema.json 2012-09-06 11:26:26.000000000 +0200
+--- new.orig/qapi-schema.json 2012-09-07 07:41:45.000000000 +0200
++++ new/qapi-schema.json 2012-09-13 09:22:06.000000000 +0200
@@ -2493,3 +2493,12 @@
# Since: 1.2.0
##
+{ 'command': 'snapshot-end' }
Index: new/qmp.c
===================================================================
---- new.orig/qmp.c 2012-09-04 12:52:21.000000000 +0200
-+++ new/qmp.c 2012-09-06 11:28:14.000000000 +0200
-@@ -479,3 +479,191 @@
+--- new.orig/qmp.c 2012-09-07 07:41:45.000000000 +0200
++++ new/qmp.c 2012-09-14 14:06:56.000000000 +0200
+@@ -479,3 +479,224 @@
return arch_query_cpu_definitions(errp);
}
+ int saved_vm_running;
+} snap_state;
+
++static int block_put_buffer(void *opaque, const uint8_t *buf,
++ int64_t pos, int size)
++{
++ bdrv_pwrite(opaque, pos, buf, size);
++ return size;
++}
++
++static int bdrv_fclose(void *opaque)
++{
++ return bdrv_flush(opaque);
++}
++
+void qmp_snapshot_start(bool has_statefile, const char *statefile, Error **errp)
+{
++ BlockDriverState *bs = NULL;
++ BlockDriver *drv = NULL;
++ int bdrv_oflags = BDRV_O_NOCACHE | BDRV_O_RDWR;
+ QEMUFile *f;
+ int ret;
+
+ if (!has_statefile)
+ return;
+
-+ f = qemu_fopen(statefile, "wb");
++ /* Open the image */
++ bs = bdrv_new("vmstate");
++ ret = bdrv_open(bs, statefile, bdrv_oflags, drv);
++ if (ret < 0) {
++ error_set(errp, QERR_OPEN_FILE_FAILED, statefile);
++ goto restart;
++ }
++
++ f = qemu_fopen_ops(bs, block_put_buffer, NULL, bdrv_fclose,
++ NULL, NULL, NULL);
+ if (!f) {
+ error_set(errp, QERR_OPEN_FILE_FAILED, statefile);
+ goto restart;
+ }
+
+ ret = qemu_savevm_state(f);
++
++ bdrv_truncate(bs, qemu_ftell(f)); // ignore errors
++
+ qemu_fclose(f);
++
+ if (ret < 0) {
+ error_set(errp, ERROR_CLASS_GENERIC_ERROR,
+ "Error %d while writing VM state\n", ret);
-+ goto restart;
++ goto restart;
+ }
++end:
++ if (bs)
++ bdrv_delete(bs);
+
+ return;
+
+ if (snap_state.saved_vm_running) {
+ vm_start();
+ }
++
++ goto end;
+}
+
+void qmp_snapshot_end(Error **errp)
+}
Index: new/qmp-commands.hx
===================================================================
---- new.orig/qmp-commands.hx 2012-09-04 12:52:21.000000000 +0200
-+++ new/qmp-commands.hx 2012-09-06 11:13:10.000000000 +0200
+--- new.orig/qmp-commands.hx 2012-09-07 07:41:45.000000000 +0200
++++ new/qmp-commands.hx 2012-09-13 09:30:33.000000000 +0200
@@ -2514,3 +2514,27 @@
.args_type = "",
.mhandler.cmd_new = qmp_marshal_input_query_target,
+
+ {
+ .name = "snapshot-start",
-+ .args_type = "statefile:s",
++ .args_type = "statefile:s?",
+ .mhandler.cmd_new = qmp_marshal_input_snapshot_start,
+ },
+
+ },
Index: new/hmp.c
===================================================================
---- new.orig/hmp.c 2012-09-04 12:52:21.000000000 +0200
-+++ new/hmp.c 2012-09-06 11:30:32.000000000 +0200
+--- new.orig/hmp.c 2012-09-07 07:41:45.000000000 +0200
++++ new/hmp.c 2012-09-13 09:22:06.000000000 +0200
@@ -1102,3 +1102,40 @@
qmp_closefd(fdname, &errp);
hmp_handle_error(mon, &errp);
+}
Index: new/hmp.h
===================================================================
---- new.orig/hmp.h 2012-09-04 12:52:21.000000000 +0200
-+++ new/hmp.h 2012-09-06 11:14:38.000000000 +0200
+--- new.orig/hmp.h 2012-09-07 07:41:45.000000000 +0200
++++ new/hmp.h 2012-09-13 09:22:06.000000000 +0200
@@ -71,5 +71,9 @@
void hmp_netdev_del(Monitor *mon, const QDict *qdict);
void hmp_getfd(Monitor *mon, const QDict *qdict);
#endif
Index: new/hmp-commands.hx
===================================================================
---- new.orig/hmp-commands.hx 2012-09-04 12:52:21.000000000 +0200
-+++ new/hmp-commands.hx 2012-09-06 11:29:05.000000000 +0200
+--- new.orig/hmp-commands.hx 2012-09-07 07:41:45.000000000 +0200
++++ new/hmp-commands.hx 2012-09-13 09:22:06.000000000 +0200
@@ -1494,3 +1494,35 @@
STEXI
@end table
+ },
Index: new/savevm.c
===================================================================
---- new.orig/savevm.c 2012-09-05 10:27:37.000000000 +0200
-+++ new/savevm.c 2012-09-05 10:27:44.000000000 +0200
+--- new.orig/savevm.c 2012-09-07 07:41:45.000000000 +0200
++++ new/savevm.c 2012-09-14 11:32:17.000000000 +0200
+@@ -404,7 +404,7 @@
+ return bdrv_flush(opaque);
+ }
+
+-static QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int is_writable)
++QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int is_writable)
+ {
+ if (is_writable)
+ return qemu_fopen_ops(bs, block_put_buffer, NULL, bdrv_fclose,
@@ -1724,7 +1724,7 @@
}
}
MigrationParams params = {
Index: new/sysemu.h
===================================================================
---- new.orig/sysemu.h 2012-09-05 10:30:42.000000000 +0200
-+++ new/sysemu.h 2012-09-05 10:30:58.000000000 +0200
+--- new.orig/sysemu.h 2012-09-07 07:41:46.000000000 +0200
++++ new/sysemu.h 2012-09-13 09:22:06.000000000 +0200
@@ -83,6 +83,7 @@
int qemu_savevm_state_iterate(QEMUFile *f);
int qemu_savevm_state_complete(QEMUFile *f);
int qemu_loadvm_state(QEMUFile *f);
/* SLIRP */
+Index: new/qemu-file.h
+===================================================================
+--- new.orig/qemu-file.h 2012-09-14 11:51:31.000000000 +0200
++++ new/qemu-file.h 2012-09-14 11:51:47.000000000 +0200
+@@ -68,6 +68,7 @@
+ QEMUFile *qemu_fopen(const char *filename, const char *mode);
+ QEMUFile *qemu_fdopen(int fd, const char *mode);
+ QEMUFile *qemu_fopen_socket(int fd);
++QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int is_writable);
+ QEMUFile *qemu_popen(FILE *popen_file, const char *mode);
+ QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
+ int qemu_stdio_fd(QEMUFile *f);