diff options
author | Alejandro Jimenez <alejandro.j.jimenez@oracle.com> | 2020-12-11 11:52:43 -0500 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2020-12-15 12:51:57 -0500 |
commit | e6dba0481363ad343c5f984dd4de3dd06d79ee68 (patch) | |
tree | 8c970cec81095fd7cb39f9b8b011f335f4bf5ec2 /softmmu | |
parent | ebe3444468a4913e0208db1f74ea9336c7580202 (diff) |
qmp: generalize watchdog-set-action to -no-reboot/-no-shutdown
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>
Diffstat (limited to 'softmmu')
-rw-r--r-- | softmmu/globals.c | 2 | ||||
-rw-r--r-- | softmmu/meson.build | 1 | ||||
-rw-r--r-- | softmmu/runstate-action.c | 41 | ||||
-rw-r--r-- | softmmu/runstate.c | 10 | ||||
-rw-r--r-- | softmmu/vl.c | 5 |
5 files changed, 51 insertions, 8 deletions
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 " |