2 * virt-host-validate-bhyve.c: Sanity check a bhyve hypervisor host
4 * Copyright (C) 2017 Roman Bogorodskiy
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
24 #include <sys/param.h>
25 #include <sys/linker.h>
27 #include "virt-host-validate-bhyve.h"
28 #include "virt-host-validate-common.h"
30 #define MODULE_STATUS(mod, err_msg, err_code) \
31 virHostMsgCheck("BHYVE", _("for %s module"), #mod); \
32 if (mod ## _loaded) { \
35 virHostMsgFail(err_code, \
36 _("%s module is not loaded, " err_msg), \
41 #define MODULE_STATUS_FAIL(mod, err_msg) \
42 MODULE_STATUS(mod, err_msg, VIR_HOST_VALIDATE_FAIL)
44 #define MODULE_STATUS_WARN(mod, err_msg) \
45 MODULE_STATUS(mod, err_msg, VIR_HOST_VALIDATE_WARN)
48 int virHostValidateBhyve(void)
52 struct kld_file_stat stat
;
53 bool vmm_loaded
= false, if_tap_loaded
= false;
54 bool if_bridge_loaded
= false, nmdm_loaded
= false;
56 for (fileid
= kldnext(0); fileid
> 0; fileid
= kldnext(fileid
)) {
57 stat
.version
= sizeof(struct kld_file_stat
);
58 if (kldstat(fileid
, &stat
) < 0)
61 if (STREQ(stat
.name
, "vmm.ko"))
63 else if (STREQ(stat
.name
, "if_tap.ko"))
65 else if (STREQ(stat
.name
, "if_bridge.ko"))
66 if_bridge_loaded
= true;
67 else if (STREQ(stat
.name
, "nmdm.ko"))
71 MODULE_STATUS_FAIL(vmm
, "will not be able to start VMs");
72 MODULE_STATUS_WARN(if_tap
, "networking will not work");
73 MODULE_STATUS_WARN(if_bridge
, "bridged networking will not work");
74 MODULE_STATUS_WARN(nmdm
, "nmdm console will not work");