From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
Subject: [PULL 14/45] qmp: generalize watchdog-set-action to -no-reboot/-no-shutdown
Date: Tue, 15 Dec 2020 12:54:14 -0500 [thread overview]
Message-ID: <20201215175445.1272776-15-pbonzini@redhat.com> (raw)
In-Reply-To: <20201215175445.1272776-1-pbonzini@redhat.com>
From: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
Add a QMP command to allow for the behaviors specified by the
-no-reboot and -no-shutdown command line option to be set at runtime.
The new command is named set-action and takes optional arguments, named
after an event, that provide a corresponding action to take.
Example:
-> { "execute": "set-action",
"arguments": {
"reboot": "none",
"shutdown": "poweroff",
"watchdog": "debug" } }
<- { "return": {} }
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
Message-Id: <1607705564-26264-4-git-send-email-alejandro.j.jimenez@oracle.com>
[Split the series differently, with -action based on the QMP command. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
MAINTAINERS | 2 ++
include/sysemu/runstate-action.h | 18 ++++++++++
include/sysemu/sysemu.h | 2 --
monitor/qmp-cmds.c | 3 +-
qapi/run-state.json | 58 ++++++++++++++++++++++++++++++++
softmmu/globals.c | 2 --
softmmu/meson.build | 1 +
softmmu/runstate-action.c | 41 ++++++++++++++++++++++
softmmu/runstate.c | 10 +++---
softmmu/vl.c | 5 +--
ui/sdl2.c | 5 +--
11 files changed, 134 insertions(+), 13 deletions(-)
create mode 100644 include/sysemu/runstate-action.h
create mode 100644 softmmu/runstate-action.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 138b4ed461..1d6ea877be 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2357,6 +2357,7 @@ M: Paolo Bonzini <pbonzini@redhat.com>
S: Maintained
F: include/qemu/main-loop.h
F: include/sysemu/runstate.h
+F: include/sysemu/runstate-action.h
F: util/main-loop.c
F: util/qemu-timer.c
F: softmmu/vl.c
@@ -2365,6 +2366,7 @@ F: softmmu/cpus.c
F: softmmu/cpu-throttle.c
F: softmmu/cpu-timers.c
F: softmmu/icount.c
+F: softmmu/runstate-action.c
F: qapi/run-state.json
Read, Copy, Update (RCU)
diff --git a/include/sysemu/runstate-action.h b/include/sysemu/runstate-action.h
new file mode 100644
index 0000000000..51a461c4ac
--- /dev/null
+++ b/include/sysemu/runstate-action.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2020 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef RUNSTATE_ACTION_H
+#define RUNSTATE_ACTION_H
+
+#include "qapi/qapi-commands-run-state.h"
+
+/* in softmmu/runstate-action.c */
+extern RebootAction reboot_action;
+extern ShutdownAction shutdown_action;
+
+#endif /* RUNSTATE_ACTION_H */
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index e8f463ff30..8fae667172 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -43,8 +43,6 @@ extern int win2k_install_hack;
extern int alt_grab;
extern int ctrl_grab;
extern int graphic_rotate;
-extern int no_shutdown;
-extern int no_reboot;
extern int old_param;
extern int boot_menu;
extern bool boot_strict;
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index d141aaa132..34f7e75b7b 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -26,6 +26,7 @@
#include "ui/vnc.h"
#include "sysemu/kvm.h"
#include "sysemu/runstate.h"
+#include "sysemu/runstate-action.h"
#include "sysemu/arch_init.h"
#include "sysemu/blockdev.h"
#include "sysemu/block-backend.h"
@@ -72,7 +73,7 @@ UuidInfo *qmp_query_uuid(Error **errp)
void qmp_quit(Error **errp)
{
- no_shutdown = 0;
+ shutdown_action = SHUTDOWN_ACTION_POWEROFF;
qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_QMP_QUIT);
}
diff --git a/qapi/run-state.json b/qapi/run-state.json
index a47c500f83..25e82d1be1 100644
--- a/qapi/run-state.json
+++ b/qapi/run-state.json
@@ -325,6 +325,34 @@
'data': [ 'reset', 'shutdown', 'poweroff', 'pause', 'debug', 'none',
'inject-nmi' ] }
+##
+# @RebootAction:
+#
+# Possible QEMU actions upon guest reboot
+#
+# @none: Reset the VM
+#
+# @shutdown: Shutdown the VM and exit
+#
+# Since: 6.0
+##
+{ 'enum': 'RebootAction',
+ 'data': [ 'none', 'shutdown' ] }
+
+##
+# @ShutdownAction:
+#
+# Possible QEMU actions upon guest shutdown
+#
+# @poweroff: Shutdown the VM and exit
+#
+# @pause: pause the VM#
+#
+# Since: 6.0
+##
+{ 'enum': 'ShutdownAction',
+ 'data': [ 'poweroff', 'pause' ] }
+
##
# @watchdog-set-action:
#
@@ -334,6 +362,36 @@
##
{ 'command': 'watchdog-set-action', 'data' : {'action': 'WatchdogAction'} }
+##
+# @set-action:
+#
+# Set the actions that will be taken by the emulator in response to guest
+# events.
+#
+# @reboot: @RebootAction action taken on guest reboot.
+#
+# @shutdown: @ShutdownAction action taken on guest shutdown.
+#
+# @watchdog: @WatchdogAction action taken when watchdog timer expires .
+#
+# Returns: Nothing on success.
+#
+# Since: 6.0
+#
+# Example:
+#
+# -> { "execute": "set-action",
+# "arguments": { "reboot": "shutdown",
+# "shutdown" : "pause",
+# "watchdog": "inject-nmi" } }
+# <- { "return": {} }
+##
+{ 'command': 'set-action',
+ 'data': { '*reboot': 'RebootAction',
+ '*shutdown': 'ShutdownAction',
+ '*watchdog': 'WatchdogAction' },
+ 'allow-preconfig': true }
+
##
# @GUEST_PANICKED:
#
diff --git a/softmmu/globals.c b/softmmu/globals.c
index e62d9cd8da..7d0fc81183 100644
--- a/softmmu/globals.c
+++ b/softmmu/globals.c
@@ -46,8 +46,6 @@ Chardev *parallel_hds[MAX_PARALLEL_PORTS];
int win2k_install_hack;
int singlestep;
int fd_bootchk = 1;
-int no_reboot;
-int no_shutdown;
int graphic_rotate;
QEMUOptionRom option_rom[MAX_OPTION_ROMS];
int nb_option_roms;
diff --git a/softmmu/meson.build b/softmmu/meson.build
index e5865b97cb..2dab6c7eb6 100644
--- a/softmmu/meson.build
+++ b/softmmu/meson.build
@@ -14,6 +14,7 @@ specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: [files(
'qtest.c',
'vl.c',
'cpu-timers.c',
+ 'runstate-action.c',
)])
specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: [files(
diff --git a/softmmu/runstate-action.c b/softmmu/runstate-action.c
new file mode 100644
index 0000000000..44de01adaf
--- /dev/null
+++ b/softmmu/runstate-action.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2020 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "sysemu/runstate-action.h"
+#include "sysemu/watchdog.h"
+#include "qemu/config-file.h"
+#include "qapi/error.h"
+#include "qemu/option_int.h"
+
+RebootAction reboot_action = REBOOT_ACTION_NONE;
+ShutdownAction shutdown_action = SHUTDOWN_ACTION_POWEROFF;
+
+/*
+ * Receives actions to be applied for specific guest events
+ * and sets the internal state as requested.
+ */
+void qmp_set_action(bool has_reboot, RebootAction reboot,
+ bool has_shutdown, ShutdownAction shutdown,
+ bool has_panic, PanicAction panic,
+ bool has_watchdog, WatchdogAction watchdog,
+ Error **errp)
+{
+ if (has_reboot) {
+ reboot_action = reboot;
+ }
+
+ if (has_watchdog) {
+ qmp_watchdog_set_action(watchdog, errp);
+ }
+
+ /* Process shutdown last, in case the panic action needs to be altered */
+ if (has_shutdown) {
+ shutdown_action = shutdown;
+ }
+}
diff --git a/softmmu/runstate.c b/softmmu/runstate.c
index 892f2f679f..bd0522ed9e 100644
--- a/softmmu/runstate.c
+++ b/softmmu/runstate.c
@@ -54,6 +54,7 @@
#include "sysemu/replay.h"
#include "sysemu/reset.h"
#include "sysemu/runstate.h"
+#include "sysemu/runstate-action.h"
#include "sysemu/sysemu.h"
#include "sysemu/tpm.h"
#include "trace.h"
@@ -471,7 +472,7 @@ void qemu_system_guest_panicked(GuestPanicInformation *info)
qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE,
!!info, info);
vm_stop(RUN_STATE_GUEST_PANICKED);
- if (!no_shutdown) {
+ if (shutdown_action == SHUTDOWN_ACTION_POWEROFF) {
qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF,
!!info, info);
qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_PANIC);
@@ -512,7 +513,8 @@ void qemu_system_guest_crashloaded(GuestPanicInformation *info)
void qemu_system_reset_request(ShutdownCause reason)
{
- if (no_reboot && reason != SHUTDOWN_CAUSE_SUBSYSTEM_RESET) {
+ if (reboot_action == REBOOT_ACTION_SHUTDOWN &&
+ reason != SHUTDOWN_CAUSE_SUBSYSTEM_RESET) {
shutdown_requested = reason;
} else {
reset_requested = reason;
@@ -591,7 +593,7 @@ void qemu_system_killed(int signal, pid_t pid)
{
shutdown_signal = signal;
shutdown_pid = pid;
- no_shutdown = 0;
+ shutdown_action = SHUTDOWN_ACTION_POWEROFF;
/* Cannot call qemu_system_shutdown_request directly because
* we are in a signal handler.
@@ -658,7 +660,7 @@ static bool main_loop_should_exit(void)
if (request) {
qemu_kill_report();
qemu_system_shutdown(request);
- if (no_shutdown) {
+ if (shutdown_action == SHUTDOWN_ACTION_PAUSE) {
vm_stop(RUN_STATE_SHUTDOWN);
} else {
return true;
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 20db39b556..04d94da843 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -36,6 +36,7 @@
#include "qemu/uuid.h"
#include "sysemu/reset.h"
#include "sysemu/runstate.h"
+#include "sysemu/runstate-action.h"
#include "sysemu/seccomp.h"
#include "sysemu/tcg.h"
#include "sysemu/xen.h"
@@ -3154,10 +3155,10 @@ void qemu_init(int argc, char **argv, char **envp)
qemu_opts_parse_noisily(olist, "hpet=off", false);
break;
case QEMU_OPTION_no_reboot:
- no_reboot = 1;
+ reboot_action = REBOOT_ACTION_SHUTDOWN;
break;
case QEMU_OPTION_no_shutdown:
- no_shutdown = 1;
+ shutdown_action = SHUTDOWN_ACTION_PAUSE;
break;
case QEMU_OPTION_show_cursor:
warn_report("The -show-cursor option is deprecated. Please "
diff --git a/ui/sdl2.c b/ui/sdl2.c
index a578017268..5e49709283 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -30,6 +30,7 @@
#include "ui/input.h"
#include "ui/sdl2.h"
#include "sysemu/runstate.h"
+#include "sysemu/runstate-action.h"
#include "sysemu/sysemu.h"
#include "ui/win32-kbd-hook.h"
@@ -606,7 +607,7 @@ static void handle_windowevent(SDL_Event *ev)
allow_close = false;
}
if (allow_close) {
- no_shutdown = 0;
+ shutdown_action = SHUTDOWN_ACTION_POWEROFF;
qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_UI);
}
} else {
@@ -653,7 +654,7 @@ void sdl2_poll_events(struct sdl2_console *scon)
allow_close = false;
}
if (allow_close) {
- no_shutdown = 0;
+ shutdown_action = SHUTDOWN_ACTION_POWEROFF;
qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_UI);
}
break;
--
2.26.2
next prev parent reply other threads:[~2020-12-15 18:08 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-15 17:54 [PULL 00/45] Misc patches for 2020-12-15 Paolo Bonzini
2020-12-15 17:54 ` [PULL 01/45] remove preconfig state Paolo Bonzini
2020-12-15 17:54 ` [PULL 02/45] vl: remove separate preconfig main_loop Paolo Bonzini
2020-12-19 21:30 ` Laurent Vivier
2020-12-20 8:52 ` Paolo Bonzini
2020-12-15 17:54 ` [PULL 03/45] vl: allow -incoming defer with -preconfig Paolo Bonzini
2020-12-15 17:54 ` [PULL 04/45] vl: extract softmmu/runstate.c Paolo Bonzini
2020-12-15 17:54 ` [PULL 05/45] vl: extract softmmu/globals.c Paolo Bonzini
2020-12-15 17:54 ` [PULL 06/45] vl: move all generic initialization out of vl.c Paolo Bonzini
2020-12-15 17:54 ` [PULL 07/45] chardev: do not use machine_init_done Paolo Bonzini
2020-12-15 17:54 ` [PULL 08/45] machine: introduce MachineInitPhase Paolo Bonzini
2020-12-15 17:54 ` [PULL 09/45] ppc/spapr: cleanup -machine pseries,nvdimm=X handling Paolo Bonzini
2020-12-15 17:54 ` [PULL 10/45] vl: make qemu_get_machine_opts static Paolo Bonzini
2020-12-15 17:54 ` [PULL 11/45] plugin: propagate errors Paolo Bonzini
2020-12-15 17:54 ` [PULL 12/45] memory: allow creating MemoryRegions before accelerators Paolo Bonzini
2020-12-15 17:54 ` [PULL 13/45] monitor: allow quitting while in preconfig state Paolo Bonzini
2020-12-15 17:54 ` Paolo Bonzini [this message]
2020-12-15 17:54 ` [PULL 15/45] vl: Add an -action option specifying response to guest events Paolo Bonzini
2020-12-15 17:54 ` [PULL 16/45] vl: Add option to avoid stopping VM upon guest panic Paolo Bonzini
2021-01-19 21:34 ` Peter Maydell
2021-01-20 5:28 ` Alejandro Jimenez
2021-01-20 13:47 ` Peter Maydell
2021-01-20 13:54 ` Daniel P. Berrangé
2021-01-20 14:47 ` Paolo Bonzini
2021-01-20 13:58 ` Paolo Bonzini
2020-12-15 17:54 ` [PULL 17/45] qtest/pvpanic: Test panic option that allows VM to continue Paolo Bonzini
2020-12-15 17:54 ` [PULL 18/45] msix: assert that accesses are within bounds Paolo Bonzini
2020-12-15 17:54 ` [PULL 19/45] memory: clamp cached translation in case it points to an MMIO region Paolo Bonzini
2021-01-13 13:27 ` Michael S. Tsirkin
2020-12-15 17:54 ` [PULL 20/45] accel/tcg: Remove deprecated '-tb-size' option Paolo Bonzini
2020-12-15 17:54 ` [PULL 21/45] docs/system: Move the list of removed features to a separate file Paolo Bonzini
2020-12-15 17:54 ` [PULL 22/45] Remove the deprecated -realtime option Paolo Bonzini
2020-12-15 17:54 ` [PULL 23/45] Remove the deprecated -show-cursor option Paolo Bonzini
2020-12-15 17:54 ` [PULL 24/45] icount: improve exec nocache usage Paolo Bonzini
2020-12-15 17:54 ` [PULL 25/45] scsi: fix device removal race vs IO restart callback on resume Paolo Bonzini
2020-12-15 17:54 ` [PULL 26/45] kvm: Take into account the unaligned section size when preparing bitmap Paolo Bonzini
2020-12-15 17:54 ` [PULL 27/45] qemu-option: simplify search for end of key Paolo Bonzini
2020-12-15 17:54 ` [PULL 28/45] qemu-option: pass QemuOptsList to opts_accepts_any Paolo Bonzini
2020-12-15 17:54 ` [PULL 29/45] vl: rename local variable in configure_accelerators Paolo Bonzini
2020-12-15 17:54 ` [PULL 30/45] docs: set CONFDIR when running sphinx Paolo Bonzini
2020-12-15 17:54 ` [PULL 31/45] hw/core: Restrict 'fw-path-provider.c' to system mode emulation Paolo Bonzini
2020-12-15 17:54 ` [PULL 32/45] qemu/atomic: Drop special case for unsupported compiler Paolo Bonzini
2020-12-15 17:54 ` [PULL 33/45] accel/tcg: Remove special case for GCC < 4.6 Paolo Bonzini
2020-12-15 17:54 ` [PULL 34/45] compiler.h: remove GCC < 3 __builtin_expect fallback Paolo Bonzini
2020-12-15 17:54 ` [PULL 35/45] qemu-plugin.h: remove GCC < 4 Paolo Bonzini
2020-12-15 17:54 ` [PULL 36/45] tests: remove GCC < 4 fallbacks Paolo Bonzini
2020-12-15 17:54 ` [PULL 37/45] virtiofsd: replace _Static_assert with QEMU_BUILD_BUG_ON Paolo Bonzini
2020-12-15 17:54 ` [PULL 38/45] compiler.h: explicit case for Clang printf attribute Paolo Bonzini
2020-12-15 17:54 ` [PULL 39/45] poison: remove GNUC check Paolo Bonzini
2020-12-15 17:54 ` [PULL 40/45] xen: " Paolo Bonzini
2020-12-15 17:54 ` [PULL 41/45] compiler: " Paolo Bonzini
2020-12-15 17:54 ` [PULL 42/45] linux-user: " Paolo Bonzini
2020-12-15 17:54 ` [PULL 43/45] compiler.h: remove QEMU_GNUC_PREREQ Paolo Bonzini
2020-12-15 17:54 ` [PULL 44/45] scripts/git.orderfile: Keep files with .inc extension sorted Paolo Bonzini
2020-12-15 17:54 ` [PULL 45/45] build: -no-pie is no functional linker flag Paolo Bonzini
2020-12-16 10:55 ` [PULL 00/45] Misc patches for 2020-12-15 Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201215175445.1272776-15-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=alejandro.j.jimenez@oracle.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).