From 4714272b397414b1f2986dccf8aa086072322646 Mon Sep 17 00:00:00 2001 From: Roman Bogorodskiy Date: Tue, 28 Oct 2025 18:04:12 +0100 Subject: [PATCH] bhyve: process: improve domain startup error handling 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 Reviewed-by: Michal Privoznik --- src/bhyve/bhyve_process.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c index 4fb7e642e1..7de614a1a3 100644 --- a/src/bhyve/bhyve_process.c +++ b/src/bhyve/bhyve_process.c @@ -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); -- 2.47.3