Blame SOURCES/kvm-shutdown-Preserve-shutdown-cause-through-replay.patch

76daa3
From 42b5017297d569a4b1e015b5398488bec24f09da Mon Sep 17 00:00:00 2001
76daa3
From: Eric Blake <eblake@redhat.com>
76daa3
Date: Thu, 1 Jun 2017 16:58:19 +0200
76daa3
Subject: [PATCH 03/17] shutdown: Preserve shutdown cause through replay
76daa3
76daa3
RH-Author: Eric Blake <eblake@redhat.com>
76daa3
Message-id: <20170601165821.26810-4-eblake@redhat.com>
76daa3
Patchwork-id: 75468
76daa3
O-Subject: [RHEL-7.4 qemu-kvm-rhev PATCH v2 3/5] shutdown: Preserve shutdown cause through replay
76daa3
Bugzilla: 1418927
76daa3
RH-Acked-by: John Snow <jsnow@redhat.com>
76daa3
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
76daa3
RH-Acked-by: Thomas Huth <thuth@redhat.com>
76daa3
76daa3
With the recent addition of ShutdownCause, we want to be able to pass
76daa3
a cause through any shutdown request, and then faithfully replay that
76daa3
cause when later replaying the same sequence.  The easiest way is to
76daa3
expand the reply event mechanism to track a series of values for
76daa3
EVENT_SHUTDOWN, one corresponding to each value of ShutdownCause.
76daa3
76daa3
We are free to change the replay stream as needed, since there are
76daa3
already no guarantees about being able to use a replay stream by
76daa3
any other version of qemu than the one that generated it.
76daa3
76daa3
The cause is not actually fed back until the next patch changes the
76daa3
signature for requesting a shutdown; a TODO marks that upcoming change.
76daa3
76daa3
Yes, this uses the gcc/clang extension of a ranged case label,
76daa3
but this is not the first time we've used non-C99 constructs.
76daa3
76daa3
Signed-off-by: Eric Blake <eblake@redhat.com>
76daa3
Reviewed-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
76daa3
Message-Id: <20170515214114.15442-4-eblake@redhat.com>
76daa3
Reviewed-by: Markus Armbruster <armbru@redhat.com>
76daa3
Signed-off-by: Markus Armbruster <armbru@redhat.com>
76daa3
(cherry picked from commit 802f045a5f61b781df55e4492d896b4d20503ba7)
76daa3
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
76daa3
---
76daa3
 include/sysemu/replay.h  | 3 ++-
76daa3
 replay/replay-internal.h | 3 ++-
76daa3
 replay/replay.c          | 7 ++++---
76daa3
 vl.c                     | 2 +-
76daa3
 4 files changed, 9 insertions(+), 6 deletions(-)
76daa3
76daa3
diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h
76daa3
index f1c0712..fa14d0e 100644
76daa3
--- a/include/sysemu/replay.h
76daa3
+++ b/include/sysemu/replay.h
76daa3
@@ -13,6 +13,7 @@
76daa3
  */
76daa3
 
76daa3
 #include "qapi-types.h"
76daa3
+#include "sysemu.h"
76daa3
 
76daa3
 /* replay clock kinds */
76daa3
 enum ReplayClockKind {
76daa3
@@ -98,7 +99,7 @@ int64_t replay_read_clock(ReplayClockKind kind);
76daa3
 /* Events */
76daa3
 
76daa3
 /*! Called when qemu shutdown is requested. */
76daa3
-void replay_shutdown_request(void);
76daa3
+void replay_shutdown_request(ShutdownCause cause);
76daa3
 /*! Should be called at check points in the execution.
76daa3
     These check points are skipped, if they were not met.
76daa3
     Saves checkpoint in the SAVE mode and validates in the PLAY mode.
76daa3
diff --git a/replay/replay-internal.h b/replay/replay-internal.h
76daa3
index ed66ed8..3ebb199 100644
76daa3
--- a/replay/replay-internal.h
76daa3
+++ b/replay/replay-internal.h
76daa3
@@ -22,8 +22,9 @@ enum ReplayEvents {
76daa3
     EVENT_EXCEPTION,
76daa3
     /* for async events */
76daa3
     EVENT_ASYNC,
76daa3
-    /* for shutdown request */
76daa3
+    /* for shutdown requests, range allows recovery of ShutdownCause */
76daa3
     EVENT_SHUTDOWN,
76daa3
+    EVENT_SHUTDOWN_LAST = EVENT_SHUTDOWN + SHUTDOWN_CAUSE__MAX,
76daa3
     /* for character device write event */
76daa3
     EVENT_CHAR_WRITE,
76daa3
     /* for character device read all event */
76daa3
diff --git a/replay/replay.c b/replay/replay.c
76daa3
index f810628..bf94e81 100644
76daa3
--- a/replay/replay.c
76daa3
+++ b/replay/replay.c
76daa3
@@ -49,8 +49,9 @@ bool replay_next_event_is(int event)
76daa3
             res = true;
76daa3
         }
76daa3
         switch (replay_state.data_kind) {
76daa3
-        case EVENT_SHUTDOWN:
76daa3
+        case EVENT_SHUTDOWN ... EVENT_SHUTDOWN_LAST:
76daa3
             replay_finish_event();
76daa3
+            /* TODO - pass replay_state.data_kind - EVENT_SHUTDOWN as cause */
76daa3
             qemu_system_shutdown_request();
76daa3
             break;
76daa3
         default:
76daa3
@@ -170,11 +171,11 @@ bool replay_has_interrupt(void)
76daa3
     return res;
76daa3
 }
76daa3
 
76daa3
-void replay_shutdown_request(void)
76daa3
+void replay_shutdown_request(ShutdownCause cause)
76daa3
 {
76daa3
     if (replay_mode == REPLAY_MODE_RECORD) {
76daa3
         replay_mutex_lock();
76daa3
-        replay_put_event(EVENT_SHUTDOWN);
76daa3
+        replay_put_event(EVENT_SHUTDOWN + cause);
76daa3
         replay_mutex_unlock();
76daa3
     }
76daa3
 }
76daa3
diff --git a/vl.c b/vl.c
76daa3
index ea181c6..18fdef2 100644
76daa3
--- a/vl.c
76daa3
+++ b/vl.c
76daa3
@@ -1820,8 +1820,8 @@ void qemu_system_killed(int signal, pid_t pid)
76daa3
 void qemu_system_shutdown_request(void)
76daa3
 {
76daa3
     trace_qemu_system_shutdown_request();
76daa3
-    replay_shutdown_request();
76daa3
     /* TODO - add a parameter to allow callers to specify reason */
76daa3
+    replay_shutdown_request(SHUTDOWN_CAUSE_HOST_ERROR);
76daa3
     shutdown_requested = SHUTDOWN_CAUSE_HOST_ERROR;
76daa3
     qemu_notify_event();
76daa3
 }
76daa3
-- 
76daa3
1.8.3.1
76daa3