]> git.proxmox.com Git - mirror_qemu.git/blame - replay/replay-snapshot.c
replay: fix save/load vm for non-empty queue
[mirror_qemu.git] / replay / replay-snapshot.c
CommitLineData
306e196f
PD
1/*
2 * replay-snapshot.c
3 *
4 * Copyright (c) 2010-2016 Institute for System Programming
5 * of the Russian Academy of Sciences.
6 *
7 * This work is licensed under the terms of the GNU GPL, version 2 or later.
8 * See the COPYING file in the top-level directory.
9 *
10 */
11
12#include "qemu/osdep.h"
13#include "qapi/error.h"
14#include "qemu-common.h"
15#include "sysemu/replay.h"
16#include "replay-internal.h"
17#include "sysemu/sysemu.h"
18#include "monitor/monitor.h"
19#include "qapi/qmp/qstring.h"
20#include "qemu/error-report.h"
21#include "migration/vmstate.h"
5e22479a 22#include "migration/snapshot.h"
306e196f 23
44b1ff31 24static int replay_pre_save(void *opaque)
306e196f
PD
25{
26 ReplayState *state = opaque;
27 state->file_offset = ftell(replay_file);
44b1ff31
DDAG
28
29 return 0;
306e196f
PD
30}
31
32static int replay_post_load(void *opaque, int version_id)
33{
34 ReplayState *state = opaque;
35 fseek(replay_file, state->file_offset, SEEK_SET);
36 /* If this was a vmstate, saved in recording mode,
37 we need to initialize replay data fields. */
38 replay_fetch_data_kind();
39
40 return 0;
41}
42
43static const VMStateDescription vmstate_replay = {
44 .name = "replay",
45 .version_id = 1,
46 .minimum_version_id = 1,
47 .pre_save = replay_pre_save,
48 .post_load = replay_post_load,
49 .fields = (VMStateField[]) {
50 VMSTATE_INT64_ARRAY(cached_clock, ReplayState, REPLAY_CLOCK_COUNT),
51 VMSTATE_UINT64(current_step, ReplayState),
52 VMSTATE_INT32(instructions_count, ReplayState),
53 VMSTATE_UINT32(data_kind, ReplayState),
54 VMSTATE_UINT32(has_unread_data, ReplayState),
55 VMSTATE_UINT64(file_offset, ReplayState),
6d0ceb80 56 VMSTATE_UINT64(block_request_id, ReplayState),
306e196f
PD
57 VMSTATE_END_OF_LIST()
58 },
59};
60
61void replay_vmstate_register(void)
62{
63 vmstate_register(NULL, 0, &vmstate_replay, &replay_state);
64}
9c2037d0
PD
65
66void replay_vmstate_init(void)
67{
927d6638
JQ
68 Error *err = NULL;
69
9c2037d0
PD
70 if (replay_snapshot) {
71 if (replay_mode == REPLAY_MODE_RECORD) {
5e22479a 72 if (save_snapshot(replay_snapshot, &err) != 0) {
927d6638 73 error_report_err(err);
9c2037d0
PD
74 error_report("Could not create snapshot for icount record");
75 exit(1);
76 }
77 } else if (replay_mode == REPLAY_MODE_PLAY) {
5e22479a 78 if (load_snapshot(replay_snapshot, &err) != 0) {
927d6638 79 error_report_err(err);
9c2037d0
PD
80 error_report("Could not load snapshot for icount replay");
81 exit(1);
82 }
83 }
84 }
85}
377b21cc
PD
86
87bool replay_can_snapshot(void)
88{
89 return replay_mode == REPLAY_MODE_NONE
90 || !replay_has_events();
91}