+++ This bug was initially created as a clone of Bug #1384007 +++
Description of problem:
When a libvirt managed qemu process gets signaled to quit, libvirt reports the same lifecylce event as if the guest operating system shuts down.
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. Create a virtual machine with a guest operating system (e.g. Linux)
2. Start the virtual machine
3. virsh -r event <DOMID> --all
4. Get PID for the qemu process of that VM
5. kill -15 $PID
event 'lifecycle' for domain <DOMAINNAME>: Shutdown Finished
A different event detail that allows to distinguish a shutdown from within the Virtual Machine from a process quit via signal from the hypervisor side.
--- Additional comment from Red Hat Bugzilla Rules Engine on 2016-10-12 07:27:15 EDT ---
Since this bug report was entered in Red Hat Bugzilla, the release flag has been set to ? to ensure that it is properly evaluated for this release.
--- Additional comment from Martin Kletzander on 2017-02-03 02:38:25 EST ---
Just a quick test for the two cases shows:
On 'virsh shutdown domain' QEMU sends us:
whether on 'kill $domain_pid' we get:
So there are two problems. First is that the difference comes *after* the point where we consider the domain to be shut down (and we have already emitted the libvirt event). More importantly, this is not guaranteed to happen (I just tried it once) and none of the differences (the stop or the second shutdown) make sense after SHUTDOWN was recieved.
The only way to differentiate this would be by adding information to the event in QEMU. So I'm cloning this BZ to QEMU for the requested support.
On the qemu side, the QMP command 'system_powerdown' (invoked by 'virsh shutdown' if the guest agent is not present) sets the global powerdown_requested, which in turn triggers a call to qemu_system_powerdown(), and that sends the first qemu_event_send_powerdown() event seen by libvirt as POWERDOWN prior to iterating through any registered powerdown_notifiers; one of those notifiers then results in the ACPI signal seen by the guest; the guest (normally) reacts by shutting down and eventually triggers the next round of events sent by qemu when qemu_system_shutdown_request() is reached. Or, if the guest agent is active, system_powerdown is skipped, but it is still a guest action that triggers qemu_system_shutdown_request(). Either way, the global shutdown_requested is set to 1, although shutdown_signal is left unchanged.
Meanwhile, the SIGTERM handler termsig_handler() calls qemu_system_killed(), which sets the global shutdown_requested but also shutdown_signal, and in turn lets main_loop_should_exit() send qemu_event_send_shutdown() seen as a SHUTDOWN event by libvirt.
Ultimately, since the global shutdown_requested is used through both code paths, the only thing that qemu could do differently is to enhance the SHUTDOWN event that it emits to report the presence of a shutdown signal, based on whether the global shutdown_signal was set at the time the event is emitted. Such a change is a new feature, though, so it would NOT make qemu 2.9. I will propose it upstream, and it could be backported to RHEV if upstream agrees to it, but then libvirt still has to have a patch to be taught to make use of that bit of information.
Missed qemu 2.9; but simple enough to still be backported if upstream approves the idea
v9 will probably be upstream soon:
Backport is here:
Fix included in qemu-kvm-rhev-2.9.0-9.el7
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.
For information on the advisory, and where to find the updated
files, follow the link below.
If the solution does not work for you, open a new bug report.