]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virt-host-validate: add bhyve support
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Fri, 24 Feb 2017 16:27:56 +0000 (20:27 +0400)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Sat, 11 Mar 2017 17:22:58 +0000 (21:22 +0400)
Add bhyve support to virt-host-validate(1). It checks for the
essential kernel modules to be available so that user can actually
start VMs, have networking and console access.

It uses the kldnext(2)/kldstat(2) routines to retrieve modules list.
As bhyve is only available on FreeBSD and these routines were available
long before bhyve appeared, not adding any specific configure checks
for that.

Also, update tools/Makefile.am to add
virt-host-validate-$driver.[hc] to the build only if the
appropriate driver is enabled.

po/POTFILES.in
tools/Makefile.am
tools/virt-host-validate-bhyve.c [new file with mode: 0644]
tools/virt-host-validate-bhyve.h [new file with mode: 0644]
tools/virt-host-validate.c
tools/virt-host-validate.pod

index ceda3edadd4e9da6dfb3bfe42ce216ab4c6d44bc..c8d01147bff38d24d4361fde16aa95779c9792ec 100644 (file)
@@ -309,6 +309,7 @@ tools/virsh-snapshot.c
 tools/virsh-volume.c
 tools/virsh.c
 tools/virt-admin.c
+tools/virt-host-validate-bhyve.c
 tools/virt-host-validate-common.c
 tools/virt-host-validate-lxc.c
 tools/virt-host-validate-qemu.c
index e6ae150259169cc4498ab1917671cc486aaf0dc5..162d8e565c1f50a867397b573798b7d848e54617 100644 (file)
@@ -139,10 +139,34 @@ libvirt_shell_la_SOURCES = vsh.c vsh.h
 
 virt_host_validate_SOURCES = \
                virt-host-validate.c \
-               virt-host-validate-common.c virt-host-validate-common.h \
-               virt-host-validate-qemu.c virt-host-validate-qemu.h \
-               virt-host-validate-lxc.c virt-host-validate-lxc.h \
-               $(NULL)
+               virt-host-validate-common.c virt-host-validate-common.h
+
+VIRT_HOST_VALIDATE_QEMU = \
+               virt-host-validate-qemu.c \
+               virt-host-validate-qemu.h
+VIRT_HOST_VALIDATE_LXC = \
+               virt-host-validate-lxc.c \
+               virt-host-validate-lxc.h
+VIRT_HOST_VALIDATE_BHYVE = \
+               virt-host-validate-bhyve.c \
+               virt-host-validate-bhyve.h
+if WITH_QEMU
+virt_host_validate_SOURCES += $(VIRT_HOST_VALIDATE_QEMU)
+else ! WITH_QEMU
+EXTRA_DIST += $(VIRT_HOST_VALIDATE_QEMU)
+endif ! WITH_QEMU
+
+if WITH_LXC
+virt_host_validate_SOURCES += $(VIRT_HOST_VALIDATE_LXC)
+else ! WITH_LXC
+EXTRA_DIST += $(VIRT_HOST_VALIDATE_LXC)
+endif ! WITH_LXC
+
+if WITH_BHYVE
+virt_host_validate_SOURCES += $(VIRT_HOST_VALIDATE_BHYVE)
+else ! WITH_BHYVE
+EXTRA_DIST += $(VIRT_HOST_VALIDATE_BHYVE)
+endif ! WITH_BHYVE
 
 virt_host_validate_LDFLAGS = \
                $(AM_LDFLAGS) \
