]>
Commit | Line | Data |
---|---|---|
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 | 24 | static int replay_pre_save(void *opaque) |
306e196f PD |
25 | { |
26 | ReplayState *state = opaque; | |
27 | state->file_offset = ftell(replay_file); | |
4b930d26 | 28 | state->host_clock_last = qemu_clock_get_last(QEMU_CLOCK_HOST); |
44b1ff31 DDAG |
29 | |
30 | return 0; | |
306e196f PD |
31 | } |
32 | ||
33 | static int replay_post_load(void *opaque, int version_id) | |
34 | { | |
35 | ReplayState *state = opaque; | |
36 | fseek(replay_file, state->file_offset, SEEK_SET); | |
4b930d26 | 37 | qemu_clock_set_last(QEMU_CLOCK_HOST, state->host_clock_last); |
306e196f PD |
38 | /* If this was a vmstate, saved in recording mode, |
39 | we need to initialize replay data fields. */ | |
40 | replay_fetch_data_kind(); | |
41 | ||
42 | return 0; | |
43 | } | |
44 | ||
45 | static const VMStateDescription vmstate_replay = { | |
46 | .name = "replay", | |
47 | .version_id = 1, | |
48 | .minimum_version_id = 1, | |
49 | .pre_save = replay_pre_save, | |
50 | .post_load = replay_post_load, | |
51 | .fields = (VMStateField[]) { | |
52 | VMSTATE_INT64_ARRAY(cached_clock, ReplayState, REPLAY_CLOCK_COUNT), | |
53 | VMSTATE_UINT64(current_step, ReplayState), | |
54 | VMSTATE_INT32(instructions_count, ReplayState), | |
55 | VMSTATE_UINT32(data_kind, ReplayState), | |
56 | VMSTATE_UINT32(has_unread_data, ReplayState), | |
57 | VMSTATE_UINT64(file_offset, ReplayState), | |
6d0ceb80 | 58 | VMSTATE_UINT64(block_request_id, ReplayState), |
4b930d26 | 59 | VMSTATE_UINT64(host_clock_last, ReplayState), |
306e196f PD |
60 | VMSTATE_END_OF_LIST() |
61 | }, | |
62 | }; | |
63 | ||
64 | void replay_vmstate_register(void) | |
65 | { | |
66 | vmstate_register(NULL, 0, &vmstate_replay, &replay_state); | |
67 | } | |
9c2037d0 PD |
68 | |
69 | void replay_vmstate_init(void) | |
70 | { | |
927d6638 JQ |
71 | Error *err = NULL; |
72 | ||
9c2037d0 PD |
73 | if (replay_snapshot) { |
74 | if (replay_mode == REPLAY_MODE_RECORD) { | |
5e22479a | 75 | if (save_snapshot(replay_snapshot, &err) != 0) { |
927d6638 | 76 | error_report_err(err); |
9c2037d0 PD |
77 | error_report("Could not create snapshot for icount record"); |
78 | exit(1); | |
79 | } | |
80 | } else if (replay_mode == REPLAY_MODE_PLAY) { | |
5e22479a | 81 | if (load_snapshot(replay_snapshot, &err) != 0) { |
927d6638 | 82 | error_report_err(err); |
9c2037d0 PD |
83 | error_report("Could not load snapshot for icount replay"); |
84 | exit(1); | |
85 | } | |
86 | } | |
87 | } | |
88 | } | |
377b21cc PD |
89 | |
90 | bool replay_can_snapshot(void) | |
91 | { | |
92 | return replay_mode == REPLAY_MODE_NONE | |
93 | || !replay_has_events(); | |
94 | } |