qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 3/4] qmp: Allow setting -action parameters on the fly


From: Paolo Bonzini
Subject: Re: [PATCH v2 3/4] qmp: Allow setting -action parameters on the fly
Date: Wed, 9 Dec 2020 22:43:13 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0

On 09/12/20 18:52, Alejandro Jimenez wrote:
+# Set the action that will be taken by the emulator in response to a guest
+# event.
+#
+# @pair: a @RunStateAction type that describes an event|action pair.
+#
+# Returns: Nothing on success.
+#
+# Since: 6.0
+#
+# Example:
+#
+# -> { "execute": "set-action",
+#         "arguments": { "pair": {
+#             "event": "shutdown",
+#             "action": "pause" } } }
+# <- { "return": {} }
+##
+{ 'command': 'set-action', 'data' : {'pair': 'RunStateAction'} }
+
+##
  # @GUEST_PANICKED:
  #
  # Emitted when guest OS panic is detected
diff --git a/softmmu/runstate-action.c b/softmmu/runstate-action.c
index a644d80..7877e7e 100644
--- a/softmmu/runstate-action.c
+++ b/softmmu/runstate-action.c
@@ -80,6 +80,35 @@ static void panic_set_action(PanicAction action, Error 
**errp)
  }
/*
+ * Receives a RunStateAction type which represents an event|action pair
+ * and sets the internal state as requested.
+ */
+void qmp_set_action(RunStateAction *pair, Error **errp)
+{
+    switch (pair->event) {
+    case RUN_STATE_EVENT_TYPE_REBOOT:
+        reboot_set_action(pair->u.reboot.action, NULL);
+        break;
+    case RUN_STATE_EVENT_TYPE_SHUTDOWN:
+        shutdown_set_action(pair->u.shutdown.action, NULL);
+        break;
+    case RUN_STATE_EVENT_TYPE_PANIC:
+        panic_set_action(pair->u.panic.action, NULL);
+        break;
+    case RUN_STATE_EVENT_TYPE_WATCHDOG:
+        qmp_watchdog_set_action(pair->u.watchdog.action, NULL);
+        break;
+    default:
+        /*
+         * The fields in the RunStateAction argument are validated
+         * by the QMP marshalling code before this function is called.
+         * This case is unreachable unless new variants are added.
+         */
+        g_assert_not_reached();
+    }
+}
+

Any reason not to have the multiple optional arguments as discussed in v1 (no reply usually means you agree)? The implementation would be nice, like

    if (actions->has_reboot) {
        reboot_set_action(actions->reboot);
    }
    etc.

?

Note that, in patches 1-2, you don't need to add an Error** argument to functions that cannot fail.

Thanks,

Paolo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]