From: "Alex Bennée" <alex.bennee@linaro.org>
To: peter.maydell@linaro.org, richard.henderson@linaro.org
Cc: qemu-devel@nongnu.org, "Ilya Leoshkevich" <iii@linux.ibm.com>,
"David Hildenbrand" <david@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Eric Blake" <eblake@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [PULL 10/13] qapi: Add exit-failure PanicAction
Date: Fri, 29 Jul 2022 10:19:40 +0100 [thread overview]
Message-ID: <20220729091943.2152410-11-alex.bennee@linaro.org> (raw)
In-Reply-To: <20220729091943.2152410-1-alex.bennee@linaro.org>
From: Ilya Leoshkevich <iii@linux.ibm.com>
Currently QEMU exits with code 0 on both panic an shutdown. For tests
it is useful to return 1 on panic, so that it counts as a test
failure.
Introduce a new exit-failure PanicAction that makes main() return
EXIT_FAILURE. Tests can use -action panic=exit-failure option to
activate this behavior.
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: David Hildenbrand <david@redhat.com>
Message-Id: <20220725223746.227063-2-iii@linux.ibm.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
diff --git a/qapi/run-state.json b/qapi/run-state.json
index 6e2162d7b3..9273ea6516 100644
--- a/qapi/run-state.json
+++ b/qapi/run-state.json
@@ -364,10 +364,13 @@
#
# @shutdown: Shutdown the VM and exit, according to the shutdown action
#
+# @exit-failure: Shutdown the VM and exit with nonzero status
+# (since 7.1)
+#
# Since: 6.0
##
{ 'enum': 'PanicAction',
- 'data': [ 'pause', 'shutdown', 'none' ] }
+ 'data': [ 'pause', 'shutdown', 'exit-failure', 'none' ] }
##
# @watchdog-set-action:
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 812f66a31a..31aa45160b 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -103,7 +103,7 @@ void qemu_boot_set(const char *boot_order, Error **errp);
bool defaults_enabled(void);
void qemu_init(int argc, char **argv, char **envp);
-void qemu_main_loop(void);
+int qemu_main_loop(void);
void qemu_cleanup(void);
extern QemuOptsList qemu_legacy_drive_opts;
diff --git a/softmmu/main.c b/softmmu/main.c
index c00432ff09..1b675a8c03 100644
--- a/softmmu/main.c
+++ b/softmmu/main.c
@@ -32,11 +32,13 @@
int qemu_main(int argc, char **argv, char **envp)
{
+ int status;
+
qemu_init(argc, argv, envp);
- qemu_main_loop();
+ status = qemu_main_loop();
qemu_cleanup();
- return 0;
+ return status;
}
#ifndef CONFIG_COCOA
diff --git a/softmmu/runstate.c b/softmmu/runstate.c
index 168e1b78a0..1e68680b9d 100644
--- a/softmmu/runstate.c
+++ b/softmmu/runstate.c
@@ -482,7 +482,8 @@ void qemu_system_guest_panicked(GuestPanicInformation *info)
qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE,
!!info, info);
vm_stop(RUN_STATE_GUEST_PANICKED);
- } else if (panic_action == PANIC_ACTION_SHUTDOWN) {
+ } else if (panic_action == PANIC_ACTION_SHUTDOWN ||
+ panic_action == PANIC_ACTION_EXIT_FAILURE) {
qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF,
!!info, info);
vm_stop(RUN_STATE_GUEST_PANICKED);
@@ -662,7 +663,7 @@ void qemu_system_debug_request(void)
qemu_notify_event();
}
-static bool main_loop_should_exit(void)
+static bool main_loop_should_exit(int *status)
{
RunState r;
ShutdownCause request;
@@ -680,6 +681,10 @@ static bool main_loop_should_exit(void)
if (shutdown_action == SHUTDOWN_ACTION_PAUSE) {
vm_stop(RUN_STATE_SHUTDOWN);
} else {
+ if (request == SHUTDOWN_CAUSE_GUEST_PANIC &&
+ panic_action == PANIC_ACTION_EXIT_FAILURE) {
+ *status = EXIT_FAILURE;
+ }
return true;
}
}
@@ -715,12 +720,14 @@ static bool main_loop_should_exit(void)
return false;
}
-void qemu_main_loop(void)
+int qemu_main_loop(void)
{
+ int status = EXIT_SUCCESS;
#ifdef CONFIG_PROFILER
int64_t ti;
#endif
- while (!main_loop_should_exit()) {
+
+ while (!main_loop_should_exit(&status)) {
#ifdef CONFIG_PROFILER
ti = profile_getclock();
#endif
@@ -729,6 +736,8 @@ void qemu_main_loop(void)
dev_time += profile_getclock() - ti;
#endif
}
+
+ return status;
}
void qemu_add_exit_notifier(Notifier *notify)
diff --git a/qemu-options.hx b/qemu-options.hx
index 79e00916a1..8e17c5064a 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -4239,7 +4239,7 @@ DEF("action", HAS_ARG, QEMU_OPTION_action,
" action when guest reboots [default=reset]\n"
"-action shutdown=poweroff|pause\n"
" action when guest shuts down [default=poweroff]\n"
- "-action panic=pause|shutdown|none\n"
+ "-action panic=pause|shutdown|exit-failure|none\n"
" action when guest panics [default=shutdown]\n"
"-action watchdog=reset|shutdown|poweroff|inject-nmi|pause|debug|none\n"
" action when watchdog fires [default=reset]\n",
--
2.30.2
next prev parent reply other threads:[~2022-07-29 9:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-29 9:19 [PULL 00/13] testing, semihosting and doc fixes Alex Bennée
2022-07-29 9:19 ` [PULL 01/13] tests: refresh to latest libvirt-ci module Alex Bennée
2022-07-29 9:19 ` [PULL 02/13] gitlab: show testlog.txt contents when cirrus/custom-runner jobs fail Alex Bennée
2022-07-29 9:19 ` [PULL 03/13] gitlab: drop 'containers-layer2' stage Alex Bennée
2022-07-29 9:19 ` [PULL 04/13] .cirrus.yml: Change winsymlinks to 'native' Alex Bennée
2022-07-29 9:19 ` [PULL 05/13] .gitlab-ci.d/windows.yml: Enable native Windows symlink Alex Bennée
2022-07-29 9:19 ` [PULL 06/13] semihosting: Don't return negative values on qemu_semihosting_console_write() failure Alex Bennée
2022-07-29 9:19 ` [PULL 07/13] semihosting: Don't copy buffer after console_write() Alex Bennée
2022-07-29 9:19 ` [PULL 08/13] semihosting: Check for errors on SET_ARG() Alex Bennée
2022-07-29 9:19 ` [PULL 09/13] semihosting: Fix handling of buffer in TARGET_SYS_TMPNAM Alex Bennée
2022-07-29 9:19 ` Alex Bennée [this message]
2022-07-29 9:19 ` [PULL 11/13] tests/tcg/s390x: Test unaligned accesses to lowcore Alex Bennée
2022-07-29 9:19 ` [PULL 12/13] docs/devel: fix description of OBJECT_DECLARE_SIMPLE_TYPE Alex Bennée
2022-07-29 9:19 ` [PULL 13/13] qemu-options: bring the kernel and image options together Alex Bennée
2022-07-29 15:36 ` [PULL 00/13] testing, semihosting and doc fixes Richard Henderson
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=20220729091943.2152410-11-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=armbru@redhat.com \
--cc=david@redhat.com \
--cc=eblake@redhat.com \
--cc=iii@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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).