diff --git a/tools/virt-host-validate-bhyve.c b/tools/virt-host-validate-bhyve.c
new file mode 100644 (file)
index 0000000..c7bf96f
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * virt-host-validate-bhyve.c: Sanity check a bhyve hypervisor host
+ *
+ * Copyright (C) 2017 Roman Bogorodskiy
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <config.h>
+
+#include <sys/param.h>
+#include <sys/linker.h>
+#include <stdio.h>
+
+#include "virt-host-validate-bhyve.h"
+#include "virt-host-validate-common.h"
+
+#define MODULE_STATUS(mod, err_msg, err_code)                  \
+    virHostMsgCheck("BHYVE", _("for %s module"), #mod);        \
+    if (mod ## _loaded) {                                      \
+        virHostMsgPass();                                      \
+    } else {                                                   \
+        virHostMsgFail(err_code,                               \
+                       _("%s module is not loaded, " err_msg), \
+                        #mod);                                 \
+        ret = -1;                                              \
+    }                                                          \
+
+#define MODULE_STATUS_FAIL(mod, err_msg) \
+    MODULE_STATUS(mod, err_msg, VIR_HOST_VALIDATE_FAIL)
+
+#define MODULE_STATUS_WARN(mod, err_msg) \
+    MODULE_STATUS(mod, err_msg, VIR_HOST_VALIDATE_WARN)
+
+
+int virHostValidateBhyve(void)
+{
+    int ret = 0;
+    int fileid = 0;
+    struct kld_file_stat stat;
+    bool vmm_loaded = false, if_tap_loaded = false;
+    bool if_bridge_loaded = false, nmdm_loaded = false;
+
+    for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) {
+        stat.version = sizeof(struct kld_file_stat);
+        if (kldstat(fileid, &stat) < 0)
+            continue;
+
+        if (STREQ(stat.name, "vmm.ko"))
+            vmm_loaded = true;
+        else if (STREQ(stat.name, "if_tap.ko"))
+            if_tap_loaded = true;
+        else if (STREQ(stat.name, "if_bridge.ko"))
+            if_bridge_loaded = true;
+        else if (STREQ(stat.name, "nmdm.ko"))
+            nmdm_loaded = true;
+    }
+
+    MODULE_STATUS_FAIL(vmm, "will not be able to start VMs");
+    MODULE_STATUS_WARN(if_tap, "networking will not work");
+    MODULE_STATUS_WARN(if_bridge, "bridged networking will not work");
+    MODULE_STATUS_WARN(nmdm, "nmdm console will not work");
+
+    return ret;
+}
diff --git a/tools/virt-host-validate-bhyve.h b/tools/virt-host-validate-bhyve.h
new file mode 100644 (file)
index 0000000..290d433
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * virt-host-validate-bhyve.h: Sanity check a bhyve hypervisor host
+ *
+ * Copyright (C) 2017 Roman Bogorodskiy
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __VIRT_HOST_VALIDATE_BHYVE_H__
+# define __VIRT_HOST_VALIDATE_BHYVE_H__
+
+int virHostValidateBhyve(void);
+
+#endif /* __VIRT_HOST_VALIDATE_BHYVE_H__ */
index f092824120aa1b43df1ab00548430d7a96da5c57..29d2482b6c045ace3fdd9635517fdbb42927fe37 100644 (file)
@@ -36,6 +36,9 @@
 #if WITH_LXC
 # include "virt-host-validate-lxc.h"
 #endif
+#if WITH_BHYVE
+# include "virt-host-validate-bhyve.h"
+#endif
 
 static void
 show_help(FILE *out, const char *argv0)
@@ -48,6 +51,7 @@ show_help(FILE *out, const char *argv0)
               "\n"
               "   - qemu\n"
               "   - lxc\n"
+              "   - bhyve\n"
               "\n"
               " Options:\n"
               "   -h, --help     Display command line help\n"
@@ -130,6 +134,14 @@ main(int argc, char **argv)
     }
 #endif
 
+#if WITH_BHYVE
+    if (!hvname || STREQ(hvname, "bhyve")) {
+        usedHvname = true;
+        if (virHostValidateBhyve() < 0)
+            ret = EXIT_FAILURE;
+    }
+#endif
+
     if (hvname && !usedHvname) {
         fprintf(stderr, _("%s: unsupported hypervisor name %s\n"),
                 argv[0], hvname);
index 84917c83b7f1657f0a237e7d9f88d0292a20d255..9101141752d112cdce8824b3aac6fb809276ffc4 100644 (file)
@@ -12,8 +12,8 @@ This tool validates that the host is configured in a suitable
 way to run libvirt hypervisor drivers. If invoked without any
 arguments it will check support for all hypervisor drivers it
 is aware of. Optionally it can be given a particular hypervisor
-type ('qemu' or 'lxc') to restrict the checks to those relevant
-for that virtualization technology
+type ('qemu', 'lxc' or 'bhyve') to restrict the checks
+to those relevant for that virtualization technology
 
 =head1 OPTIONS