Skip to contentSkip to conversation

runstate: cleanup reboot and panic actions

PATCH In review Paolo Bonzini 4 participants 4 messages Jan 20, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 runstate: cleanup reboot and panic actions

The possible choices for panic, reset and watchdog actions are inconsistent.

"-action panic=poweroff" should be renamed to "-action panic=shutdown" on the command line. This is because "-action panic=poweroff" and "-action watchdog=poweroff" have slightly different semantics, the first does an unorderly exit while the second goes through qemu_cleanup(). With this change, -no-shutdown would not have to change "-action panic=pause" "pause", just like it does not have to change the reset action.

"-action reboot=none" should be renamed to "-action reboot=reset". This should be self explanatory, since for example "-action panic=none" lets the guest proceed without taking any action.

---
 qapi/run-state.json       | 10 ++++++----
 qemu-options.hx           |  8 ++++----
 softmmu/runstate-action.c |  4 ++--
 softmmu/runstate.c        |  7 ++++---
 softmmu/vl.c              |  2 +-
 5 files changed, 17 insertions(+), 14 deletions(-)
qapi/run-state.json +6 -4
index 1f3b329f05..43d66d700f 100644
@@ -330,14 +330,14 @@
 #
 # Possible QEMU actions upon guest reboot
 #
-# @none: Reset the VM
+# @reset: Reset the VM
 #
-# @shutdown: Shutdown the VM and exit
+# @shutdown: Shutdown the VM and exit, according to the shutdown action
 #
 # Since: 6.0
 ##
 { 'enum': 'RebootAction',
-  'data': [ 'none', 'shutdown' ] }
+  'data': [ 'reset', 'shutdown' ] }
 
 ##
 # @ShutdownAction:
@@ -360,10 +360,12 @@
 #
 # @pause: Pause the VM
 #
+# @shutdown: Shutdown the VM and exit, according to the shutdown action
+#
 # Since: 6.0
 ##
 { 'enum': 'PanicAction',
-  'data': [ 'poweroff', 'pause', 'none' ] }
+  'data': [ 'pause', 'shutdown', 'none' ] }
 
 ##
 # @watchdog-set-action:
qemu-options.hx +4 -4
index 62791f56d8..9172d51659 100644
@@ -3900,12 +3900,12 @@ SRST
 ERST
 
 DEF("action", HAS_ARG, QEMU_OPTION_action,
-    "-action reboot=none|shutdown\n"
-    "                   action when guest reboots [default=none]\n"
+    "-action reboot=reset|shutdown\n"
+    "                   action when guest reboots [default=reset]\n"
     "-action shutdown=poweroff|pause\n"
     "                   action when guest shuts down [default=poweroff]\n"
-    "-action panic=poweroff|pause|none\n"
-    "                   action when guest panics [default=poweroff]\n"
+    "-action panic=pause|shutdown|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",
     QEMU_ARCH_ALL)
softmmu/runstate-action.c +2 -2
index 99ce880886..ae0761a9c3 100644
@@ -13,9 +13,9 @@
 #include "qapi/error.h"
 #include "qemu/option_int.h"
 
-RebootAction reboot_action = REBOOT_ACTION_NONE;
+RebootAction reboot_action = REBOOT_ACTION_RESET;
 ShutdownAction shutdown_action = SHUTDOWN_ACTION_POWEROFF;
-PanicAction panic_action = PANIC_ACTION_POWEROFF;
+PanicAction panic_action = PANIC_ACTION_SHUTDOWN;
 
 /*
  * Receives actions to be applied for specific guest events
softmmu/runstate.c +4 -3
index 6177693a30..beee050815 100644
@@ -471,14 +471,15 @@ void qemu_system_guest_panicked(GuestPanicInformation *info)
     }
     /*
      * TODO:  Currently the available panic actions are: none, pause, and
-     * poweroff, but in principle debug and reset could be supported as well.
+     * shutdown, but in principle debug and reset could be supported as well.
      * Investigate any potential use cases for the unimplemented actions.
      */
-    if (panic_action == PANIC_ACTION_PAUSE) {
+    if (panic_action == PANIC_ACTION_PAUSE
+        || (panic_action == PANIC_ACTION_SHUTDOWN && shutdown_action == SHUTDOWN_ACTION_PAUSE)) {
         qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE,
                                         !!info, info);
         vm_stop(RUN_STATE_GUEST_PANICKED);
-    } else if (panic_action == PANIC_ACTION_POWEROFF) {
+    } else if (panic_action == PANIC_ACTION_SHUTDOWN) {
         qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF,
                                        !!info, info);
         vm_stop(RUN_STATE_GUEST_PANICKED);
