diff mbox

[v2,04/10] replay: save/load initial state

Message ID 20160915090105.6440.95131.stgit@PASHA-ISP
State New
Headers show

Commit Message

Pavel Dovgalyuk Sept. 15, 2016, 9:01 a.m. UTC
This patch implements initial vmstate creation or loading at the start
of record/replay. It is needed for rewinding the execution in the replay mode.

Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
---
 include/sysemu/replay.h  |    6 ++++++
 replay/Makefile.objs     |    1 +
 replay/replay-snapshot.c |   31 +++++++++++++++++++++++++++++++
 vl.c                     |    2 ++
 4 files changed, 40 insertions(+)
 create mode 100644 replay/replay-snapshot.c

Comments

Paolo Bonzini Sept. 15, 2016, 9:25 a.m. UTC | #1
On 15/09/2016 11:01, Pavel Dovgalyuk wrote:
> +{
> +    if (replay_mode == REPLAY_MODE_RECORD) {
> +        QDict *opts = qdict_new();
> +        qdict_put(opts, "name", qstring_from_str("replay_init"));
> +        hmp_savevm(cur_mon, opts);
> +        QDECREF(opts);
> +    } else if (replay_mode == REPLAY_MODE_PLAY) {
> +        load_vmstate("replay_init");

See my other message about a suggestion to remove the hardcoded snapshot
name.

Also, I think the return value of load_vmstate and hmp_savevm should be
checked.

> +    }
> +}
> diff --git a/vl.c b/vl.c
> index 1c68779..6698d88 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -4593,6 +4593,8 @@ int main(int argc, char **argv, char **envp)
>          if (load_vmstate(loadvm) < 0) {
>              autostart = 0;
>          }
> +    } else {
> +        replay_vmstate_init();
>      }

Should -loadvm be incompatible with -rr?

Paolo
Pavel Dovgalyuk Sept. 16, 2016, 7:56 a.m. UTC | #2
> From: Paolo Bonzini [mailto:pbonzini@redhat.com]
> On 15/09/2016 11:01, Pavel Dovgalyuk wrote:
> > +{
> > +    if (replay_mode == REPLAY_MODE_RECORD) {
> > +        QDict *opts = qdict_new();
> > +        qdict_put(opts, "name", qstring_from_str("replay_init"));
> > +        hmp_savevm(cur_mon, opts);
> > +        QDECREF(opts);
> > +    } else if (replay_mode == REPLAY_MODE_PLAY) {
> > +        load_vmstate("replay_init");
> 
> See my other message about a suggestion to remove the hardcoded snapshot
> name.
> 
> Also, I think the return value of load_vmstate and hmp_savevm should be
> checked.

Load may be unsuccessful when the system is started with temporary overlay file.
This is ok.

> > +    }
> > +}
> > diff --git a/vl.c b/vl.c
> > index 1c68779..6698d88 100644
> > --- a/vl.c
> > +++ b/vl.c
> > @@ -4593,6 +4593,8 @@ int main(int argc, char **argv, char **envp)
> >          if (load_vmstate(loadvm) < 0) {
> >              autostart = 0;
> >          }
> > +    } else {
> > +        replay_vmstate_init();
> >      }
> 
> Should -loadvm be incompatible with -rr?

User either loads some initial state or relies on replay which uses 'replay_init'.

Pavel Dovgalyuk
Paolo Bonzini Sept. 16, 2016, 9:29 a.m. UTC | #3
On 16/09/2016 09:56, Pavel Dovgalyuk wrote:
>>> > > +{
>>> > > +    if (replay_mode == REPLAY_MODE_RECORD) {
>>> > > +        QDict *opts = qdict_new();
>>> > > +        qdict_put(opts, "name", qstring_from_str("replay_init"));
>>> > > +        hmp_savevm(cur_mon, opts);
>>> > > +        QDECREF(opts);
>>> > > +    } else if (replay_mode == REPLAY_MODE_PLAY) {
>>> > > +        load_vmstate("replay_init");
>> > 
>> > See my other message about a suggestion to remove the hardcoded snapshot
>> > name.
>> > 
>> > Also, I think the return value of load_vmstate and hmp_savevm should be
>> > checked.
> 
> Load may be unsuccessful when the system is started with temporary overlay file.
> This is ok.

This seems to be in favor of using a rrsnapshot option instead.  Using
rrsnapshot for temporary overlay would make little sense.

Paolo
diff mbox

Patch

diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h
index a408633..aa378ce 100644
--- a/include/sysemu/replay.h
+++ b/include/sysemu/replay.h
@@ -145,4 +145,10 @@  void replay_unregister_net(ReplayNetState *rns);
 void replay_net_packet_event(ReplayNetState *rns, unsigned flags,
                              const struct iovec *iov, int iovcnt);
 
+/* VM state operations */
+
+/*! Called at the start of execution.
+    Loads or saves initial vmstate depending on execution mode. */
+void replay_vmstate_init(void);
+
 #endif
diff --git a/replay/Makefile.objs b/replay/Makefile.objs
index f55a6b5..4600d74 100644
--- a/replay/Makefile.objs
+++ b/replay/Makefile.objs
@@ -5,3 +5,4 @@  common-obj-y += replay-time.o
 common-obj-y += replay-input.o
 common-obj-y += replay-char.o
 common-obj-y += replay-net.o
+common-obj-y += replay-snapshot.o
diff --git a/replay/replay-snapshot.c b/replay/replay-snapshot.c
new file mode 100644
index 0000000..a48c6fc
--- /dev/null
+++ b/replay/replay-snapshot.c
@@ -0,0 +1,31 @@ 
+/*
+ * replay-snapshot.c
+ *
+ * Copyright (c) 2010-2016 Institute for System Programming
+ *                         of the Russian Academy of Sciences.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qemu-common.h"
+#include "sysemu/replay.h"
+#include "replay-internal.h"
+#include "sysemu/sysemu.h"
+#include "monitor/monitor.h"
+#include "qapi/qmp/qstring.h"
+
+void replay_vmstate_init(void)
+{
+    if (replay_mode == REPLAY_MODE_RECORD) {
+        QDict *opts = qdict_new();
+        qdict_put(opts, "name", qstring_from_str("replay_init"));
+        hmp_savevm(cur_mon, opts);
+        QDECREF(opts);
+    } else if (replay_mode == REPLAY_MODE_PLAY) {
+        load_vmstate("replay_init");
+    }
+}
diff --git a/vl.c b/vl.c
index 1c68779..6698d88 100644
--- a/vl.c
+++ b/vl.c
@@ -4593,6 +4593,8 @@  int main(int argc, char **argv, char **envp)
         if (load_vmstate(loadvm) < 0) {
             autostart = 0;
         }
+    } else {
+        replay_vmstate_init();
     }
 
     qdev_prop_check_globals();