File: virt-host-validate-bhyve.c

package info (click to toggle)
libvirt 11.3.0-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 199,880 kB
  • sloc: ansic: 531,532; xml: 289,675; python: 11,881; perl: 2,629; sh: 2,172; makefile: 447; javascript: 126; cpp: 22
file content (79 lines) | stat: -rw-r--r-- 2,551 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * 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 "virt-host-validate-bhyve.h"
#include "virt-host-validate-common.h"

#define MODULE_STATUS(mod, err_msg, err_code) \
    virValidateCheck("BHYVE", _("Checking for %1$s module"), #mod); \
    if (mod ## _loaded) { \
        virValidatePass(); \
    } else { \
        virValidateFail(err_code, \
                        _("%1$s module is not loaded, " err_msg), \
                        #mod); \
        ret = -1; \
    }

#define MODULE_STATUS_FAIL(mod, err_msg) \
    MODULE_STATUS(mod, err_msg, VIR_VALIDATE_FAIL)

#define MODULE_STATUS_WARN(mod, err_msg) \
    MODULE_STATUS(mod, err_msg, VIR_VALIDATE_WARN)


int virHostValidateBhyve(void)
{
    int ret = 0;
    int fileid = 0;
    g_autofree struct kld_file_stat *stat = g_new0(struct kld_file_stat, 1);
    bool vmm_loaded = false;
    bool if_tap_loaded = false;
    bool if_bridge_loaded = false;
    bool 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;
}