From 7c7c8b0b6c7eca6b65a6fbd6a48e170c34ec61c9 Mon Sep 17 00:00:00 2001 From: Conrad Meyer Date: Sat, 8 Nov 2014 11:48:35 -0500 Subject: [PATCH] bhyve: Add console support for grub-bhyve bootloader This enables booting interactive GRUB menus (e.g. install CDs) with libvirt-bhyve. Caveat: A terminal other than the '--console' option to 'virsh start' (e.g. 'cu -l /dev/nmdm0B -s 115200') must be used to connect to grub-bhyve because the bhyve loader path is synchronous and must occur before the VM actually starts. Changing the bhyveProcessStart logic around to accommodate '--console' for interactive loader use seems like a significant project and probably not worth it, if UEFI/BIOS support for bhyve is "coming soon." --- src/bhyve/bhyve_command.c | 18 ++++++++++++++++++ src/bhyve/bhyve_driver.c | 13 +++++++++++++ src/bhyve/bhyve_driver.h | 2 ++ src/bhyve/bhyve_utils.h | 2 ++ 4 files changed, 35 insertions(+) diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index 203495cd9d..26d4797465 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -25,8 +25,10 @@ #include #include +#include "bhyve_capabilities.h" #include "bhyve_command.h" #include "bhyve_domain.h" +#include "bhyve_driver.h" #include "datatypes.h" #include "viralloc.h" #include "virfile.h" @@ -447,6 +449,22 @@ virBhyveProcessBuildGrubbhyveCmd(virDomainDefPtr def, virCommandAddArgFormat(cmd, "%llu", VIR_DIV_UP(def->mem.max_balloon, 1024)); + if ((bhyveDriverGetGrubCaps(conn) & BHYVE_GRUB_CAP_CONSDEV) != 0 && + def->nserials > 0) { + virDomainChrDefPtr chr; + + chr = def->serials[0]; + + if (chr->source.type != VIR_DOMAIN_CHR_TYPE_NMDM) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("only nmdm console types are supported")); + return NULL; + } + + virCommandAddArg(cmd, "--cons-dev"); + virCommandAddArg(cmd, chr->source.data.file.path); + } + /* VM name */ virCommandAddArg(cmd, def->name); diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 4aee249167..38207374b9 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -1169,6 +1169,9 @@ bhyveStateInitialize(bool priveleged ATTRIBUTE_UNUSED, if (!(bhyve_driver->caps = virBhyveCapsBuild())) goto cleanup; + if (virBhyveProbeGrubCaps(&bhyve_driver->grubcaps) < 0) + goto cleanup; + if (!(bhyve_driver->xmlopt = virDomainXMLOptionNew(&virBhyveDriverDomainDefParserConfig, &virBhyveDriverPrivateDataCallbacks, NULL))) @@ -1226,6 +1229,16 @@ bhyveStateInitialize(bool priveleged ATTRIBUTE_UNUSED, return -1; } +unsigned +bhyveDriverGetGrubCaps(virConnectPtr conn) +{ + bhyveConnPtr driver = conn->privateData; + + if (driver != NULL) + return driver->grubcaps; + return 0; +} + static void bhyveStateAutoStart(void) { diff --git a/src/bhyve/bhyve_driver.h b/src/bhyve/bhyve_driver.h index b70991d7e1..af2424ad3d 100644 --- a/src/bhyve/bhyve_driver.h +++ b/src/bhyve/bhyve_driver.h @@ -25,4 +25,6 @@ int bhyveRegister(void); +unsigned bhyveDriverGetGrubCaps(virConnectPtr conn); + #endif /* __BHYVE_DRIVER_H__ */ diff --git a/src/bhyve/bhyve_utils.h b/src/bhyve/bhyve_utils.h index 848f9a1cdc..bbaa3a35fa 100644 --- a/src/bhyve/bhyve_utils.h +++ b/src/bhyve/bhyve_utils.h @@ -45,6 +45,8 @@ struct _bhyveConn { virObjectEventStatePtr domainEventState; virCloseCallbacksPtr closeCallbacks; + + unsigned grubcaps; }; typedef struct _bhyveConn bhyveConn;