Pavel Dovgalyuk | 306e196 | 2016-09-26 11:08:10 +0300 | [diff] [blame] | 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" |
| 22 | |
| 23 | static void replay_pre_save(void *opaque) |
| 24 | { |
| 25 | ReplayState *state = opaque; |
| 26 | state->file_offset = ftell(replay_file); |
| 27 | } |
| 28 | |
| 29 | static int replay_post_load(void *opaque, int version_id) |
| 30 | { |
| 31 | ReplayState *state = opaque; |
| 32 | fseek(replay_file, state->file_offset, SEEK_SET); |
| 33 | /* If this was a vmstate, saved in recording mode, |
| 34 | we need to initialize replay data fields. */ |
| 35 | replay_fetch_data_kind(); |
| 36 | |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | static const VMStateDescription vmstate_replay = { |
| 41 | .name = "replay", |
| 42 | .version_id = 1, |
| 43 | .minimum_version_id = 1, |
| 44 | .pre_save = replay_pre_save, |
| 45 | .post_load = replay_post_load, |
| 46 | .fields = (VMStateField[]) { |
| 47 | VMSTATE_INT64_ARRAY(cached_clock, ReplayState, REPLAY_CLOCK_COUNT), |
| 48 | VMSTATE_UINT64(current_step, ReplayState), |
| 49 | VMSTATE_INT32(instructions_count, ReplayState), |
| 50 | VMSTATE_UINT32(data_kind, ReplayState), |
| 51 | VMSTATE_UINT32(has_unread_data, ReplayState), |
| 52 | VMSTATE_UINT64(file_offset, ReplayState), |
Pavel Dovgalyuk | 6d0ceb8 | 2016-09-26 11:08:16 +0300 | [diff] [blame] | 53 | VMSTATE_UINT64(block_request_id, ReplayState), |
Pavel Dovgalyuk | 306e196 | 2016-09-26 11:08:10 +0300 | [diff] [blame] | 54 | VMSTATE_END_OF_LIST() |
| 55 | }, |
| 56 | }; |
| 57 | |
| 58 | void replay_vmstate_register(void) |
| 59 | { |
| 60 | vmstate_register(NULL, 0, &vmstate_replay, &replay_state); |
| 61 | } |
Pavel Dovgalyuk | 9c2037d | 2017-01-24 10:17:47 +0300 | [diff] [blame] | 62 | |
| 63 | void replay_vmstate_init(void) |
| 64 | { |
| 65 | if (replay_snapshot) { |
| 66 | if (replay_mode == REPLAY_MODE_RECORD) { |
Juan Quintela | c34c2f3 | 2017-04-18 11:35:04 +0200 | [diff] [blame] | 67 | if (save_vmstate(replay_snapshot) != 0) { |
Pavel Dovgalyuk | 9c2037d | 2017-01-24 10:17:47 +0300 | [diff] [blame] | 68 | error_report("Could not create snapshot for icount record"); |
| 69 | exit(1); |
| 70 | } |
| 71 | } else if (replay_mode == REPLAY_MODE_PLAY) { |
| 72 | if (load_vmstate(replay_snapshot) != 0) { |
| 73 | error_report("Could not load snapshot for icount replay"); |
| 74 | exit(1); |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |