File: virt-host-validate-qemu.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 (128 lines) | stat: -rw-r--r-- 4,804 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * virt-host-validate-qemu.c: Sanity check a QEMU hypervisor host
 *
 * Copyright (C) 2012 Red Hat, Inc.
 *
 * 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 "virt-host-validate-qemu.h"
#include "virt-host-validate-common.h"
#include "virarch.h"
#include "virbitmap.h"
#include "vircgroup.h"

int virHostValidateQEMU(void)
{
    g_autoptr(virBitmap) flags = NULL;
    int ret = 0;
    bool hasHwVirt = false;
    bool hasVirtFlag = false;
    virArch arch = virArchFromHost();
    const char *kvmhint = _("Check that CPU and firmware supports virtualization and kvm module is loaded");

    if (!(flags = virHostValidateGetCPUFlags()))
        return -1;

    switch ((int)arch) {
    case VIR_ARCH_I686:
    case VIR_ARCH_X86_64:
        hasVirtFlag = true;
        kvmhint = _("Check that the 'kvm-intel' or 'kvm-amd' modules are loaded & the BIOS has enabled virtualization");
        if (virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_SVM) ||
            virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_VMX))
            hasHwVirt = true;
        break;
    case VIR_ARCH_S390:
    case VIR_ARCH_S390X:
        hasVirtFlag = true;
        if (virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_SIE))
            hasHwVirt = true;
        break;
    case VIR_ARCH_PPC64:
    case VIR_ARCH_PPC64LE:
        hasVirtFlag = true;
        hasHwVirt = true;
        break;
    default:
        hasHwVirt = false;
    }

    if (hasVirtFlag) {
        virValidateCheck("QEMU", "%s", _("Checking for hardware virtualization"));
        if (hasHwVirt) {
            virValidatePass();
        } else {
            virValidateFail(VIR_VALIDATE_FAIL,
                            _("Host not compatible with KVM; HW virtualization CPU features not found. Only emulated CPUs are available; performance will be significantly limited"));
            ret = -1;
        }
    }

    if (hasHwVirt || !hasVirtFlag) {
        if (virHostValidateDeviceExists("QEMU", "/dev/kvm",
                                        VIR_VALIDATE_FAIL,
                                        kvmhint) <0)
            ret = -1;
        else if (virHostValidateDeviceAccessible("QEMU", "/dev/kvm",
                                                 VIR_VALIDATE_FAIL,
                                                 _("Check /dev/kvm is world writable or you are in a group that is allowed to access it")) < 0)
            ret = -1;
    }

    if (arch == VIR_ARCH_PPC64 || arch == VIR_ARCH_PPC64LE) {
        virValidateCheck("QEMU", "%s", _("Checking for PowerPC KVM module loaded"));

        if (!virHostKernelModuleIsLoaded("kvm_hv"))
            virValidateFail(VIR_VALIDATE_WARN,
                            _("Load kvm_hv for better performance"));
        else
            virValidatePass();
    }

    if (virHostValidateDeviceExists("QEMU", "/dev/vhost-net",
                                    VIR_VALIDATE_WARN,
                                    _("Load the 'vhost_net' module to improve performance of virtio networking")) < 0)
        ret = -1;

    if (virHostValidateDeviceExists("QEMU", "/dev/net/tun",
                                    VIR_VALIDATE_FAIL,
                                    _("Load the 'tun' module to enable networking for QEMU guests")) < 0)
        ret = -1;

    if (virHostValidateCGroupControllers("QEMU",
                                         (1 << VIR_CGROUP_CONTROLLER_MEMORY) |
                                         (1 << VIR_CGROUP_CONTROLLER_CPU) |
                                         (1 << VIR_CGROUP_CONTROLLER_CPUACCT) |
                                         (1 << VIR_CGROUP_CONTROLLER_CPUSET) |
                                         (1 << VIR_CGROUP_CONTROLLER_DEVICES) |
                                         (1 << VIR_CGROUP_CONTROLLER_BLKIO),
                                         VIR_VALIDATE_WARN) < 0) {
        ret = -1;
    }

    if (virHostValidateIOMMU("QEMU",
                             VIR_VALIDATE_WARN) < 0)
        ret = -1;

    if (virHostValidateSecureGuests("QEMU",
                                    VIR_VALIDATE_WARN) < 0)
        ret = -1;

    return ret;
}