From nobody Tue May 7 12:36:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1494942672368238.78328459780505; Tue, 16 May 2017 06:51:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 80D8040F00; Tue, 16 May 2017 13:50:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 04E3887E20; Tue, 16 May 2017 13:50:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9390A4A48C; Tue, 16 May 2017 13:50:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4GDo1hg026412 for ; Tue, 16 May 2017 09:50:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id AA25158823; Tue, 16 May 2017 13:50:01 +0000 (UTC) Received: from caroline.brq.redhat.com (dhcp129-198.brq.redhat.com [10.34.129.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id D283817258; Tue, 16 May 2017 13:49:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 80D8040F00 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 80D8040F00 From: Martin Kletzander To: libvir-list@redhat.com Date: Tue, 16 May 2017 15:49:54 +0200 Message-Id: <945092d5c52b8d13dafe22e02fb63a05e844ea1e.1494942424.git.mkletzan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2] qemu: Report shutdown event details X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 16 May 2017 13:51:05 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" QEMU will likely report the details of it shutting down, particularly whether the shutdown was initiated by the guest or host. We should forward that information along, at least for shutdown events. Reset has that as well, however that is not a lifecycle event and would add extra constants that might not be used. It can be added later on. Since the only way we can extend information provided to the user is adding event details, we might as well emit multiple events (one with the reason for the shutdown and keep the one for the shutdown being finished for clarity and compatibility). Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1384007 Signed-off-by: Martin Kletzander --- v2: - Adapt to new message format Patch in QEMU: https://lists.gnu.org/archive/html/qemu-devel/2017-05= /msg03624.html Applied to qapi-next: https://lists.gnu.org/archive/html/qemu-devel/2017-05= /msg03742.html examples/object-events/event-test.c | 6 ++++++ include/libvirt/libvirt-domain.h | 11 ++++++++++- src/qemu/qemu_monitor.c | 6 +++--- src/qemu/qemu_monitor.h | 3 ++- src/qemu/qemu_monitor_json.c | 10 ++++++++-- src/qemu/qemu_process.c | 22 ++++++++++++++++++++++ tools/virsh-domain.c | 5 ++++- 7 files changed, 55 insertions(+), 8 deletions(-) diff --git a/examples/object-events/event-test.c b/examples/object-events/e= vent-test.c index 12690cac09ce..d3a81eb4a559 100644 --- a/examples/object-events/event-test.c +++ b/examples/object-events/event-test.c @@ -240,6 +240,12 @@ eventDetailToString(int event, case VIR_DOMAIN_EVENT_SHUTDOWN_FINISHED: return "Finished"; + case VIR_DOMAIN_EVENT_SHUTDOWN_GUEST: + return "Killed on a guest request"; + + case VIR_DOMAIN_EVENT_SHUTDOWN_HOST: + return "Killed on a host request"; + case VIR_DOMAIN_EVENT_SHUTDOWN_LAST: break; } diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index c9e96a6c90bc..de391a9214d1 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -2983,7 +2983,16 @@ typedef enum { * Details on the cause of a 'shutdown' lifecycle event */ typedef enum { - VIR_DOMAIN_EVENT_SHUTDOWN_FINISHED =3D 0, /* Guest finished shutdown s= equence */ + /* Guest finished shutdown sequence */ + VIR_DOMAIN_EVENT_SHUTDOWN_FINISHED =3D 0, + + /* Guest is shutting down due to request from guest (e.g. hardware-spe= cific + * action) */ + VIR_DOMAIN_EVENT_SHUTDOWN_GUEST =3D 1, + + /* Guest is shutting down due to request from host (e.g. killed by a + * signal) */ + VIR_DOMAIN_EVENT_SHUTDOWN_HOST =3D 2, # ifdef VIR_ENUM_SENTINELS VIR_DOMAIN_EVENT_SHUTDOWN_LAST diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 2148d483ed6a..a2de1a6c5bad 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -1326,13 +1326,13 @@ qemuMonitorEmitEvent(qemuMonitorPtr mon, const char= *event, int -qemuMonitorEmitShutdown(qemuMonitorPtr mon) +qemuMonitorEmitShutdown(qemuMonitorPtr mon, virTristateBool guest) { int ret =3D -1; - VIR_DEBUG("mon=3D%p", mon); + VIR_DEBUG("mon=3D%p guest=3D%u", mon, guest); mon->willhangup =3D 1; - QEMU_MONITOR_CALLBACK(mon, ret, domainShutdown, mon->vm); + QEMU_MONITOR_CALLBACK(mon, ret, domainShutdown, mon->vm, guest); return ret; } diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 12f98beba763..8956bf929aaa 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -130,6 +130,7 @@ typedef int (*qemuMonitorDomainEventCallback)(qemuMonit= orPtr mon, void *opaque); typedef int (*qemuMonitorDomainShutdownCallback)(qemuMonitorPtr mon, virDomainObjPtr vm, + virTristateBool guest, void *opaque); typedef int (*qemuMonitorDomainResetCallback)(qemuMonitorPtr mon, virDomainObjPtr vm, @@ -344,7 +345,7 @@ int qemuMonitorGetDiskSecret(qemuMonitorPtr mon, int qemuMonitorEmitEvent(qemuMonitorPtr mon, const char *event, long long seconds, unsigned int micros, const char *details); -int qemuMonitorEmitShutdown(qemuMonitorPtr mon); +int qemuMonitorEmitShutdown(qemuMonitorPtr mon, virTristateBool guest); int qemuMonitorEmitReset(qemuMonitorPtr mon); int qemuMonitorEmitPowerdown(qemuMonitorPtr mon); int qemuMonitorEmitStop(qemuMonitorPtr mon); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 083729003ba3..757595dd7472 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -523,9 +523,15 @@ qemuMonitorJSONKeywordStringToJSON(const char *str, co= nst char *firstkeyword) } -static void qemuMonitorJSONHandleShutdown(qemuMonitorPtr mon, virJSONValue= Ptr data ATTRIBUTE_UNUSED) +static void qemuMonitorJSONHandleShutdown(qemuMonitorPtr mon, virJSONValue= Ptr data) { - qemuMonitorEmitShutdown(mon); + bool guest =3D false; + virTristateBool guest_initiated =3D VIR_TRISTATE_BOOL_ABSENT; + + if (virJSONValueObjectGetBoolean(data, "guest", &guest) =3D=3D 0) + guest_initiated =3D guest ? VIR_TRISTATE_BOOL_YES : VIR_TRISTATE_B= OOL_NO; + + qemuMonitorEmitShutdown(mon, guest_initiated); } static void qemuMonitorJSONHandleReset(qemuMonitorPtr mon, virJSONValuePtr= data ATTRIBUTE_UNUSED) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index c19bd292596a..f7248dac9b89 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -634,10 +634,12 @@ qemuProcessHandleEvent(qemuMonitorPtr mon ATTRIBUTE_U= NUSED, static int qemuProcessHandleShutdown(qemuMonitorPtr mon ATTRIBUTE_UNUSED, virDomainObjPtr vm, + virTristateBool guest_initiated, void *opaque) { virQEMUDriverPtr driver =3D opaque; qemuDomainObjPrivatePtr priv; + virObjectEventPtr pre_event =3D NULL; virObjectEventPtr event =3D NULL; virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); @@ -662,6 +664,25 @@ qemuProcessHandleShutdown(qemuMonitorPtr mon ATTRIBUTE= _UNUSED, virDomainObjSetState(vm, VIR_DOMAIN_SHUTDOWN, VIR_DOMAIN_SHUTDOWN_UNKNOWN); + + switch (guest_initiated) { + case VIR_TRISTATE_BOOL_YES: + pre_event =3D virDomainEventLifecycleNewFromObj(vm, + VIR_DOMAIN_EVENT_SHUTDOWN, + VIR_DOMAIN_EVENT_SHUTDOWN_= GUEST); + break; + + case VIR_TRISTATE_BOOL_NO: + pre_event =3D virDomainEventLifecycleNewFromObj(vm, + VIR_DOMAIN_EVENT_SHUTDOWN, + VIR_DOMAIN_EVENT_SHUTDOWN_= HOST); + break; + + case VIR_TRISTATE_BOOL_ABSENT: + case VIR_TRISTATE_BOOL_LAST: + break; + } + event =3D virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_SHUTDOWN, VIR_DOMAIN_EVENT_SHUTDOWN_FINISHED); @@ -678,6 +699,7 @@ qemuProcessHandleShutdown(qemuMonitorPtr mon ATTRIBUTE_= UNUSED, unlock: virObjectUnlock(vm); + qemuDomainEventQueue(driver, pre_event); qemuDomainEventQueue(driver, event); virObjectUnref(cfg); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 0d19d0e0126e..f05dcbdac5bc 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -12249,7 +12249,10 @@ VIR_ENUM_IMPL(virshDomainEventStopped, VIR_ENUM_DECL(virshDomainEventShutdown) VIR_ENUM_IMPL(virshDomainEventShutdown, VIR_DOMAIN_EVENT_SHUTDOWN_LAST, - N_("Finished")) + N_("Finished"), + N_("Shutting down on a guest request"), + N_("Shutting down on a host request"), + ) VIR_ENUM_DECL(virshDomainEventPMSuspended) VIR_ENUM_IMPL(virshDomainEventPMSuspended, -- 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list