/src/qemu/replay/replay-snapshot.c
Line | Count | Source |
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 "system/replay.h" |
15 | | #include "replay-internal.h" |
16 | | #include "monitor/monitor.h" |
17 | | #include "qobject/qstring.h" |
18 | | #include "qemu/error-report.h" |
19 | | #include "migration/vmstate.h" |
20 | | #include "migration/snapshot.h" |
21 | | |
22 | | static int replay_pre_save(void *opaque) |
23 | 0 | { |
24 | 0 | ReplayState *state = opaque; |
25 | 0 | state->file_offset = ftell(replay_file); |
26 | |
|
27 | 0 | return 0; |
28 | 0 | } |
29 | | |
30 | | static int replay_post_load(void *opaque, int version_id) |
31 | 0 | { |
32 | 0 | ReplayState *state = opaque; |
33 | 0 | if (replay_mode == REPLAY_MODE_PLAY) { |
34 | 0 | fseek(replay_file, state->file_offset, SEEK_SET); |
35 | | /* If this was a vmstate, saved in recording mode, |
36 | | we need to initialize replay data fields. */ |
37 | 0 | replay_fetch_data_kind(); |
38 | 0 | } else if (replay_mode == REPLAY_MODE_RECORD) { |
39 | | /* This is only useful for loading the initial state. |
40 | | Therefore reset all the counters. */ |
41 | 0 | state->instruction_count = 0; |
42 | 0 | state->block_request_id = 0; |
43 | 0 | } |
44 | |
|
45 | 0 | return 0; |
46 | 0 | } |
47 | | |
48 | | static const VMStateDescription vmstate_replay = { |
49 | | .name = "replay", |
50 | | .version_id = 3, |
51 | | .minimum_version_id = 3, |
52 | | .pre_save = replay_pre_save, |
53 | | .post_load = replay_post_load, |
54 | | .fields = (const VMStateField[]) { |
55 | | VMSTATE_INT64_ARRAY(cached_clock, ReplayState, REPLAY_CLOCK_COUNT), |
56 | | VMSTATE_UINT64(current_icount, ReplayState), |
57 | | VMSTATE_INT32(instruction_count, ReplayState), |
58 | | VMSTATE_UINT32(current_event, ReplayState), |
59 | | VMSTATE_UINT32(data_kind, ReplayState), |
60 | | VMSTATE_BOOL(has_unread_data, ReplayState), |
61 | | VMSTATE_UINT64(file_offset, ReplayState), |
62 | | VMSTATE_UINT64(block_request_id, ReplayState), |
63 | | VMSTATE_UINT64(read_event_id, ReplayState), |
64 | | VMSTATE_END_OF_LIST() |
65 | | }, |
66 | | }; |
67 | | |
68 | | void replay_vmstate_register(void) |
69 | 0 | { |
70 | 0 | vmstate_register(NULL, 0, &vmstate_replay, &replay_state); |
71 | 0 | } |
72 | | |
73 | | void replay_vmstate_init(void) |
74 | 0 | { |
75 | 0 | Error *err = NULL; |
76 | |
|
77 | 0 | if (replay_snapshot) { |
78 | 0 | if (replay_mode == REPLAY_MODE_RECORD) { |
79 | 0 | if (!save_snapshot(replay_snapshot, |
80 | 0 | true, NULL, false, NULL, &err)) { |
81 | 0 | error_report_err(err); |
82 | 0 | error_report("Could not create snapshot for icount record"); |
83 | 0 | exit(1); |
84 | 0 | } |
85 | 0 | } else if (replay_mode == REPLAY_MODE_PLAY) { |
86 | 0 | if (!load_snapshot(replay_snapshot, NULL, false, NULL, &err)) { |
87 | 0 | error_report_err(err); |
88 | 0 | error_report("Could not load snapshot for icount replay"); |
89 | 0 | exit(1); |
90 | 0 | } |
91 | 0 | } |
92 | 0 | } |
93 | 0 | } |
94 | | |
95 | | bool replay_can_snapshot(void) |
96 | 0 | { |
97 | 0 | return replay_mode == REPLAY_MODE_NONE |
98 | 0 | || !replay_has_events(); |
99 | 0 | } |