softmmu/vl.c +1 -1
index 7ddf405d76..59304261cf 100644
@@ -3202,7 +3202,7 @@ void qemu_init(int argc, char **argv, char **envp)
                 break;
             case QEMU_OPTION_no_shutdown:
                 olist = qemu_find_opts("action");
-                qemu_opts_parse_noisily(olist, "panic=pause,shutdown=pause", false);
+                qemu_opts_parse_noisily(olist, "shutdown=pause", false);
                 break;
             case QEMU_OPTION_uuid:
                 if (qemu_uuid_parse(optarg, &qemu_uuid) < 0) {
Signature · 1 line
2.29.2
#1 lore raw
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [PATCH] runstate: cleanup reboot and panic actions

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu

 - [tag update]      patchew/[email protected] -> patchew/[email protected]
 - [tag update]      patchew/[email protected] -> patchew/[email protected]
 - [tag update]      patchew/[email protected] -> patchew/[email protected]
 - [tag update]      patchew/[email protected] -> patchew/[email protected]
 * [new tag]         patchew/[email protected] -> patchew/[email protected]

Switched to a new branch 'test'
202e902 runstate: cleanup reboot and panic actions

=== OUTPUT BEGIN ===
ERROR: line over 90 characters
#117: FILE: softmmu/runstate.c:478:
+ || (panic_action == PANIC_ACTION_SHUTDOWN && shutdown_action == SHUTDOWN_ACTION_PAUSE)) {

total: 1 errors, 0 warnings, 83 lines checked

Commit 202e902ccc44 (runstate: cleanup reboot and panic actions) has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

Reviewed-by on v1 1/1
#2 lore raw
In reply to Paolo Bonzini
Quoted 31 lines · Paolo Bonzini

The possible choices for panic, reset and watchdog actions are inconsistent.

"-action panic=poweroff" should be renamed to "-action panic=shutdown" on the command line. This is because "-action panic=poweroff" and "-action watchdog=poweroff" have slightly different semantics, the first does an unorderly exit while the second goes through qemu_cleanup(). With this change, -no-shutdown would not have to change "-action panic=pause" "pause", just like it does not have to change the reset action.

"-action reboot=none" should be renamed to "-action reboot=reset". This should be self explanatory, since for example "-action panic=none" lets the guest proceed without taking any action.

---
 qapi/run-state.json       | 10 ++++++----
 qemu-options.hx           |  8 ++++----
 softmmu/runstate-action.c |  4 ++--
 softmmu/runstate.c        |  7 ++++---
 softmmu/vl.c              |  2 +-
 5 files changed, 17 insertions(+), 14 deletions(-)
qapi/run-state.json +0 -1
index 1f3b329f05..43d66d700f 100644
@@ -330,14 +330,14 @@
 #
 # Possible QEMU actions upon guest reboot
 #
-# @none: Reset the VM

qapi/run-state.json line 340

Quoted 10 lines
qapi/run-state.json +3 -2
+# @reset: Reset the VM
 #
-# @shutdown: Shutdown the VM and exit
+# @shutdown: Shutdown the VM and exit, according to the shutdown action
 #
 # Since: 6.0
 ##
 { 'enum': 'RebootAction',
-  'data': [ 'none', 'shutdown' ] }
+  'data': [ 'reset', 'shutdown' ] }

Given that the enum is new, we are not locked into back-compat, so changing the names to be consistent is reasonable.

Reviewed-by Eric Blake <eblake$redhat.com>

qapi/run-state.json void qemu_system_guest_panicked(GuestPanicInformation *info) · line 478

Quoted 12 lines
qapi/run-state.json +4 -2
+++ b/softmmu/runstate.c
@@ -471,14 +471,15 @@ void qemu_system_guest_panicked(GuestPanicInformation *info)
     }
     /*
      * TODO:  Currently the available panic actions are: none, pause, and
-     * poweroff, but in principle debug and reset could be supported as well.
+     * shutdown, but in principle debug and reset could be supported as well.
      * Investigate any potential use cases for the unimplemented actions.
      */
