1 From 46fd4bb673a91d40352c95e9d3f62f63b5021053 Mon Sep 17 00:00:00 2001
2 From: Stefan Priebe <s.priebe@profihost.ag>
3 Date: Fri, 29 Nov 2013 22:17:03 +0100
4 Subject: [PATCH] internal-snapshot-async-qemu1.7.patch
9 hmp-commands.hx | 34 ++++
12 include/block/block.h | 1 +
13 include/sysemu/sysemu.h | 5 +-
15 qapi-schema.json | 46 +++++
16 qemu-options.hx | 13 ++
17 qmp-commands.hx | 31 +++
18 savevm-async.c | 478 +++++++++++++++++++++++++++++++++++++++++++++++
21 14 files changed, 692 insertions(+), 7 deletions(-)
22 create mode 100644 savevm-async.c
24 Index: new/Makefile.objs
25 ===================================================================
26 --- new.orig/Makefile.objs 2014-05-05 09:49:29.000000000 +0200
27 +++ new/Makefile.objs 2014-05-05 09:54:17.000000000 +0200
29 common-obj-y += qemu-char.o #aio.o
30 common-obj-y += block-migration.o
31 common-obj-y += page_cache.o xbzrle.o
32 +common-obj-y += savevm-async.o
34 common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
37 ===================================================================
38 --- new.orig/block.c 2014-05-05 09:49:29.000000000 +0200
39 +++ new/block.c 2014-05-05 09:54:17.000000000 +0200
41 bs_new->drv ? bs_new->drv->format_name : "");
44 -static void bdrv_delete(BlockDriverState *bs)
45 +void bdrv_delete(BlockDriverState *bs)
49 Index: new/hmp-commands.hx
50 ===================================================================
51 --- new.orig/hmp-commands.hx 2014-05-05 09:49:29.000000000 +0200
52 +++ new/hmp-commands.hx 2014-05-05 09:54:17.000000000 +0200
54 show current migration capabilities
55 @item info migrate_cache_size
56 show current migration XBZRLE cache size
60 show balloon information
62 @@ -1798,3 +1800,35 @@
68 + .name = "savevm-start",
69 + .args_type = "statefile:s?",
70 + .params = "[statefile]",
71 + .help = "Prepare for snapshot and halt VM. Save VM state to statefile.",
72 + .mhandler.cmd = hmp_savevm_start,
76 + .name = "snapshot-drive",
77 + .args_type = "device:s,name:s",
78 + .params = "device name",
79 + .help = "Create internal snapshot.",
80 + .mhandler.cmd = hmp_snapshot_drive,
84 + .name = "delete-drive-snapshot",
85 + .args_type = "device:s,name:s",
86 + .params = "device name",
87 + .help = "Delete internal snapshot.",
88 + .mhandler.cmd = hmp_delete_drive_snapshot,
92 + .name = "savevm-end",
95 + .help = "Resume VM after snaphot.",
96 + .mhandler.cmd = hmp_savevm_end,
99 ===================================================================
100 --- new.orig/hmp.c 2014-05-05 09:49:29.000000000 +0200
101 +++ new/hmp.c 2014-05-05 09:54:17.000000000 +0200
102 @@ -1738,3 +1738,60 @@
103 qmp_object_del(id, &err);
104 hmp_handle_error(mon, &err);
107 +void hmp_savevm_start(Monitor *mon, const QDict *qdict)
109 + Error *errp = NULL;
110 + const char *statefile = qdict_get_try_str(qdict, "statefile");
112 + qmp_savevm_start(statefile != NULL, statefile, &errp);
113 + hmp_handle_error(mon, &errp);
116 +void hmp_snapshot_drive(Monitor *mon, const QDict *qdict)
118 + Error *errp = NULL;
119 + const char *name = qdict_get_str(qdict, "name");
120 + const char *device = qdict_get_str(qdict, "device");
122 + qmp_snapshot_drive(device, name, &errp);
123 + hmp_handle_error(mon, &errp);
126 +void hmp_delete_drive_snapshot(Monitor *mon, const QDict *qdict)
128 + Error *errp = NULL;
129 + const char *name = qdict_get_str(qdict, "name");
130 + const char *device = qdict_get_str(qdict, "device");
132 + qmp_delete_drive_snapshot(device, name, &errp);
133 + hmp_handle_error(mon, &errp);
136 +void hmp_savevm_end(Monitor *mon, const QDict *qdict)
138 + Error *errp = NULL;
140 + qmp_savevm_end(&errp);
141 + hmp_handle_error(mon, &errp);
144 +void hmp_info_savevm(Monitor *mon, const QDict *qdict)
147 + info = qmp_query_savevm(NULL);
149 + if (info->has_status) {
150 + monitor_printf(mon, "savevm status: %s\n", info->status);
151 + monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
154 + monitor_printf(mon, "savevm status: not running\n");
156 + if (info->has_bytes) {
157 + monitor_printf(mon, "Bytes saved: %"PRIu64"\n", info->bytes);
159 + if (info->has_error) {
160 + monitor_printf(mon, "Error: %s\n", info->error);
164 ===================================================================
165 --- new.orig/hmp.h 2014-05-05 09:49:29.000000000 +0200
166 +++ new/hmp.h 2014-05-05 09:54:17.000000000 +0200
168 void hmp_info_uuid(Monitor *mon, const QDict *qdict);
169 void hmp_info_chardev(Monitor *mon, const QDict *qdict);
170 void hmp_info_mice(Monitor *mon, const QDict *qdict);
171 +void hmp_info_savevm(Monitor *mon, const QDict *qdict);
172 void hmp_info_migrate(Monitor *mon, const QDict *qdict);
173 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict);
174 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict);
176 void hmp_netdev_del(Monitor *mon, const QDict *qdict);
177 void hmp_getfd(Monitor *mon, const QDict *qdict);
178 void hmp_closefd(Monitor *mon, const QDict *qdict);
179 +void hmp_savevm_start(Monitor *mon, const QDict *qdict);
180 +void hmp_snapshot_drive(Monitor *mon, const QDict *qdict);
181 +void hmp_delete_drive_snapshot(Monitor *mon, const QDict *qdict);
182 +void hmp_savevm_end(Monitor *mon, const QDict *qdict);
183 void hmp_send_key(Monitor *mon, const QDict *qdict);
184 void hmp_screen_dump(Monitor *mon, const QDict *qdict);
185 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict);
186 Index: new/include/block/block.h
187 ===================================================================
188 --- new.orig/include/block/block.h 2014-05-05 09:49:29.000000000 +0200
189 +++ new/include/block/block.h 2014-05-05 09:54:17.000000000 +0200
191 const char *backing_file);
192 int bdrv_get_backing_file_depth(BlockDriverState *bs);
193 int bdrv_truncate(BlockDriverState *bs, int64_t offset);
194 +void bdrv_delete(BlockDriverState *bs);
195 int64_t bdrv_getlength(BlockDriverState *bs);
196 int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);
197 void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
198 Index: new/include/sysemu/sysemu.h
199 ===================================================================
200 --- new.orig/include/sysemu/sysemu.h 2014-05-05 09:49:29.000000000 +0200
201 +++ new/include/sysemu/sysemu.h 2014-05-05 09:54:17.000000000 +0200
204 void do_savevm(Monitor *mon, const QDict *qdict);
205 int load_vmstate(const char *name);
206 +int load_state_from_blockdev(const char *filename);
207 void do_delvm(Monitor *mon, const QDict *qdict);
208 void do_info_snapshots(Monitor *mon, const QDict *qdict);
210 void qemu_announce_self(void);
212 bool qemu_savevm_state_blocked(Error **errp);
213 -void qemu_savevm_state_begin(QEMUFile *f,
214 +int qemu_savevm_state_begin(QEMUFile *f,
215 const MigrationParams *params);
216 int qemu_savevm_state_iterate(QEMUFile *f);
217 -void qemu_savevm_state_complete(QEMUFile *f);
218 +int qemu_savevm_state_complete(QEMUFile *f);
219 void qemu_savevm_state_cancel(void);
220 uint64_t qemu_savevm_state_pending(QEMUFile *f, uint64_t max_size);
221 int qemu_loadvm_state(QEMUFile *f);
223 ===================================================================
224 --- new.orig/monitor.c 2014-05-05 09:49:29.000000000 +0200
225 +++ new/monitor.c 2014-05-05 09:54:17.000000000 +0200
226 @@ -2931,6 +2931,13 @@
227 .mhandler.cmd = hmp_info_migrate_cache_size,
233 + .help = "show savevm status",
234 + .mhandler.cmd = hmp_info_savevm,
240 Index: new/qapi-schema.json
241 ===================================================================
242 --- new.orig/qapi-schema.json 2014-05-05 09:49:29.000000000 +0200
243 +++ new/qapi-schema.json 2014-05-05 09:54:17.000000000 +0200
246 '*setup-time': 'int'} }
251 +# Information about current migration process.
253 +# @status: #optional string describing the current savevm status.
254 +# This can be 'active', 'completed', 'failed'.
255 +# If this field is not returned, no savevm process
256 +# has been initiated
258 +# @error: #optional string containing error message is status is failed.
260 +# @total-time: #optional total amount of milliseconds since savevm started.
261 +# If savevm has ended, it returns the total save time
263 +# @bytes: #optional total amount of data transfered
267 +{ 'type': 'SaveVMInfo',
268 + 'data': {'*status': 'str', '*error': 'str',
269 + '*total-time': 'int', '*bytes': 'int'} }
274 +# Returns information about current savevm process.
276 +# Returns: @SaveVMInfo
280 +{ 'command': 'query-savevm', 'returns': 'SaveVMInfo' }
287 @@ -3687,8 +3723,18 @@
292 { 'command': 'query-target', 'returns': 'TargetInfo' }
294 +{ 'command': 'savevm-start', 'data': { '*statefile': 'str' } }
296 +{ 'command': 'snapshot-drive', 'data': { 'device': 'str', 'name': 'str' } }
298 +{ 'command': 'delete-drive-snapshot', 'data': { 'device': 'str', 'name': 'str' } }
300 +{ 'command': 'savevm-end' }
306 Index: new/qemu-options.hx
307 ===================================================================
308 --- new.orig/qemu-options.hx 2014-05-05 09:49:29.000000000 +0200
309 +++ new/qemu-options.hx 2014-05-05 09:54:17.000000000 +0200
310 @@ -2759,6 +2759,19 @@
311 Start right away with a saved state (@code{loadvm} in monitor)
314 +DEF("loadstate", HAS_ARG, QEMU_OPTION_loadstate, \
315 + "-loadstate file\n" \
316 + " start right away with a saved state\n",
319 +@item -loadstate @var{file}
321 +Start right away with a saved state. This option does not rollback
322 +disk state like @code{loadvm}, so user must make sure that disk
323 +have correct state. @var{file} can be any valid device URL. See the section
324 +for "Device URL Syntax" for more information.
328 DEF("daemonize", 0, QEMU_OPTION_daemonize, \
329 "-daemonize daemonize QEMU after initializing\n", QEMU_ARCH_ALL)
330 Index: new/qmp-commands.hx
331 ===================================================================
332 --- new.orig/qmp-commands.hx 2014-05-05 09:49:29.000000000 +0200
333 +++ new/qmp-commands.hx 2014-05-05 09:54:17.000000000 +0200
334 @@ -3593,3 +3593,34 @@
341 + .name = "savevm-start",
342 + .args_type = "statefile:s?",
343 + .mhandler.cmd_new = qmp_marshal_input_savevm_start,
347 + .name = "snapshot-drive",
348 + .args_type = "device:s,name:s",
349 + .mhandler.cmd_new = qmp_marshal_input_snapshot_drive,
353 + .name = "delete-drive-snapshot",
354 + .args_type = "device:s,name:s",
355 + .mhandler.cmd_new = qmp_marshal_input_delete_drive_snapshot,
359 + .name = "savevm-end",
361 + .mhandler.cmd_new = qmp_marshal_input_savevm_end,
365 + .name = "query-savevm",
367 + .mhandler.cmd_new = qmp_marshal_input_query_savevm,
369 Index: new/savevm-async.c
370 ===================================================================
371 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
372 +++ new/savevm-async.c 2014-05-05 09:55:53.000000000 +0200
374 +#include "qemu-common.h"
375 +#include "qapi/qmp/qerror.h"
376 +#include "sysemu/sysemu.h"
377 +#include "qmp-commands.h"
378 +#include "qemu-options.h"
379 +#include "migration/qemu-file.h"
380 +#include "qom/qom-qobject.h"
381 +#include "migration/migration.h"
382 +#include "block/snapshot.h"
383 +#include "block/qapi.h"
384 +#include "block/block.h"
385 +#include "qemu/timer.h"
387 +/* #define DEBUG_SAVEVM_STATE */
389 +#ifdef DEBUG_SAVEVM_STATE
390 +#define DPRINTF(fmt, ...) \
391 + do { printf("savevm-async: " fmt, ## __VA_ARGS__); } while (0)
393 +#define DPRINTF(fmt, ...) \
401 + SAVE_STATE_COMPLETED,
405 +static struct SnapshotState {
406 + BlockDriverState *bs;
410 + int saved_vm_running;
412 + int64_t total_time;
415 +SaveVMInfo *qmp_query_savevm(Error **errp)
417 + SaveVMInfo *info = g_malloc0(sizeof(*info));
418 + struct SnapshotState *s = &snap_state;
420 + if (s->state != SAVE_STATE_DONE) {
421 + info->has_bytes = true;
422 + info->bytes = s->bs_pos;
423 + switch (s->state) {
424 + case SAVE_STATE_ERROR:
425 + info->has_status = true;
426 + info->status = g_strdup("failed");
427 + info->has_total_time = true;
428 + info->total_time = s->total_time;
430 + info->has_error = true;
431 + info->error = g_strdup(error_get_pretty(s->error));
434 + case SAVE_STATE_ACTIVE:
435 + info->has_status = true;
436 + info->status = g_strdup("active");
437 + info->has_total_time = true;
438 + info->total_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME)
441 + case SAVE_STATE_COMPLETED:
442 + info->has_status = true;
443 + info->status = g_strdup("completed");
444 + info->has_total_time = true;
445 + info->total_time = s->total_time;
453 +static int save_snapshot_cleanup(void)
457 + DPRINTF("save_snapshot_cleanup\n");
459 + snap_state.total_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME) -
460 + snap_state.total_time;
462 + if (snap_state.file) {
463 + ret = qemu_fclose(snap_state.file);
466 + if (snap_state.bs) {
467 + /* try to truncate, but ignore errors (will fail on block devices).
468 + * note: bdrv_read() need whole blocks, so we round up
470 + size_t size = (snap_state.bs_pos + BDRV_SECTOR_SIZE) & BDRV_SECTOR_MASK;
471 + bdrv_truncate(snap_state.bs, size);
472 + bdrv_set_in_use(snap_state.bs, 0);
473 + bdrv_unref(snap_state.bs);
474 + snap_state.bs = NULL;
480 +static void save_snapshot_error(const char *fmt, ...)
486 + msg = g_strdup_vprintf(fmt, ap);
489 + DPRINTF("save_snapshot_error: %s\n", msg);
491 + if (!snap_state.error) {
492 + error_set(&snap_state.error, ERROR_CLASS_GENERIC_ERROR, "%s", msg);
497 + snap_state.state = SAVE_STATE_ERROR;
499 + save_snapshot_cleanup();
502 +static void save_snapshot_completed(void)
504 + DPRINTF("save_snapshot_completed\n");
506 + if (save_snapshot_cleanup() < 0) {
507 + snap_state.state = SAVE_STATE_ERROR;
509 + snap_state.state = SAVE_STATE_COMPLETED;
513 +static int block_state_close(void *opaque)
515 + snap_state.file = NULL;
516 + return bdrv_flush(snap_state.bs);
519 +static int block_state_put_buffer(void *opaque, const uint8_t *buf,
520 + int64_t pos, int size)
524 + assert(pos == snap_state.bs_pos);
526 + if ((ret = bdrv_pwrite(snap_state.bs, snap_state.bs_pos, buf, size)) > 0) {
527 + snap_state.bs_pos += ret;
533 +static void process_savevm_co(void *opaque)
537 + MigrationParams params = {
542 + snap_state.state = SAVE_STATE_ACTIVE;
544 + qemu_mutex_unlock_iothread();
545 + ret = qemu_savevm_state_begin(snap_state.file, ¶ms);
546 + qemu_mutex_lock_iothread();
549 + save_snapshot_error("qemu_savevm_state_begin failed");
553 + while (snap_state.state == SAVE_STATE_ACTIVE) {
554 + uint64_t pending_size;
556 + pending_size = qemu_savevm_state_pending(snap_state.file, 0);
558 + if (pending_size) {
559 + ret = qemu_savevm_state_iterate(snap_state.file);
561 + save_snapshot_error("qemu_savevm_state_iterate error %d", ret);
564 + DPRINTF("savevm inerate pending size %lu ret %d\n", pending_size, ret);
566 + DPRINTF("done iterating\n");
567 + if (runstate_is_running()) {
568 + vm_stop(RUN_STATE_SAVE_VM);
570 + DPRINTF("savevm inerate finished\n");
571 + qemu_savevm_state_complete(snap_state.file);
572 + DPRINTF("save complete\n");
573 + save_snapshot_completed();
577 + /* stop the VM if we get to the end of available space,
578 + * or if pending_size is just a few MB
580 + maxlen = bdrv_getlength(snap_state.bs) - 30*1024*1024;
581 + if ((pending_size < 100000) ||
582 + ((snap_state.bs_pos + pending_size) >= maxlen)) {
583 + if (runstate_is_running()) {
584 + vm_stop(RUN_STATE_SAVE_VM);
590 +static const QEMUFileOps block_file_ops = {
591 + .put_buffer = block_state_put_buffer,
592 + .close = block_state_close,
596 +void qmp_savevm_start(bool has_statefile, const char *statefile, Error **errp)
598 + BlockDriver *drv = NULL;
599 + Error *local_err = NULL;
601 + int bdrv_oflags = BDRV_O_CACHE_WB | BDRV_O_RDWR;
604 + if (snap_state.state != SAVE_STATE_DONE) {
605 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
606 + "VM snapshot already started\n");
610 + /* initialize snapshot info */
611 + snap_state.saved_vm_running = runstate_is_running();
612 + snap_state.bs_pos = 0;
613 + snap_state.total_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
615 + if (snap_state.error) {
616 + error_free(snap_state.error);
617 + snap_state.error = NULL;
620 + if (!has_statefile) {
621 + vm_stop(RUN_STATE_SAVE_VM);
622 + snap_state.state = SAVE_STATE_COMPLETED;
626 + if (qemu_savevm_state_blocked(errp)) {
630 + /* Open the image */
631 + snap_state.bs = bdrv_new("vmstate");
632 + ret = bdrv_open(&snap_state.bs, statefile, NULL, NULL, bdrv_oflags, drv, &local_err);
635 + error_set(errp, ERROR_CLASS_GENERIC_ERROR, "failed to open '%s'", statefile);
639 + snap_state.file = qemu_fopen_ops(&snap_state, &block_file_ops);
641 + if (!snap_state.file) {
642 + error_set(errp, ERROR_CLASS_GENERIC_ERROR, "failed to open '%s'", statefile);
647 + bdrv_set_in_use(snap_state.bs, 1);
648 + bdrv_ref(snap_state.bs);
650 + Coroutine *co = qemu_coroutine_create(process_savevm_co);
651 + qemu_coroutine_enter(co, NULL);
657 + save_snapshot_error("setup failed");
659 + if (snap_state.saved_vm_running) {
664 +void qmp_savevm_end(Error **errp)
666 + if (snap_state.state == SAVE_STATE_DONE) {
667 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
668 + "VM snapshot not started\n");
672 + if (snap_state.saved_vm_running) {
676 + snap_state.state = SAVE_STATE_DONE;
679 +void qmp_snapshot_drive(const char *device, const char *name, Error **errp)
681 + BlockDriverState *bs;
682 + QEMUSnapshotInfo sn1, *sn = &sn1;
690 + if (snap_state.state != SAVE_STATE_COMPLETED) {
691 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
692 + "VM snapshot not ready/started\n");
696 + bs = bdrv_find(device);
698 + error_set(errp, QERR_DEVICE_NOT_FOUND, device);
702 + if (!bdrv_is_inserted(bs)) {
703 + error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
707 + if (bdrv_is_read_only(bs)) {
708 + error_set(errp, QERR_DEVICE_IS_READ_ONLY, device);
712 + if (!bdrv_can_snapshot(bs)) {
713 + error_set(errp, QERR_NOT_SUPPORTED);
717 + if (bdrv_snapshot_find(bs, sn, name) >= 0) {
718 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
719 + "snapshot '%s' already exists", name);
724 + memset(sn, 0, sizeof(*sn));
728 + sn->date_sec = tb.time;
729 + sn->date_nsec = tb.millitm * 1000000;
731 + gettimeofday(&tv, NULL);
732 + sn->date_sec = tv.tv_sec;
733 + sn->date_nsec = tv.tv_usec * 1000;
735 + sn->vm_clock_nsec = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
737 + pstrcpy(sn->name, sizeof(sn->name), name);
739 + sn->vm_state_size = 0; /* do not save state */
741 + ret = bdrv_snapshot_create(bs, sn);
743 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
744 + "Error while creating snapshot on '%s'\n", device);
749 +void qmp_delete_drive_snapshot(const char *device, const char *name,
752 + BlockDriverState *bs;
753 + QEMUSnapshotInfo sn1, *sn = &sn1;
754 + Error *local_err = NULL;
758 + bs = bdrv_find(device);
760 + error_set(errp, QERR_DEVICE_NOT_FOUND, device);
763 + if (bdrv_is_read_only(bs)) {
764 + error_set(errp, QERR_DEVICE_IS_READ_ONLY, device);
768 + if (!bdrv_can_snapshot(bs)) {
769 + error_set(errp, QERR_NOT_SUPPORTED);
773 + if (bdrv_snapshot_find(bs, sn, name) < 0) {
774 + /* return success if snapshot does not exists */
778 + ret = bdrv_snapshot_delete(bs, NULL, name, &local_err);
780 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
781 + "Error while deleting snapshot on '%s'\n", device);
786 +static int loadstate_get_buffer(void *opaque, uint8_t *buf, int64_t pos,
789 + BlockDriverState *bs = (BlockDriverState *)opaque;
790 + int64_t maxlen = bdrv_getlength(bs);
791 + if (pos > maxlen) {
794 + if ((pos + size) > maxlen) {
795 + size = maxlen - pos - 1;
800 + return bdrv_pread(bs, pos, buf, size);
803 +static const QEMUFileOps loadstate_file_ops = {
804 + .get_buffer = loadstate_get_buffer,
807 +int load_state_from_blockdev(const char *filename)
809 + BlockDriverState *bs = NULL;
810 + BlockDriver *drv = NULL;
811 + Error *local_err = NULL;
816 + bs = bdrv_new("vmstate");
817 + ret = bdrv_open(&bs, filename, NULL, NULL, BDRV_O_CACHE_WB, drv, &local_err);
818 + bdrv_set_in_use(bs, 1);
822 + error_report("Could not open VM state file");
826 + /* restore the VM state */
827 + f = qemu_fopen_ops(bs, &loadstate_file_ops);
829 + error_report("Could not open VM state file");
834 + qemu_system_reset(VMRESET_SILENT);
835 + ret = qemu_loadvm_state(f);
839 + error_report("Error %d while loading VM state", ret);
847 + bdrv_set_in_use(bs, 0);
853 ===================================================================
854 --- new.orig/savevm.c 2014-05-05 09:49:29.000000000 +0200
855 +++ new/savevm.c 2014-05-05 09:54:17.000000000 +0200
856 @@ -460,11 +460,11 @@
860 -void qemu_savevm_state_begin(QEMUFile *f,
861 +int qemu_savevm_state_begin(QEMUFile *f,
862 const MigrationParams *params)
868 trace_savevm_state_begin();
869 QTAILQ_FOREACH(se, &savevm_handlers, entry) {
882 -void qemu_savevm_state_complete(QEMUFile *f)
883 +int qemu_savevm_state_complete(QEMUFile *f)
888 trace_savevm_section_end(se->idstr, se->section_id);
890 qemu_file_set_error(f, ret);
898 qemu_put_byte(f, QEMU_VM_EOF);
900 + return qemu_file_get_error(f);
903 uint64_t qemu_savevm_state_pending(QEMUFile *f, uint64_t max_size)
905 ===================================================================
906 --- new.orig/vl.c 2014-05-05 09:49:29.000000000 +0200
907 +++ new/vl.c 2014-05-05 09:54:17.000000000 +0200
908 @@ -2953,6 +2953,7 @@
911 const char *loadvm = NULL;
912 + const char *loadstate = NULL;
913 MachineClass *machine_class;
914 QEMUMachine *machine;
915 const char *cpu_model;
916 @@ -3574,6 +3575,9 @@
917 case QEMU_OPTION_loadvm:
920 + case QEMU_OPTION_loadstate:
921 + loadstate = optarg;
923 case QEMU_OPTION_full_screen:
926 @@ -4541,6 +4545,10 @@
927 if (load_vmstate(loadvm) < 0) {
930 + } else if (loadstate) {
931 + if (load_state_from_blockdev(loadstate) < 0) {