From d43013e24de2f101f2d878823d78e2c1f8e2d6ed Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Wed, 5 Dec 2018 12:01:29 +0100 Subject: qapi: Turn ShutdownCause into QAPI enum Needed so the patch after next can add ShutdownCause to QMP events SHUTDOWN and RESET. Signed-off-by: Dominik Csapak Message-Id: <20181205110131.23049-2-d.csapak@proxmox.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- qapi/run-state.json | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'qapi') diff --git a/qapi/run-state.json b/qapi/run-state.json index 332e448..de7725b 100644 --- a/qapi/run-state.json +++ b/qapi/run-state.json @@ -60,6 +60,40 @@ 'guest-panicked', 'colo', 'preconfig' ] } ## +# @ShutdownCause: +# +# An enumeration of reasons for a Shutdown. +# +# @none: No shutdown request pending +# +# @host-error: An error prevents further use of guest +# +# @host-qmp: Reaction to a QMP command, like 'quit' +# +# @host-signal: Reaction to a signal, such as SIGINT +# +# @host-ui: Reaction to a UI event, like window close +# +# @guest-shutdown: Guest shutdown/suspend request, via ACPI or other +# hardware-specific means +# +# @guest-reset: Guest reset request, and command line turns that into +# a shutdown +# +# @guest-panic: Guest panicked, and command line turns that into a shutdown +# +# @subsystem-reset: Partial guest reset that does not trigger QMP events and +# ignores --no-reboot. This is useful for sanitizing +# hypercalls on s390 that are used during kexec/kdump/boot +# +## +{ 'enum': 'ShutdownCause', + # Beware, shutdown_caused_by_guest() depends on enumeration order + 'data': [ 'none', 'host-error', 'host-qmp', 'host-signal', 'host-ui', + 'guest-shutdown', 'guest-reset', 'guest-panic', + 'subsystem-reset'] } + +## # @StatusInfo: # # Information about VCPU run state -- cgit v1.1 From ecd7a0d5bbfbbb6922dfe4049227256d1eafa3b8 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Wed, 5 Dec 2018 12:01:30 +0100 Subject: qmp: Add reason to SHUTDOWN and RESET events This makes it possible to determine what the exact reason was for a RESET or a SHUTDOWN. A management layer might need the specific reason of those events to determine which cleanups or other actions it needs to do. This patch also updates the iotests to the new expected output that includes the reason. Signed-off-by: Dominik Csapak Message-Id: <20181205110131.23049-3-d.csapak@proxmox.com> Reviewed-by: Markus Armbruster [Commit message tweaked] Signed-off-by: Markus Armbruster --- qapi/run-state.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'qapi') diff --git a/qapi/run-state.json b/qapi/run-state.json index de7725b..436ba4e 100644 --- a/qapi/run-state.json +++ b/qapi/run-state.json @@ -141,6 +141,8 @@ # a guest-initiated ACPI shutdown request or other hardware-specific action) # rather than a host request (such as sending qemu a SIGINT). (since 2.10) # +# @reason: The @ShutdownCause which resulted in the SHUTDOWN. (since 4.0) +# # Note: If the command-line option "-no-shutdown" has been specified, qemu will # not exit, and a STOP event will eventually follow the SHUTDOWN event # @@ -152,7 +154,7 @@ # "timestamp": { "seconds": 1267040730, "microseconds": 682951 } } # ## -{ 'event': 'SHUTDOWN', 'data': { 'guest': 'bool' } } +{ 'event': 'SHUTDOWN', 'data': { 'guest': 'bool', 'reason': 'ShutdownCause' } } ## # @POWERDOWN: @@ -180,6 +182,8 @@ # rather than a host request (such as the QMP command system_reset). # (since 2.10) # +# @reason: The @ShutdownCause of the RESET. (since 4.0) +# # Since: 0.12.0 # # Example: @@ -188,7 +192,7 @@ # "timestamp": { "seconds": 1267041653, "microseconds": 9518 } } # ## -{ 'event': 'RESET', 'data': { 'guest': 'bool' } } +{ 'event': 'RESET', 'data': { 'guest': 'bool', 'reason': 'ShutdownCause' } } ## # @STOP: -- cgit v1.1 From 9254893882139b9a7738214d669958df4dfeee2f Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Wed, 5 Dec 2018 12:01:31 +0100 Subject: qmp: Split ShutdownCause host-qmp into quit and system-reset It is interesting to know whether the shutdown cause was 'quit' or 'reset', especially when using "--no-reboot". In that case, a management layer can now determine if the guest wanted a reboot or shutdown, and can act accordingly. Changes the output of the reason in the iotests from 'host-qmp' to 'host-qmp-quit'. This does not break compatibility because the field was introduced in the same version. Signed-off-by: Dominik Csapak Message-Id: <20181205110131.23049-4-d.csapak@proxmox.com> Reviewed-by: Markus Armbruster [Commit message tweaked] Signed-off-by: Markus Armbruster --- qapi/run-state.json | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'qapi') diff --git a/qapi/run-state.json b/qapi/run-state.json index 436ba4e..d7477cd 100644 --- a/qapi/run-state.json +++ b/qapi/run-state.json @@ -68,7 +68,9 @@ # # @host-error: An error prevents further use of guest # -# @host-qmp: Reaction to a QMP command, like 'quit' +# @host-qmp-quit: Reaction to the QMP command 'quit' +# +# @host-qmp-system-reset: Reaction to the QMP command 'system_reset' # # @host-signal: Reaction to a signal, such as SIGINT # @@ -89,9 +91,9 @@ ## { 'enum': 'ShutdownCause', # Beware, shutdown_caused_by_guest() depends on enumeration order - 'data': [ 'none', 'host-error', 'host-qmp', 'host-signal', 'host-ui', - 'guest-shutdown', 'guest-reset', 'guest-panic', - 'subsystem-reset'] } + 'data': [ 'none', 'host-error', 'host-qmp-quit', 'host-qmp-system-reset', + 'host-signal', 'host-ui', 'guest-shutdown', 'guest-reset', + 'guest-panic', 'subsystem-reset'] } ## # @StatusInfo: -- cgit v1.1 From 46ea94ca9cfcd56c27efafd2ff32281360e0267f Mon Sep 17 00:00:00 2001 From: Daniel Henrique Barboza Date: Wed, 5 Dec 2018 17:46:59 -0200 Subject: qmp: query-current-machine with wakeup-suspend-support When issuing the qmp/hmp 'system_wakeup' command, what happens in a nutshell is: - qmp_system_wakeup_request set runstate to RUNNING, sets a wakeup_reason and notify the event - in the main_loop, all vcpus are paused, a system reset is issued, all subscribers of wakeup_notifiers receives a notification, vcpus are then resumed and the wake up QAPI event is fired Note that this procedure alone doesn't ensure that the guest will awake from SUSPENDED state - the subscribers of the wake up event must take action to resume the guest, otherwise the guest will simply reboot. At this moment, only the ACPI machines via acpi_pm1_cnt_init and xen_hvm_init have wake-up from suspend support. However, only the presence of 'system_wakeup' is required for QGA to support 'guest-suspend-ram' and 'guest-suspend-hybrid' at this moment. This means that the user/management will expect to suspend the guest using one of those suspend commands and then resume execution using system_wakeup, regardless of the support offered in system_wakeup in the first place. This patch creates a new API called query-current-machine [1], that holds a new flag called 'wakeup-suspend-support' that indicates if the guest supports wake up from suspend via system_wakeup. The machine is considered to implement wake-up support if a call to a new 'qemu_register_wakeup_support' is made during its init, as it is now being done inside acpi_pm1_cnt_init and xen_hvm_init. This allows for any other machine type to declare wake-up support regardless of ACPI state or wakeup_notifiers subscription, making easier for newer implementations that might have their own mechanisms in the future. This is the expected output of query-current-machine when running a x86 guest: {"execute" : "query-current-machine"} {"return": {"wakeup-suspend-support": true}} Running the same x86 guest, but with the --no-acpi option: {"execute" : "query-current-machine"} {"return": {"wakeup-suspend-support": false}} This is the output when running a pseries guest: {"execute" : "query-current-machine"} {"return": {"wakeup-suspend-support": false}} With this extra tool, management can avoid situations where a guest that does not have proper suspend/wake capabilities ends up in inconsistent state (e.g. https://github.com/open-power-host-os/qemu/issues/31). [1] the decision of creating the query-current-machine API is based on discussions in the QEMU mailing list where it was decided that query-target wasn't a proper place to store the wake-up flag, neither was query-machines because this isn't a static property of the machine object. This new API can then be used to store other dynamic machine properties that are scattered around the code ATM. More info at: https://lists.gnu.org/archive/html/qemu-devel/2018-05/msg04235.html Reported-by: Balamuruhan S Signed-off-by: Daniel Henrique Barboza Message-Id: <20181205194701.17836-2-danielhb413@gmail.com> Reviewed-by: Markus Armbruster Acked-by: Eduardo Habkost Signed-off-by: Markus Armbruster --- qapi/misc.json | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'qapi') diff --git a/qapi/misc.json b/qapi/misc.json index 8325e0d..c4696ef 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -2013,6 +2013,30 @@ { 'command': 'query-machines', 'returns': ['MachineInfo'] } ## +# @CurrentMachineParams: +# +# Information describing the running machine parameters. +# +# @wakeup-suspend-support: true if the machine supports wake up from +# suspend +# +# Since: 4.0 +## +{ 'struct': 'CurrentMachineParams', + 'data': { 'wakeup-suspend-support': 'bool'} } + +## +# @query-current-machine: +# +# Return information on the current virtual machine. +# +# Returns: CurrentMachineParams +# +# Since: 4.0 +## +{ 'command': 'query-current-machine', 'returns': 'CurrentMachineParams' } + +## # @CpuDefinitionInfo: # # Virtual CPU definition. -- cgit v1.1 From fb0641121072d9d612773370688a6887bb78db08 Mon Sep 17 00:00:00 2001 From: Daniel Henrique Barboza Date: Wed, 5 Dec 2018 17:47:01 -0200 Subject: qmp hmp: Make system_wakeup check wake-up support and run state The qmp/hmp command 'system_wakeup' is simply a direct call to 'qemu_system_wakeup_request' from vl.c. This function verifies if runstate is SUSPENDED and if the wake up reason is valid before proceeding. However, no error or warning is thrown if any of those pre-requirements isn't met. There is no way for the caller to differentiate between a successful wakeup or an error state caused when trying to wake up a guest that wasn't suspended. This means that system_wakeup is silently failing, which can be considered a bug. Adding error handling isn't an API break in this case - applications that didn't check the result will remain broken, the ones that check it will have a chance to deal with it. Adding to that, the commit before previous created a new QMP API called query-current-machine, with a new flag called wakeup-suspend-support, that indicates if the guest has the capability of waking up from suspended state. Although such guest will never reach SUSPENDED state and erroring it out in this scenario would suffice, it is more informative for the user to differentiate between a failure because the guest isn't suspended versus a failure because the guest does not have support for wake up at all. All this considered, this patch changes qmp_system_wakeup to check if the guest is capable of waking up from suspend, and if it is suspended. After this patch, this is the output of system_wakeup in a guest that does not have wake-up from suspend support (ppc64): (qemu) system_wakeup wake-up from suspend is not supported by this guest (qemu) And this is the output of system_wakeup in a x86 guest that has the support but isn't suspended: (qemu) system_wakeup Unable to wake up: guest is not in suspended state (qemu) Reported-by: Balamuruhan S Signed-off-by: Daniel Henrique Barboza Message-Id: <20181205194701.17836-4-danielhb413@gmail.com> Reviewed-by: Markus Armbruster Acked-by: Eduardo Habkost Reviewed-by: Michael S. Tsirkin Signed-off-by: Markus Armbruster --- qapi/misc.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'qapi') diff --git a/qapi/misc.json b/qapi/misc.json index c4696ef..24d20a8 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -1239,12 +1239,18 @@ ## # @system_wakeup: # -# Wakeup guest from suspend. Does nothing in case the guest isn't suspended. +# Wake up guest from suspend. If the guest has wake-up from suspend +# support enabled (wakeup-suspend-support flag from +# query-current-machine), wake-up guest from suspend if the guest is +# in SUSPENDED state. Return an error otherwise. # # Since: 1.1 # # Returns: nothing. # +# Note: prior to 4.0, this command does nothing in case the guest +# isn't suspended. +# # Example: # # -> { "execute": "system_wakeup" } -- cgit v1.1