]> git.proxmox.com Git - pve-qemu-kvm.git/blob - debian/patches/internal-snapshot-async.patch
correctly add query-savevm qmp command
[pve-qemu-kvm.git] / debian / patches / internal-snapshot-async.patch
1 Index: new/qapi-schema.json
2 ===================================================================
3 --- new.orig/qapi-schema.json 2012-09-24 07:15:44.000000000 +0200
4 +++ new/qapi-schema.json 2012-09-24 07:15:58.000000000 +0200
5 @@ -358,6 +358,40 @@
6 '*total-time': 'int'} }
7
8 ##
9 +# @SaveVMInfo
10 +#
11 +# Information about current migration process.
12 +#
13 +# @status: #optional string describing the current savevm status.
14 +# This can be 'active', 'completed', 'failed'.
15 +# If this field is not returned, no savevm process
16 +# has been initiated
17 +#
18 +# @error: #optional string containing error message is status is failed.
19 +#
20 +# @total-time: #optional total amount of milliseconds since savevm started.
21 +# If savevm has ended, it returns the total save time
22 +#
23 +# @bytes: #optional total amount of data transfered
24 +#
25 +# Since: 1.3
26 +##
27 +{ 'type': 'SaveVMInfo',
28 + 'data': {'*status': 'str', '*error': 'str',
29 + '*total-time': 'int', '*bytes': 'int'} }
30 +
31 +##
32 +# @query-savevm
33 +#
34 +# Returns information about current savevm process.
35 +#
36 +# Returns: @SaveVMInfo
37 +#
38 +# Since: 1.3
39 +##
40 +{ 'command': 'query-savevm', 'returns': 'SaveVMInfo' }
41 +
42 +##
43 # @query-migrate
44 #
45 # Returns information about current migration process.
46 @@ -2493,3 +2527,12 @@
47 # Since: 1.2.0
48 ##
49 { 'command': 'query-target', 'returns': 'TargetInfo' }
50 +
51 +
52 +{ 'command': 'savevm-start' 'data': { '*statefile': 'str' } }
53 +
54 +{ 'command': 'snapshot-drive', 'data': { 'device': 'str', 'name': 'str' } }
55 +
56 +{ 'command': 'delete-drive-snapshot', 'data': { 'device': 'str', 'name': 'str' } }
57 +
58 +{ 'command': 'savevm-end' }
59 Index: new/qmp-commands.hx
60 ===================================================================
61 --- new.orig/qmp-commands.hx 2012-09-24 07:15:44.000000000 +0200
62 +++ new/qmp-commands.hx 2012-09-24 08:58:56.000000000 +0200
63 @@ -2514,3 +2514,34 @@
64 .args_type = "",
65 .mhandler.cmd_new = qmp_marshal_input_query_target,
66 },
67 +
68 + {
69 + .name = "savevm-start",
70 + .args_type = "statefile:s?",
71 + .mhandler.cmd_new = qmp_marshal_input_savevm_start,
72 + },
73 +
74 + {
75 + .name = "snapshot-drive",
76 + .args_type = "device:s,name:s",
77 + .mhandler.cmd_new = qmp_marshal_input_snapshot_drive,
78 + },
79 +
80 + {
81 + .name = "delete-drive-snapshot",
82 + .args_type = "device:s,name:s",
83 + .mhandler.cmd_new = qmp_marshal_input_delete_drive_snapshot,
84 + },
85 +
86 + {
87 + .name = "savevm-end",
88 + .args_type = "",
89 + .mhandler.cmd_new = qmp_marshal_input_savevm_end,
90 + },
91 +
92 + {
93 + .name = "query-savevm",
94 + .args_type = "",
95 + .mhandler.cmd_new = qmp_marshal_input_query_savevm,
96 + },
97 +
98 Index: new/hmp.c
99 ===================================================================
100 --- new.orig/hmp.c 2012-09-24 07:15:44.000000000 +0200
101 +++ new/hmp.c 2012-09-24 07:15:58.000000000 +0200
102 @@ -1102,3 +1102,60 @@
103 qmp_closefd(fdname, &errp);
104 hmp_handle_error(mon, &errp);
105 }
106 +
107 +void hmp_savevm_start(Monitor *mon, const QDict *qdict)
108 +{
109 + Error *errp = NULL;
110 + const char *statefile = qdict_get_try_str(qdict, "statefile");
111 +
112 + qmp_savevm_start(statefile != NULL, statefile, &errp);
113 + hmp_handle_error(mon, &errp);
114 +}
115 +
116 +void hmp_snapshot_drive(Monitor *mon, const QDict *qdict)
117 +{
118 + Error *errp = NULL;
119 + const char *name = qdict_get_str(qdict, "name");
120 + const char *device = qdict_get_str(qdict, "device");
121 +
122 + qmp_snapshot_drive(device, name, &errp);
123 + hmp_handle_error(mon, &errp);
124 +}
125 +
126 +void hmp_delete_drive_snapshot(Monitor *mon, const QDict *qdict)
127 +{
128 + Error *errp = NULL;
129 + const char *name = qdict_get_str(qdict, "name");
130 + const char *device = qdict_get_str(qdict, "device");
131 +
132 + qmp_delete_drive_snapshot(device, name, &errp);
133 + hmp_handle_error(mon, &errp);
134 +}
135 +
136 +void hmp_savevm_end(Monitor *mon, const QDict *qdict)
137 +{
138 + Error *errp = NULL;
139 +
140 + qmp_savevm_end(&errp);
141 + hmp_handle_error(mon, &errp);
142 +}
143 +
144 +void hmp_info_savevm(Monitor *mon)
145 +{
146 + SaveVMInfo *info;
147 + info = qmp_query_savevm(NULL);
148 +
149 + if (info->has_status) {
150 + monitor_printf(mon, "savevm status: %s\n", info->status);
151 + monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
152 + info->total_time);
153 + } else {
154 + monitor_printf(mon, "savevm status: not running\n");
155 + }
156 + if (info->has_bytes) {
157 + monitor_printf(mon, "Bytes saved: %"PRIu64"\n", info->bytes);
158 + }
159 + if (info->has_error) {
160 + monitor_printf(mon, "Error: %s\n", info->error);
161 + }
162 +}
163 Index: new/hmp.h
164 ===================================================================
165 --- new.orig/hmp.h 2012-09-24 07:15:44.000000000 +0200
166 +++ new/hmp.h 2012-09-24 07:15:58.000000000 +0200
167 @@ -25,6 +25,7 @@
168 void hmp_info_uuid(Monitor *mon);
169 void hmp_info_chardev(Monitor *mon);
170 void hmp_info_mice(Monitor *mon);
171 +void hmp_info_savevm(Monitor *mon);
172 void hmp_info_migrate(Monitor *mon);
173 void hmp_info_migrate_capabilities(Monitor *mon);
174 void hmp_info_migrate_cache_size(Monitor *mon);
175 @@ -71,5 +72,9 @@
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
184 #endif
185 Index: new/hmp-commands.hx
186 ===================================================================
187 --- new.orig/hmp-commands.hx 2012-09-24 07:15:44.000000000 +0200
188 +++ new/hmp-commands.hx 2012-09-24 07:15:58.000000000 +0200
189 @@ -1468,6 +1468,8 @@
190 show current migration capabilities
191 @item info migrate_cache_size
192 show current migration XBZRLE cache size
193 +@item info savevm
194 +show savevm status
195 @item info balloon
196 show balloon information
197 @item info qtree
198 @@ -1494,3 +1496,35 @@
199 STEXI
200 @end table
201 ETEXI
202 +
203 + {
204 + .name = "savevm-start",
205 + .args_type = "statefile:s?",
206 + .params = "[statefile]",
207 + .help = "Prepare for snapshot and halt VM. Save VM state to statefile.",
208 + .mhandler.cmd = hmp_savevm_start,
209 + },
210 +
211 + {
212 + .name = "snapshot-drive",
213 + .args_type = "device:s,name:s",
214 + .params = "device name",
215 + .help = "Create internal snapshot.",
216 + .mhandler.cmd = hmp_snapshot_drive,
217 + },
218 +
219 + {
220 + .name = "delete-drive-snapshot",
221 + .args_type = "device:s,name:s",
222 + .params = "device name",
223 + .help = "Delete internal snapshot.",
224 + .mhandler.cmd = hmp_delete_drive_snapshot,
225 + },
226 +
227 + {
228 + .name = "savevm-end",
229 + .args_type = "",
230 + .params = "",
231 + .help = "Resume VM after snaphot.",
232 + .mhandler.cmd = hmp_savevm_end,
233 + },
234 Index: new/savevm-async.c
235 ===================================================================
236 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
237 +++ new/savevm-async.c 2012-09-24 09:17:54.000000000 +0200
238 @@ -0,0 +1,441 @@
239 +#include "qemu-common.h"
240 +#include "qerror.h"
241 +#include "sysemu.h"
242 +#include "qmp-commands.h"
243 +#include "blockdev.h"
244 +#include "qemu/qom-qobject.h"
245 +#include "buffered_file.h"
246 +#include "migration.h"
247 +
248 +//#define DEBUG_SAVEVM_STATE
249 +
250 +#ifdef DEBUG_SAVEVM_STATE
251 +#define DPRINTF(fmt, ...) \
252 + do { printf("savevm-async: " fmt, ## __VA_ARGS__); } while (0)
253 +#else
254 +#define DPRINTF(fmt, ...) \
255 + do { } while (0)
256 +#endif
257 +
258 +enum {
259 + SAVE_STATE_DONE,
260 + SAVE_STATE_ERROR,
261 + SAVE_STATE_ACTIVE,
262 + SAVE_STATE_COMPLETED,
263 +};
264 +
265 +static struct SnapshotState {
266 + BlockDriverState *bs;
267 + size_t bs_pos;
268 + int state;
269 + Error *error;
270 + int saved_vm_running;
271 + QEMUFile *file;
272 + int64_t total_time;
273 +} snap_state;
274 +
275 +SaveVMInfo *qmp_query_savevm(Error **errp)
276 +{
277 + SaveVMInfo *info = g_malloc0(sizeof(*info));
278 + struct SnapshotState *s = &snap_state;
279 +
280 + if (s->state != SAVE_STATE_DONE) {
281 + info->has_bytes = true;
282 + info->bytes = s->bs_pos;
283 + switch (s->state) {
284 + case SAVE_STATE_ERROR:
285 + info->has_status = true;
286 + info->status = g_strdup("failed");
287 + info->has_total_time = true;
288 + info->total_time = s->total_time;
289 + if (s->error) {
290 + info->has_error = true;
291 + info->error = g_strdup(error_get_pretty(s->error));
292 + }
293 + break;
294 + case SAVE_STATE_ACTIVE:
295 + info->has_status = true;
296 + info->status = g_strdup("active");
297 + info->has_total_time = true;
298 + info->total_time = qemu_get_clock_ms(rt_clock)
299 + - s->total_time;
300 + break;
301 + case SAVE_STATE_COMPLETED:
302 + info->has_status = true;
303 + info->status = g_strdup("completed");
304 + info->has_total_time = true;
305 + info->total_time = s->total_time;
306 + break;
307 + }
308 + }
309 +
310 + return info;
311 +}
312 +
313 +static int save_snapshot_cleanup(void)
314 +{
315 + int ret = 0;
316 +
317 + DPRINTF("save_snapshot_cleanup\n");
318 +
319 + snap_state.total_time = qemu_get_clock_ms(rt_clock) -
320 + snap_state.total_time;
321 +
322 + if (snap_state.file) {
323 + ret = qemu_fclose(snap_state.file);
324 + }
325 +
326 + if (snap_state.bs) {
327 + // try to truncate, but ignore errors (will fail on block devices).
328 + // note: bdrv_read() need whole blocks, so we round up
329 + size_t size = (snap_state.bs_pos + BDRV_SECTOR_SIZE) & BDRV_SECTOR_MASK;
330 + bdrv_truncate(snap_state.bs, size);
331 +
332 + bdrv_delete(snap_state.bs);
333 + snap_state.bs = NULL;
334 + }
335 +
336 + return ret;
337 +}
338 +
339 +static void save_snapshot_error(const char *fmt, ...)
340 +{
341 + va_list ap;
342 + char *msg;
343 +
344 + va_start(ap, fmt);
345 + msg = g_strdup_vprintf(fmt, ap);
346 + va_end(ap);
347 +
348 + DPRINTF("save_snapshot_error: %s\n", msg);
349 +
350 + if (!snap_state.error) {
351 + error_set(&snap_state.error, ERROR_CLASS_GENERIC_ERROR, "%s", msg);
352 + }
353 +
354 + g_free (msg);
355 +
356 + snap_state.state = SAVE_STATE_ERROR;
357 +
358 + save_snapshot_cleanup();
359 +}
360 +
361 +static void save_snapshot_completed(void)
362 +{
363 + DPRINTF("save_snapshot_completed\n");
364 +
365 + if (save_snapshot_cleanup() < 0) {
366 + snap_state.state = SAVE_STATE_ERROR;
367 + } else {
368 + snap_state.state = SAVE_STATE_COMPLETED;
369 + }
370 +}
371 +
372 +static int block_state_close(void *opaque)
373 +{
374 + snap_state.file = NULL;
375 + return bdrv_flush(snap_state.bs);
376 +}
377 +
378 +static ssize_t block_state_put_buffer(void *opaque, const void *buf,
379 + size_t size)
380 +{
381 + int ret;
382 +
383 + if ((ret = bdrv_pwrite(snap_state.bs, snap_state.bs_pos, buf, size)) > 0) {
384 + snap_state.bs_pos += ret;
385 + }
386 +
387 + return ret;
388 +}
389 +
390 +static void block_state_put_ready(void *opaque)
391 +{
392 + int ret;
393 +
394 + if (snap_state.state != SAVE_STATE_ACTIVE) {
395 + save_snapshot_error("put_ready returning because of non-active state");
396 + return;
397 + }
398 +
399 + if (!runstate_check(RUN_STATE_SAVE_VM)) {
400 + save_snapshot_error("put_ready returning because of wrong run state");
401 + return;
402 + }
403 +
404 + ret = qemu_savevm_state_iterate(snap_state.file);
405 + if (ret < 0) {
406 + save_snapshot_error("qemu_savevm_state_iterate error %d", ret);
407 + return;
408 + } else if (ret == 1) {
409 + DPRINTF("savevm inerate finished\n");
410 + if ((ret = qemu_savevm_state_complete(snap_state.file)) < 0) {
411 + save_snapshot_error("qemu_savevm_state_complete error %d", ret);
412 + return;
413 + } else {
414 + DPRINTF("save complete\n");
415 + save_snapshot_completed();
416 + return;
417 + }
418 + }
419 +}
420 +
421 +static void block_state_wait_for_unfreeze(void *opaque)
422 +{
423 + /* do nothing here - should not be called */
424 +}
425 +
426 +void qmp_savevm_start(bool has_statefile, const char *statefile, Error **errp)
427 +{
428 + BlockDriver *drv = NULL;
429 + int bdrv_oflags = BDRV_O_CACHE_WB | BDRV_O_RDWR;
430 + MigrationParams params = {
431 + .blk = 0,
432 + .shared = 0
433 + };
434 + int ret;
435 +
436 + if (snap_state.state != SAVE_STATE_DONE) {
437 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
438 + "VM snapshot already started\n");
439 + return;
440 + }
441 +
442 + /* initialize snapshot info */
443 + snap_state.saved_vm_running = runstate_is_running();
444 + snap_state.bs_pos = 0;
445 + snap_state.total_time = qemu_get_clock_ms(rt_clock);
446 +
447 + if (snap_state.error) {
448 + error_free(snap_state.error);
449 + snap_state.error = NULL;
450 + }
451 +
452 + /* stop the VM */
453 + vm_stop(RUN_STATE_SAVE_VM);
454 +
455 + if (!has_statefile) {
456 + snap_state.state = SAVE_STATE_COMPLETED;
457 + return;
458 + }
459 +
460 + if (qemu_savevm_state_blocked(errp)) {
461 + return;
462 + }
463 +
464 + /* Open the image */
465 + snap_state.bs = bdrv_new("vmstate");
466 + ret = bdrv_open(snap_state.bs, statefile, bdrv_oflags, drv);
467 + if (ret < 0) {
468 + error_set(errp, QERR_OPEN_FILE_FAILED, statefile);
469 + goto restart;
470 + }
471 +
472 + snap_state.file = qemu_fopen_ops_buffered(&snap_state, 1000000000,
473 + block_state_put_buffer,
474 + block_state_put_ready,
475 + block_state_wait_for_unfreeze,
476 + block_state_close);
477 +
478 + if (!snap_state.file) {
479 + error_set(errp, QERR_OPEN_FILE_FAILED, statefile);
480 + goto restart;
481 + }
482 +
483 + snap_state.state = SAVE_STATE_ACTIVE;
484 +
485 + ret = qemu_savevm_state_begin(snap_state.file, &params);
486 + if (ret < 0) {
487 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
488 + "qemu_savevm_state_begin failed\n");
489 + goto restart;
490 + }
491 +
492 + block_state_put_ready(&snap_state);
493 +
494 + return;
495 +
496 +restart:
497 +
498 + save_snapshot_error("setup failed");
499 +
500 + if (snap_state.saved_vm_running) {
501 + vm_start();
502 + }
503 +}
504 +
505 +void qmp_savevm_end(Error **errp)
506 +{
507 + if (snap_state.state == SAVE_STATE_DONE) {
508 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
509 + "VM snapshot not started\n");
510 + return;
511 + }
512 +
513 + if (snap_state.saved_vm_running) {
514 + vm_start();
515 + }
516 +
517 + snap_state.state = SAVE_STATE_DONE;
518 +}
519 +
520 +void qmp_snapshot_drive(const char *device, const char *name, Error **errp)
521 +{
522 + BlockDriverState *bs;
523 + QEMUSnapshotInfo sn1, *sn = &sn1;
524 + int ret;
525 +#ifdef _WIN32
526 + struct _timeb tb;
527 +#else
528 + struct timeval tv;
529 +#endif
530 +
531 + if (snap_state.state != SAVE_STATE_COMPLETED) {
532 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
533 + "VM snapshot not ready/started\n");
534 + return;
535 + }
536 +
537 + bs = bdrv_find(device);
538 + if (!bs) {
539 + error_set(errp, QERR_DEVICE_NOT_FOUND, device);
540 + return;
541 + }
542 +
543 + if (!bdrv_is_inserted(bs)) {
544 + error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
545 + return;
546 + }
547 +
548 + if (bdrv_is_read_only(bs)) {
549 + error_set(errp, QERR_DEVICE_IS_READ_ONLY, device);
550 + return;
551 + }
552 +
553 + if (!bdrv_can_snapshot(bs)) {
554 + error_set(errp, QERR_NOT_SUPPORTED);
555 + return;
556 + }
557 +
558 + if (bdrv_snapshot_find(bs, sn, name) >= 0) {
559 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
560 + "snapshot '%s' already exists", name);
561 + return;
562 + }
563 +
564 + sn = &sn1;
565 + memset(sn, 0, sizeof(*sn));
566 +
567 +#ifdef _WIN32
568 + _ftime(&tb);
569 + sn->date_sec = tb.time;
570 + sn->date_nsec = tb.millitm * 1000000;
571 +#else
572 + gettimeofday(&tv, NULL);
573 + sn->date_sec = tv.tv_sec;
574 + sn->date_nsec = tv.tv_usec * 1000;
575 +#endif
576 + sn->vm_clock_nsec = qemu_get_clock_ns(vm_clock);
577 +
578 + pstrcpy(sn->name, sizeof(sn->name), name);
579 +
580 + sn->vm_state_size = 0; /* do not save state */
581 +
582 + ret = bdrv_snapshot_create(bs, sn);
583 + if (ret < 0) {
584 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
585 + "Error while creating snapshot on '%s'\n", device);
586 + return;
587 + }
588 +}
589 +
590 +void qmp_delete_drive_snapshot(const char *device, const char *name,
591 + Error **errp)
592 +{
593 + BlockDriverState *bs;
594 + QEMUSnapshotInfo sn1, *sn = &sn1;
595 + int ret;
596 +
597 + bs = bdrv_find(device);
598 + if (!bs) {
599 + error_set(errp, QERR_DEVICE_NOT_FOUND, device);
600 + return;
601 + }
602 + if (bdrv_is_read_only(bs)) {
603 + error_set(errp, QERR_DEVICE_IS_READ_ONLY, device);
604 + return;
605 + }
606 +
607 + if (!bdrv_can_snapshot(bs)) {
608 + error_set(errp, QERR_NOT_SUPPORTED);
609 + return;
610 + }
611 +
612 + if (bdrv_snapshot_find(bs, sn, name) < 0) {
613 + /* return success if snapshot does not exists */
614 + return;
615 + }
616 +
617 + ret = bdrv_snapshot_delete(bs, name);
618 + if (ret < 0) {
619 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
620 + "Error while deleting snapshot on '%s'\n", device);
621 + return;
622 + }
623 +}
624 +
625 +static int loadstate_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
626 +{
627 + BlockDriverState *bs = (BlockDriverState *)opaque;
628 + int64_t maxlen = bdrv_getlength(bs);
629 + if (pos > maxlen) {
630 + return -EIO;
631 + }
632 + if ((pos + size) > maxlen) {
633 + size = maxlen - pos - 1;
634 + }
635 + if (size == 0) {
636 + return 0;
637 + }
638 + return bdrv_pread(bs, pos, buf, size);
639 +}
640 +
641 +int load_state_from_blockdev(const char *filename)
642 +{
643 + BlockDriverState *bs = NULL;
644 + BlockDriver *drv = NULL;
645 + QEMUFile *f;
646 + int ret = -1;
647 +
648 + bs = bdrv_new("vmstate");
649 + ret = bdrv_open(bs, filename, BDRV_O_CACHE_WB, drv);
650 + if (ret < 0) {
651 + error_report("Could not open VM state file");
652 + goto the_end;
653 + }
654 +
655 + /* restore the VM state */
656 + f = qemu_fopen_ops(bs, NULL, loadstate_get_buffer, NULL, NULL, NULL, NULL);
657 + if (!f) {
658 + error_report("Could not open VM state file");
659 + ret = -EINVAL;
660 + goto the_end;
661 + }
662 +
663 + qemu_system_reset(VMRESET_SILENT);
664 + ret = qemu_loadvm_state(f);
665 +
666 + qemu_fclose(f);
667 + if (ret < 0) {
668 + error_report("Error %d while loading VM state", ret);
669 + goto the_end;
670 + }
671 +
672 + ret = 0;
673 +
674 + the_end:
675 + if (bs) {
676 + bdrv_delete(bs);
677 + }
678 + return ret;
679 +}
680 Index: new/Makefile.objs
681 ===================================================================
682 --- new.orig/Makefile.objs 2012-09-24 07:15:44.000000000 +0200
683 +++ new/Makefile.objs 2012-09-24 07:15:58.000000000 +0200
684 @@ -78,6 +78,7 @@
685 common-obj-y += pflib.o
686 common-obj-y += bitmap.o bitops.o
687 common-obj-y += page_cache.o
688 +common-obj-y += savevm-async.o
689
690 common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
691 common-obj-$(CONFIG_WIN32) += version.o
692 Index: new/sysemu.h
693 ===================================================================
694 --- new.orig/sysemu.h 2012-09-24 07:15:44.000000000 +0200
695 +++ new/sysemu.h 2012-09-24 07:15:58.000000000 +0200
696 @@ -72,6 +72,7 @@
697
698 void do_savevm(Monitor *mon, const QDict *qdict);
699 int load_vmstate(const char *name);
700 +int load_state_from_blockdev(const char *filename);
701 void do_delvm(Monitor *mon, const QDict *qdict);
702 void do_info_snapshots(Monitor *mon);
703
704 Index: new/qemu-options.hx
705 ===================================================================
706 --- new.orig/qemu-options.hx 2012-09-24 07:15:51.000000000 +0200
707 +++ new/qemu-options.hx 2012-09-24 07:15:58.000000000 +0200
708 @@ -2477,6 +2477,19 @@
709 Start right away with a saved state (@code{loadvm} in monitor)
710 ETEXI
711
712 +DEF("loadstate", HAS_ARG, QEMU_OPTION_loadstate, \
713 + "-loadstate file\n" \
714 + " start right away with a saved state\n",
715 + QEMU_ARCH_ALL)
716 +STEXI
717 +@item -loadstate @var{file}
718 +@findex -loadstate
719 +Start right away with a saved state. This option does not rollback
720 +disk state like @code{loadvm}, so user must make sure that disk
721 +have correct state. @var{file} can be any valid device URL. See the section
722 +for "Device URL Syntax" for more information.
723 +ETEXI
724 +
725 #ifndef _WIN32
726 DEF("daemonize", 0, QEMU_OPTION_daemonize, \
727 "-daemonize daemonize QEMU after initializing\n", QEMU_ARCH_ALL)
728 Index: new/vl.c
729 ===================================================================
730 --- new.orig/vl.c 2012-09-24 07:15:53.000000000 +0200
731 +++ new/vl.c 2012-09-24 07:15:58.000000000 +0200
732 @@ -2364,6 +2364,7 @@
733 int optind;
734 const char *optarg;
735 const char *loadvm = NULL;
736 + const char *loadstate = NULL;
737 QEMUMachine *machine;
738 const char *cpu_model;
739 const char *vga_model = "none";
740 @@ -2998,6 +2999,9 @@
741 case QEMU_OPTION_loadvm:
742 loadvm = optarg;
743 break;
744 + case QEMU_OPTION_loadstate:
745 + loadstate = optarg;
746 + break;
747 case QEMU_OPTION_full_screen:
748 full_screen = 1;
749 break;
750 @@ -3821,6 +3825,10 @@
751 if (load_vmstate(loadvm) < 0) {
752 autostart = 0;
753 }
754 + } else if (loadstate) {
755 + if (load_state_from_blockdev(loadstate) < 0) {
756 + autostart = 0;
757 + }
758 }
759
760 if (incoming) {
761 Index: new/monitor.c
762 ===================================================================
763 --- new.orig/monitor.c 2012-09-24 09:21:18.000000000 +0200
764 +++ new/monitor.c 2012-09-24 09:21:32.000000000 +0200
765 @@ -2952,6 +2952,13 @@
766 .mhandler.info = hmp_info_migrate_cache_size,
767 },
768 {
769 + .name = "savevm",
770 + .args_type = "",
771 + .params = "",
772 + .help = "show savevm status",
773 + .mhandler.info = hmp_info_savevm,
774 + },
775 + {
776 .name = "balloon",
777 .args_type = "",
778 .params = "",