-    if (panic_action == PANIC_ACTION_PAUSE) {
+    if (panic_action == PANIC_ACTION_PAUSE
+        || (panic_action == PANIC_ACTION_SHUTDOWN && shutdown_action == SHUTDOWN_ACTION_PAUSE)) {

Long line.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
Reviewed-by on v1 1/1
#3 lore raw
In reply to Paolo Bonzini
Quoted 29 lines · Paolo Bonzini

The possible choices for panic, reset and watchdog actions are inconsistent.

"-action panic=poweroff" should be renamed to "-action panic=shutdown" on the command line. This is because "-action panic=poweroff" and "-action watchdog=poweroff" have slightly different semantics, the first does an unorderly exit while the second goes through qemu_cleanup(). With this change, -no-shutdown would not have to change "-action panic=pause" "pause", just like it does not have to change the reset action.

"-action reboot=none" should be renamed to "-action reboot=reset". This should be self explanatory, since for example "-action panic=none" lets the guest proceed without taking any action.

---
  qapi/run-state.json       | 10 ++++++----
  qemu-options.hx           |  8 ++++----
  softmmu/runstate-action.c |  4 ++--
  softmmu/runstate.c        |  7 ++++---
  softmmu/vl.c              |  2 +-
  5 files changed, 17 insertions(+), 14 deletions(-)
softmmu/runstate-action.c +0 -0
index 99ce880886..ae0761a9c3 100644
@@ -13,9 +13,9 @@
  #include "qapi/error.h"

softmmu/runstate-action.c line 21

Quoted 10 lines
softmmu/runstate-action.c +2 -2
  #include "qemu/option_int.h"
 
-RebootAction reboot_action = REBOOT_ACTION_NONE;
+RebootAction reboot_action = REBOOT_ACTION_RESET;
  ShutdownAction shutdown_action = SHUTDOWN_ACTION_POWEROFF;
-PanicAction panic_action = PANIC_ACTION_POWEROFF;
+PanicAction panic_action = PANIC_ACTION_SHUTDOWN;
 
  /*
   * Receives actions to be applied for specific guest events

Hi Paolo,
Since you have removed the need for "fixing" the panic action when -no-shutdown (or its equivalent action/qmp command) is issued, I'd also remove the following comment on qmp_set_action():

     /* Process shutdown last, in case the panic action needs to be altered */ if (has_shutdown) {
         shutdown_action = shutdown;
     }

Quoted 13 lines
softmmu/runstate.c +1 -2
index 6177693a30..beee050815 100644
@@ -471,14 +471,15 @@ void qemu_system_guest_panicked(GuestPanicInformation *info)
      }
      /*
       * TODO:  Currently the available panic actions are: none, pause, and
-     * poweroff, but in principle debug and reset could be supported as well.
+     * shutdown, but in principle debug and reset could be supported as well.
       * Investigate any potential use cases for the unimplemented actions.
       */
-    if (panic_action == PANIC_ACTION_PAUSE) {

softmmu/runstate.c void qemu_system_guest_panicked(GuestPanicInformation *info) · line 485

Quoted 10 lines
softmmu/runstate.c +3 -1
+    if (panic_action == PANIC_ACTION_PAUSE
+        || (panic_action == PANIC_ACTION_SHUTDOWN && shutdown_action == SHUTDOWN_ACTION_PAUSE)) {
          qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE,
                                          !!info, info);
          vm_stop(RUN_STATE_GUEST_PANICKED);
-    } else if (panic_action == PANIC_ACTION_POWEROFF) {
+    } else if (panic_action == PANIC_ACTION_SHUTDOWN) {
          qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF,
                                         !!info, info);
          vm_stop(RUN_STATE_GUEST_PANICKED);

I see that you are moving forward with only sending the GUEST_PANICKED event once.

Quoted 13 lines
softmmu/vl.c +1 -1
index 7ddf405d76..59304261cf 100644
@@ -3202,7 +3202,7 @@ void qemu_init(int argc, char **argv, char **envp)
                  break;
              case QEMU_OPTION_no_shutdown:
                  olist = qemu_find_opts("action");
-                qemu_opts_parse_noisily(olist, "panic=pause,shutdown=pause", false);
+                qemu_opts_parse_noisily(olist, "shutdown=pause", false);
                  break;
              case QEMU_OPTION_uuid:
                  if (qemu_uuid_parse(optarg, &qemu_uuid) < 0) {