In order to start unprivileged VMs, bhyve(8) requires using the monitor mode, which is enabled by the '-M' argument.
In monitor mode bhyve runs a monitor process and a VM process. We already know the monitor process ID, but we also need to know the VM process ID (e.g. for reconnecting or shutting it down with a signal). Thus, also probe the bhyvectl(8)'s "--get-vm-pid" argument, which returns a VM's PID. Signed-off-by: Roman Bogorodskiy <[email protected]> --- src/bhyve/bhyve_capabilities.c | 29 +++++++++++++++++++++++++++++ src/bhyve/bhyve_capabilities.h | 2 ++ 2 files changed, 31 insertions(+) diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c index 85988a2ce8..e21f01e982 100644 --- a/src/bhyve/bhyve_capabilities.c +++ b/src/bhyve/bhyve_capabilities.c @@ -263,6 +263,9 @@ bhyveProbeCapsFromHelp(unsigned int *caps, char *binary) if (strstr(help, "-n:") != NULL) *caps |= BHYVE_CAP_NUMA; + if (strstr(help, "-M:") != NULL) + *caps |= BHYVE_CAP_MONITOR; + return 0; } @@ -357,6 +360,29 @@ bhyveProbeCapsRctl(unsigned int *caps) return; } +static int +bhyveProbeCapsBhyvectl(unsigned int *caps) +{ + g_autofree char *binary = virFindFileInPath("bhyvectl"); + g_autofree char *help = NULL; + g_autoptr(virCommand) cmd = NULL; + int exit; + + if (!binary) + return 0; + + cmd = virCommandNew(binary); + virCommandAddArg(cmd, "--help"); + virCommandSetErrorBuffer(cmd, &help); + if (virCommandRun(cmd, &exit) < 0) + return -1; + + if (strstr(help, "--get-vm-pid") != NULL) + *caps |= BHYVE_CAP_GET_VMPID; + + return 0; +} + int virBhyveProbeCaps(unsigned int *caps) { @@ -379,6 +405,9 @@ virBhyveProbeCaps(unsigned int *caps) if ((ret = bhyveProbeCapsVNCPassword(caps, binary))) goto out; + if ((ret = bhyveProbeCapsBhyvectl(caps))) + goto out; + bhyveProbeCapsRctl(caps); out: diff --git a/src/bhyve/bhyve_capabilities.h b/src/bhyve/bhyve_capabilities.h index 0302b68e22..c790c57ba7 100644 --- a/src/bhyve/bhyve_capabilities.h +++ b/src/bhyve/bhyve_capabilities.h @@ -58,6 +58,8 @@ typedef enum { BHYVE_CAP_ACPI = 1 << 12, BHYVE_CAP_NUMA = 1 << 13, BHYVE_CAP_RCTL = 1 << 14, + BHYVE_CAP_MONITOR = 1 << 15, + BHYVE_CAP_GET_VMPID = 1 << 16, } virBhyveCapsFlags; int virBhyveProbeGrubCaps(virBhyveGrubCapsFlags *caps); -- 2.55.0
