[PATCH v4 0/4] Add reboot stopped reason
Report the new VIR_DOMAIN_EVENT_STOPPED_REBOOT reason when reboot has been requested. I have only tested this on Xen. I preferred to rely on the stopped reason, as there is no discussion that it should be sent, while for the reboot event, there is debate that it shouldn't always be sent. CI: https://gitlab.com/libvirt/libvirt/-/merge_requests/567 Previous discussion and patches: https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/thread/ZB5AL... https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/thread/KYAL4... https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/thread/5W4TO... Since last discussion, I: - Joined the libvirt patches so that each patch can build - Joined the drivers patches - Joined the NEWS patches - Fixed the documentation message Ben Grande (4): libvirt: Add stopped reason of reboot docs: libvirt-domain: briefly document reboot event drivers: Propagate stopped reason of reboot NEWS: Introduce VIR_DOMAIN_EVENT_STOPPED_REASON NEWS.rst | 12 ++++++++++++ examples/c/misc/event-test.c | 3 +++ include/libvirt/libvirt-domain.h | 1 + src/libvirt-domain.c | 5 ++++- src/libxl/libxl_domain.c | 2 +- src/lxc/lxc_process.c | 2 +- src/test/test_driver.c | 2 +- tools/virsh-domain-event.c | 3 ++- 8 files changed, 25 insertions(+), 5 deletions(-) -- Benjamin Grande
If domain "on_reboot" is not set to "restart", the listener can be aware of such reboot request and run their own procedures. Resolves: https://github.com/QubesOS/qubes-issues/issues/8196 Signed-off-by: Ben Grande <ben@invisiblethingslab.com> --- examples/c/misc/event-test.c | 3 +++ include/libvirt/libvirt-domain.h | 1 + tools/virsh-domain-event.c | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/c/misc/event-test.c b/examples/c/misc/event-test.c index 3e2b0a7827..1bac8d0cb8 100644 --- a/examples/c/misc/event-test.c +++ b/examples/c/misc/event-test.c @@ -239,6 +239,9 @@ eventDetailToString(int event, case VIR_DOMAIN_EVENT_STOPPED_RECREATED: return "Recreated"; + case VIR_DOMAIN_EVENT_STOPPED_REBOOT: + return "Reboot"; + case VIR_DOMAIN_EVENT_STOPPED_LAST: break; } diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h index 9ee153c6eb..ada0df65a7 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -5778,6 +5778,7 @@ typedef enum { VIR_DOMAIN_EVENT_STOPPED_FAILED = 5, /* Host emulator/mgmt failed (Since: 0.5.0) */ VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT = 6, /* offline snapshot loaded (Since: 0.8.0) */ VIR_DOMAIN_EVENT_STOPPED_RECREATED = 7, /* Secure guest recreation (Since: 11.6.0) */ + VIR_DOMAIN_EVENT_STOPPED_REBOOT = 8, /* Host or guest requested reboot (Since: 12.9.0) */ # ifdef VIR_ENUM_SENTINELS VIR_DOMAIN_EVENT_STOPPED_LAST /* (Since: 0.9.10) */ diff --git a/tools/virsh-domain-event.c b/tools/virsh-domain-event.c index 0e408a11e8..9021cdc0f8 100644 --- a/tools/virsh-domain-event.c +++ b/tools/virsh-domain-event.c @@ -108,7 +108,8 @@ VIR_ENUM_IMPL(virshDomainEventStopped, N_("Saved"), N_("Failed"), N_("Snapshot"), - N_("Recreated")); + N_("Recreated"), + N_("Reboot")); VIR_ENUM_DECL(virshDomainEventShutdown); VIR_ENUM_IMPL(virshDomainEventShutdown, -- Benjamin Grande
For the subject prefix, I'd suggest: include: Introduce VIR_DOMAIN_EVENT_STOPPED_REBOOT detail On 11/9/26 4:47 AM, Ben Grande wrote:
If domain "on_reboot" is not set to "restart", the listener can be aware of such reboot request and run their own procedures.
This only mentions what a listener can do. It should introduce and describe the new detail. E.g. something like: Introduce a new VIR_DOMAIN_EVENT_STOPPED_REBOOT detail for the 'stopped' lifecycle event, which indicates a domain has stopped due to a host or domain OS initiated reboot.
Resolves: https://github.com/QubesOS/qubes-issues/issues/8196 Signed-off-by: Ben Grande <ben@invisiblethingslab.com> --- examples/c/misc/event-test.c | 3 +++ include/libvirt/libvirt-domain.h | 1 + tools/virsh-domain-event.c | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/examples/c/misc/event-test.c b/examples/c/misc/event-test.c index 3e2b0a7827..1bac8d0cb8 100644 --- a/examples/c/misc/event-test.c +++ b/examples/c/misc/event-test.c @@ -239,6 +239,9 @@ eventDetailToString(int event, case VIR_DOMAIN_EVENT_STOPPED_RECREATED: return "Recreated";
+ case VIR_DOMAIN_EVENT_STOPPED_REBOOT: + return "Reboot"; + case VIR_DOMAIN_EVENT_STOPPED_LAST: break; } diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h index 9ee153c6eb..ada0df65a7 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -5778,6 +5778,7 @@ typedef enum { VIR_DOMAIN_EVENT_STOPPED_FAILED = 5, /* Host emulator/mgmt failed (Since: 0.5.0) */ VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT = 6, /* offline snapshot loaded (Since: 0.8.0) */ VIR_DOMAIN_EVENT_STOPPED_RECREATED = 7, /* Secure guest recreation (Since: 11.6.0) */ + VIR_DOMAIN_EVENT_STOPPED_REBOOT = 8, /* Host or guest requested reboot (Since: 12.9.0) */
Now 12.10.0. Regards, Jim
Signed-off-by: Ben Grande <ben@invisiblethingslab.com> --- src/libvirt-domain.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index acd9ffc44b..f1d4a30c2e 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -1779,7 +1779,10 @@ virDomainShutdownFlags(virDomainPtr domain, unsigned int flags) * Note that the guest OS may ignore the request. * Additionally, the hypervisor may check and support the domain * 'on_reboot' XML setting resulting in a domain that shuts down instead - * of rebooting. + * of rebooting. When 'on_reboot' isn't 'restart', drivers that support it will + * emit a VIR_DOMAIN_EVENT_STOPPED lifecycle event with detail + * VIR_DOMAIN_EVENT_STOPPED_REBOOT. For more information, see + * https://libvirt.org/formatdomain.html#events-configuration * * If @flags is set to zero, then the hypervisor will choose the * method of shutdown it considers best. To have greater control -- Benjamin Grande
I question whether this patch is even needed. Related APIs such as virtDomainShutdown*, virtDomainReset, etc make no mention of events that might be emitted. I'd be in favor of dropping it. On 11/9/26 4:47 AM, Ben Grande wrote:
Signed-off-by: Ben Grande <ben@invisiblethingslab.com> --- src/libvirt-domain.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index acd9ffc44b..f1d4a30c2e 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -1779,7 +1779,10 @@ virDomainShutdownFlags(virDomainPtr domain, unsigned int flags) * Note that the guest OS may ignore the request. * Additionally, the hypervisor may check and support the domain * 'on_reboot' XML setting resulting in a domain that shuts down instead - * of rebooting. + * of rebooting. When 'on_reboot' isn't 'restart', drivers that support it will + * emit a VIR_DOMAIN_EVENT_STOPPED lifecycle event with detail + * VIR_DOMAIN_EVENT_STOPPED_REBOOT. For more information, see + * https://libvirt.org/formatdomain.html#events-configuration
This doesn't match libxl driver behavior anyhow, which will emit a VIR_DOMAIN_EVENT_STOPPED event regardless of 'on_reboot' setting. Regards, Jim
Resolves: https://github.com/QubesOS/qubes-issues/issues/8196 Signed-off-by: Ben Grande <ben@invisiblethingslab.com> --- src/libxl/libxl_domain.c | 2 +- src/lxc/lxc_process.c | 2 +- src/test/test_driver.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 51dc3edcc2..808a8a333c 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -547,7 +547,7 @@ libxlDomainShutdownThread(void *opaque) dom_event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED, - VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN); + VIR_DOMAIN_EVENT_STOPPED_REBOOT); switch ((virDomainLifecycleAction) vm->def->onReboot) { case VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY: libxlDomainShutdownHandleDestroy(driver, vm); diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 466ce07afd..b9fa21a815 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -727,7 +727,7 @@ static void virLXCProcessMonitorExitNotify(virLXCMonitor *mon G_GNUC_UNUSED, priv->stopReason = VIR_DOMAIN_EVENT_STOPPED_FAILED; break; case VIR_LXC_MONITOR_EXIT_STATUS_REBOOT: - priv->stopReason = VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN; + priv->stopReason = VIR_DOMAIN_EVENT_STOPPED_REBOOT; priv->wantReboot = true; break; default: diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 8546c3e251..fbde51f3e4 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2076,7 +2076,7 @@ static int testDomainReboot(virDomainPtr domain, testDomainShutdownState(domain, privdom, VIR_DOMAIN_SHUTOFF_SHUTDOWN); event = virDomainEventLifecycleNewFromObj(privdom, VIR_DOMAIN_EVENT_STOPPED, - VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN); + VIR_DOMAIN_EVENT_STOPPED_REBOOT); if (!privdom->persistent) virDomainObjListRemove(privconn->domains, privdom); -- Benjamin Grande
On 11/9/26 4:47 AM, Ben Grande wrote:
Resolves: https://github.com/QubesOS/qubes-issues/issues/8196 Signed-off-by: Ben Grande <ben@invisiblethingslab.com> --- src/libxl/libxl_domain.c | 2 +- src/lxc/lxc_process.c | 2 +- src/test/test_driver.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 51dc3edcc2..808a8a333c 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -547,7 +547,7 @@ libxlDomainShutdownThread(void *opaque)
dom_event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED, - VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN); + VIR_DOMAIN_EVENT_STOPPED_REBOOT); switch ((virDomainLifecycleAction) vm->def->onReboot) { case VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY: libxlDomainShutdownHandleDestroy(driver, vm); diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 466ce07afd..b9fa21a815 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -727,7 +727,7 @@ static void virLXCProcessMonitorExitNotify(virLXCMonitor *mon G_GNUC_UNUSED, priv->stopReason = VIR_DOMAIN_EVENT_STOPPED_FAILED; break; case VIR_LXC_MONITOR_EXIT_STATUS_REBOOT: - priv->stopReason = VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN; + priv->stopReason = VIR_DOMAIN_EVENT_STOPPED_REBOOT;
As mentioned in the V2 review, this is only used when virLXCProcessReboot() fails in virLXCProcessMonitorEOFNotify(). It seems odd to emit a 'stopped' event with 'reboot' detail when the reboot has failed. In addition, the code never consults the 'on_reboot' setting. IMO, best to leave this driver as is. Regards, Jim
priv->wantReboot = true; break; default: diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 8546c3e251..fbde51f3e4 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2076,7 +2076,7 @@ static int testDomainReboot(virDomainPtr domain, testDomainShutdownState(domain, privdom, VIR_DOMAIN_SHUTOFF_SHUTDOWN); event = virDomainEventLifecycleNewFromObj(privdom, VIR_DOMAIN_EVENT_STOPPED, - VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN); + VIR_DOMAIN_EVENT_STOPPED_REBOOT);
if (!privdom->persistent) virDomainObjListRemove(privconn->domains, privdom);
Signed-off-by: Ben Grande <ben@invisiblethingslab.com> --- NEWS.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/NEWS.rst b/NEWS.rst index 802f89190a..09ff7ef3e7 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -33,8 +33,20 @@ v12.10.0 (unreleased) width reported to the guest. This allows the apparent bandwidth of a passed-through device to match the host hardware. + * Introduce ``VIR_DOMAIN_EVENT_STOPPED_REBOOT`` event reason + + Extract the shutdown reason from the hypervisor, and in case the domain + asked for reboot, the event ``VIR_DOMAIN_EVENT_STOPPED`` will have the + detail type ``VIR_DOMAIN_EVENT_STOPPED_REBOOT``. + * **Improvements** + * lxc: Report reboot reason ``VIR_DOMAIN_EVENT_STOPPED_REBOOT``. + + * libxl: Report reboot reason ``VIR_DOMAIN_EVENT_STOPPED_REBOOT``. + + * test driver: Report reboot reason ``VIR_DOMAIN_EVENT_STOPPED_REBOOT``. + * **Bug fixes** -- Benjamin Grande
In the subject, should be VIR_DOMAIN_EVENT_STOPPED_REBOOT. On 11/9/26 4:47 AM, Ben Grande wrote:
Signed-off-by: Ben Grande <ben@invisiblethingslab.com> --- NEWS.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/NEWS.rst b/NEWS.rst index 802f89190a..09ff7ef3e7 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -33,8 +33,20 @@ v12.10.0 (unreleased) width reported to the guest. This allows the apparent bandwidth of a passed-through device to match the host hardware.
+ * Introduce ``VIR_DOMAIN_EVENT_STOPPED_REBOOT`` event reason
Since the related enum is named 'virDomainEventStoppedDetailType', I'd use 'detail' instead of 'reason'.
+ + Extract the shutdown reason from the hypervisor, and in case the domain + asked for reboot, the event ``VIR_DOMAIN_EVENT_STOPPED`` will have the + detail type ``VIR_DOMAIN_EVENT_STOPPED_REBOOT``.
This isn't true for all drivers, right? Looking at past news entries related to events, I think it's enough mention the new event detail. What do you think of something like: A new ``VIR_DOMAIN_EVENT_STOPPED_REBOOT`` detail is now available for use with the ``VIR_DOMAIN_EVENT_STOPPED`` lifecycle event. Drivers may use it to indicate a domain has stopped as part of a reboot request.
+ * **Improvements**
+ * lxc: Report reboot reason ``VIR_DOMAIN_EVENT_STOPPED_REBOOT``. + + * libxl: Report reboot reason ``VIR_DOMAIN_EVENT_STOPPED_REBOOT``. + + * test driver: Report reboot reason ``VIR_DOMAIN_EVENT_STOPPED_REBOOT``.
These additions could be dropped IMO. Regards, Jim
participants (2)
-
Ben Grande -
Jim Fehlig