]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
bhyve: process: improve domain startup error handling master
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Tue, 28 Oct 2025 17:04:12 +0000 (18:04 +0100)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Sat, 8 Nov 2025 08:14:37 +0000 (09:14 +0100)
After executing the bhyve binary, it might happen that it fails very
early due to configuration issues (missing/inaccessible files, incorrect
custom args), bugs, etc. In this case it'll look like the domain has
started normally, but quickly turned off.

Improve that by waiting for the domain's vmm entity to appear in
/dev/vmm.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/bhyve/bhyve_process.c

index 4fb7e642e143ccf67b098c839f156f45496efd3b..7de614a1a3de447d5cb83592d8a665892c754e55 100644 (file)
@@ -51,6 +51,7 @@
 #include "virnetdev.h"
 #include "virnetdevbridge.h"
 #include "virnetdevtap.h"
+#include "virtime.h"
 
 #define VIR_FROM_THIS   VIR_FROM_BHYVE
 
@@ -143,7 +144,10 @@ virBhyveProcessStartImpl(struct _bhyveConn *driver,
     g_autoptr(virCommand) cmd = NULL;
     g_autoptr(virCommand) load_cmd = NULL;
     bhyveDomainObjPrivate *priv = vm->privateData;
+    g_autofree char *domain_vmm_path = NULL;
+    virTimeBackOffVar timebackoff;
     int ret = -1, rc;
+    bool vmm_appeared = false;
 
     logfile = g_strdup_printf("%s/%s.log", BHYVE_LOG_DIR, vm->def->name);
     if ((logfd = open(logfile, O_WRONLY | O_APPEND | O_CREAT,
@@ -228,6 +232,24 @@ virBhyveProcessStartImpl(struct _bhyveConn *driver,
         goto cleanup;
     }
 
+    domain_vmm_path = g_strdup_printf("/dev/vmm/%s", vm->def->name);
+
+    if (virTimeBackOffStart(&timebackoff, 1, 5000) < 0)
+        goto cleanup;
+    while (virTimeBackOffWait(&timebackoff)) {
+        if (virFileExists(domain_vmm_path)) {
+            vmm_appeared = true;
+            break;
+        }
+    }
+
+    if (!vmm_appeared) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Domain %1$s didn't show up in /dev/vmm"),
+                       vm->def->name);
+        goto cleanup;
+    }
+
     vm->def->id = vm->pid;
     virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason);
     priv->mon = bhyveMonitorOpen(vm, driver);