[PATCH] bhyve: fix shutdown handling on arm64

Roman Bogorodskiy posted 1 patch 2 days, 9 hours ago
src/bhyve/bhyve_monitor.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
[PATCH] bhyve: fix shutdown handling on arm64
Posted by Roman Bogorodskiy 2 days, 9 hours ago
The bhyve driver requests signal-based shutdown by sending a
SIGTERM signal to the bhyve process.

On amd64 bhyve handles this signal to start ACPI shutdown.

On arm64 bhyve does not implement ACPI shutdown, so it does
not implement a signal handler for SIGTERM and just terminates.

These cases are seen differently in the monitor, and the
latter case is not handled, which could result in stopped
domain reported as running. Fix by handling both cases.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
---
 src/bhyve/bhyve_monitor.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/bhyve/bhyve_monitor.c b/src/bhyve/bhyve_monitor.c
index dab07ff95f..8e481b17aa 100644
--- a/src/bhyve/bhyve_monitor.c
+++ b/src/bhyve/bhyve_monitor.c
@@ -20,6 +20,7 @@
 
 #include <config.h>
 
+#include <signal.h>
 #include <sys/types.h>
 #include <sys/event.h>
 #include <sys/time.h>
@@ -117,6 +118,7 @@ bhyveMonitorIO(int watch, int kq, int events G_GNUC_UNUSED, void *opaque)
     const char *name;
     struct kevent kev;
     int rc, status;
+    bool shutdownBySignal;
 
     if (watch != mon->watch || kq != mon->kq) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -153,13 +155,19 @@ bhyveMonitorIO(int watch, int kq, int events G_GNUC_UNUSED, void *opaque)
 
     name = vm->def->name;
     status = kev.data;
+    /* On amd64 SIGTERM triggers ACPI shutdown, and we see it as WIFEXITED(status).
+     * However, arm64 has no SIGTERM handler, so we see it as WIFSIGNALED(status).
+     */
+    shutdownBySignal = WIFSIGNALED(status) &&
+        WTERMSIG(status) == SIGTERM;
+
     if (WIFSIGNALED(status) && WCOREDUMP(status)) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Guest %1$s got signal %2$d and crashed"),
                        name, WTERMSIG(status));
         virBhyveProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_CRASHED, false);
-    } else if (WIFEXITED(status)) {
-        if (WEXITSTATUS(status) == 0 || mon->reboot) {
+    } else if (WIFEXITED(status) || shutdownBySignal) {
+        if ((!shutdownBySignal && WEXITSTATUS(status) == 0) || mon->reboot) {
             /* 0 - reboot */
             if (vm->def->onReboot == VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY ||
                 vm->def->onReboot == VIR_DOMAIN_LIFECYCLE_ACTION_PRESERVE) {
@@ -169,7 +177,7 @@ bhyveMonitorIO(int watch, int kq, int events G_GNUC_UNUSED, void *opaque)
                 VIR_INFO("Guest %s rebooted; restarting domain.", name);
                 virBhyveProcessRestart(driver, vm);
             }
-        } else if (WEXITSTATUS(status) < 3) {
+        } else if (shutdownBySignal || WEXITSTATUS(status) < 3) {
             /* 1 - shutdown, 2 - halt, 3 - triple fault. others - error */
             if (vm->def->onPoweroff == VIR_DOMAIN_LIFECYCLE_ACTION_RESTART ||
                 vm->def->onPoweroff == VIR_DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME) {
-- 
2.55.0
Re: [PATCH] bhyve: fix shutdown handling on arm64
Posted by Michal Prívozník via Devel 2 days, 4 hours ago
On 10/23/26 09:11, Roman Bogorodskiy wrote:
> The bhyve driver requests signal-based shutdown by sending a
> SIGTERM signal to the bhyve process.
> 
> On amd64 bhyve handles this signal to start ACPI shutdown.
> 
> On arm64 bhyve does not implement ACPI shutdown, so it does
> not implement a signal handler for SIGTERM and just terminates.
> 
> These cases are seen differently in the monitor, and the
> latter case is not handled, which could result in stopped
> domain reported as running. Fix by handling both cases.
> 
> Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
> ---
>  src/bhyve/bhyve_monitor.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal