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