提交 0b30dc01 编写于 作者: P Pavel Dovgalyuk 提交者: Paolo Bonzini

replay: save vmstate of the asynchronous events

This patch fixes saving and loading the snapshots in the replay mode.
It is required for the snapshots created in the moment when the header
of the asynchronous event is read. This information was not saved in
the snapshot. After loading the vmstate replay continued with the file offset
passed the event header. The event header is lost in this case and replay
hangs.
Signed-off-by: NPavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
Message-Id: <20180227095322.1060.53929.stgit@pasha-VirtualBox>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
上级 89e46eb4
......@@ -27,10 +27,6 @@ typedef struct Event {
} Event;
static QTAILQ_HEAD(, Event) events_list = QTAILQ_HEAD_INITIALIZER(events_list);
static unsigned int read_event_kind = -1;
static uint64_t read_id = -1;
static int read_checkpoint = -1;
static bool events_enabled;
/* Functions */
......@@ -218,58 +214,60 @@ void replay_save_events(int checkpoint)
static Event *replay_read_event(int checkpoint)
{
Event *event;
if (read_event_kind == -1) {
read_checkpoint = replay_get_byte();
read_event_kind = replay_get_byte();
read_id = -1;
if (replay_state.read_event_kind == -1) {
replay_state.read_event_checkpoint = replay_get_byte();
replay_state.read_event_kind = replay_get_byte();
replay_state.read_event_id = -1;
replay_check_error();
}
if (checkpoint != read_checkpoint) {
if (checkpoint != replay_state.read_event_checkpoint) {
return NULL;
}
/* Events that has not to be in the queue */
switch (read_event_kind) {
switch (replay_state.read_event_kind) {
case REPLAY_ASYNC_EVENT_BH:
if (read_id == -1) {
read_id = replay_get_qword();
if (replay_state.read_event_id == -1) {
replay_state.read_event_id = replay_get_qword();
}
break;
case REPLAY_ASYNC_EVENT_INPUT:
event = g_malloc0(sizeof(Event));
event->event_kind = read_event_kind;
event->event_kind = replay_state.read_event_kind;
event->opaque = replay_read_input_event();
return event;
case REPLAY_ASYNC_EVENT_INPUT_SYNC:
event = g_malloc0(sizeof(Event));
event->event_kind = read_event_kind;
event->event_kind = replay_state.read_event_kind;
event->opaque = 0;
return event;
case REPLAY_ASYNC_EVENT_CHAR_READ:
event = g_malloc0(sizeof(Event));
event->event_kind = read_event_kind;
event->event_kind = replay_state.read_event_kind;
event->opaque = replay_event_char_read_load();
return event;
case REPLAY_ASYNC_EVENT_BLOCK:
if (read_id == -1) {
read_id = replay_get_qword();
if (replay_state.read_event_id == -1) {
replay_state.read_event_id = replay_get_qword();
}
break;
case REPLAY_ASYNC_EVENT_NET:
event = g_malloc0(sizeof(Event));
event->event_kind = read_event_kind;
event->event_kind = replay_state.read_event_kind;
event->opaque = replay_event_net_load();
return event;
default:
error_report("Unknown ID %d of replay event", read_event_kind);
error_report("Unknown ID %d of replay event",
replay_state.read_event_kind);
exit(1);
break;
}
QTAILQ_FOREACH(event, &events_list, events) {
if (event->event_kind == read_event_kind
&& (read_id == -1 || read_id == event->id)) {
if (event->event_kind == replay_state.read_event_kind
&& (replay_state.read_event_id == -1
|| replay_state.read_event_id == event->id)) {
break;
}
}
......@@ -295,7 +293,7 @@ void replay_read_events(int checkpoint)
break;
}
replay_finish_event();
read_event_kind = -1;
replay_state.read_event_kind = -1;
replay_run_event(event);
g_free(event);
......@@ -304,7 +302,7 @@ void replay_read_events(int checkpoint)
void replay_init_events(void)
{
read_event_kind = -1;
replay_state.read_event_kind = -1;
}
void replay_finish_events(void)
......
......@@ -80,6 +80,12 @@ typedef struct ReplayState {
uint64_t block_request_id;
/*! Prior value of the host clock */
uint64_t host_clock_last;
/*! Asynchronous event type read from the log */
int32_t read_event_kind;
/*! Asynchronous event id read from the log */
uint64_t read_event_id;
/*! Asynchronous event checkpoint id read from the log */
int32_t read_event_checkpoint;
} ReplayState;
extern ReplayState replay_state;
......
......@@ -57,6 +57,9 @@ static const VMStateDescription vmstate_replay = {
VMSTATE_UINT64(file_offset, ReplayState),
VMSTATE_UINT64(block_request_id, ReplayState),
VMSTATE_UINT64(host_clock_last, ReplayState),
VMSTATE_INT32(read_event_kind, ReplayState),
VMSTATE_UINT64(read_event_id, ReplayState),
VMSTATE_INT32(read_event_checkpoint, ReplayState),
VMSTATE_END_OF_LIST()
},
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册