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> --- Ideally, I'd also like to display the errors that the bhyve binary logs in this case. But as I'm doing: virCommandSetErrorFD(cmd, &logfd); I'm not sure if I should read that again from logfd, or are there more optimal ways to do that? src/bhyve/bhyve_process.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c index 4fb7e642e1..591c2d1ded 100644 --- a/src/bhyve/bhyve_process.c +++ b/src/bhyve/bhyve_process.c @@ -143,7 +143,12 @@ virBhyveProcessStartImpl(struct _bhyveConn *driver, g_autoptr(virCommand) cmd = NULL; g_autoptr(virCommand) load_cmd = NULL; bhyveDomainObjPrivate *priv = vm->privateData; + g_auto(virBuffer) domain_vmm_path_buf = VIR_BUFFER_INITIALIZER; + g_autofree char *domain_vmm_path = NULL; int ret = -1, rc; + size_t i = 0; + int timeout = 3; + 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 +233,25 @@ virBhyveProcessStartImpl(struct _bhyveConn *driver, goto cleanup; } + virBufferAsprintf(&domain_vmm_path_buf, "/dev/vmm/%s", vm->def->name); + domain_vmm_path = virBufferContentAndReset(&domain_vmm_path_buf); + + do { + if (virFileExists(domain_vmm_path)) { + vmm_appeared = true; + break; + } + + g_usleep(500000); + } while (!vmm_appeared && ++i < timeout); + + 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.51.0