mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-20 23:04:22 +01:00
Since we prefer vsock over virtio serial port, we add 'vhost_vsock' in kernel mosules list. But vhost_vsock.ko shouldn't be the definitely required kernel modules, afterall, we could also use virtio serial port. if kata-env shows SupportsVSocks as false, users could run kata-check to manually load vhost_vsock.ko and get detailed info(errors) Fixes: #1512 Signed-off-by: Penny Zheng <penny.zheng@arm.com>
130 lines
3.2 KiB
Go
130 lines
3.2 KiB
Go
// Copyright (c) 2018 Intel Corporation
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/sirupsen/logrus"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
cpuFlagsTag = genericCPUFlagsTag
|
|
archCPUVendorField = genericCPUVendorField
|
|
// On s390x the cpu model is indicated by the field machine.
|
|
// Example:
|
|
// processor 0: version = FF, identification = 3FEC87, machine = 2964
|
|
archCPUModelField = "machine"
|
|
)
|
|
|
|
// archRequiredCPUFlags maps a CPU flag value to search for and a
|
|
// human-readable description of that value.
|
|
var archRequiredCPUFlags = map[string]string{}
|
|
|
|
// archRequiredCPUAttribs maps a CPU (non-CPU flag) attribute value to search for
|
|
// and a human-readable description of that value.
|
|
var archRequiredCPUAttribs = map[string]string{}
|
|
|
|
// archRequiredKernelModules maps a required module name to a human-readable
|
|
// description of the modules functionality and an optional list of
|
|
// required module parameters.
|
|
var archRequiredKernelModules = map[string]kernelModule{
|
|
"kvm": {
|
|
desc: "Kernel-based Virtual Machine",
|
|
required: true,
|
|
},
|
|
"vhost_vsock": {
|
|
desc: "Host Support for Linux VM Sockets",
|
|
required: false,
|
|
},
|
|
}
|
|
|
|
func setCPUtype() error {
|
|
return nil
|
|
}
|
|
|
|
// kvmIsUsable determines if it will be possible to create a full virtual machine
|
|
// by creating a minimal VM and then deleting it.
|
|
func kvmIsUsable() error {
|
|
return genericKvmIsUsable()
|
|
}
|
|
|
|
func archHostCanCreateVMContainer() error {
|
|
return kvmIsUsable()
|
|
}
|
|
|
|
// hostIsVMContainerCapable checks to see if the host is theoretically capable
|
|
// of creating a VM container.
|
|
func hostIsVMContainerCapable(details vmContainerCapableDetails) error {
|
|
|
|
_, err := getCPUInfo(details.cpuInfoFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
count, err := checkKernelModules(details.requiredKernelModules, archKernelParamHandler)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if count == 0 {
|
|
return nil
|
|
}
|
|
|
|
return fmt.Errorf("ERROR: %s", failMessage)
|
|
|
|
}
|
|
|
|
func archKernelParamHandler(onVMM bool, fields logrus.Fields, msg string) bool {
|
|
return genericArchKernelParamHandler(onVMM, fields, msg)
|
|
}
|
|
|
|
// getS390xCPUDetails returns the cpu information
|
|
func getS390xCPUDetails() (vendor, model string, err error) {
|
|
prefixModel := "processor"
|
|
cpuinfo, err := getCPUInfo(procCPUInfo)
|
|
if err != nil {
|
|
return "", "", err
|
|
}
|
|
|
|
lines := strings.Split(cpuinfo, "\n")
|
|
|
|
for _, line := range lines {
|
|
if archCPUVendorField != "" {
|
|
if strings.HasPrefix(line, archCPUVendorField) {
|
|
fields := strings.Split(line, ":")
|
|
if len(fields) > 1 {
|
|
vendor = strings.TrimSpace(fields[1])
|
|
}
|
|
}
|
|
}
|
|
if archCPUModelField != "" {
|
|
if strings.HasPrefix(line, prefixModel) {
|
|
fields := strings.Split(strings.TrimSpace(line), ",")
|
|
cpuModel := strings.Split(fields[2], "=")
|
|
model = strings.TrimSpace(cpuModel[1])
|
|
}
|
|
}
|
|
}
|
|
|
|
if vendor == "" {
|
|
return "", "", fmt.Errorf("cannot find vendor field in file %v", procCPUInfo)
|
|
}
|
|
|
|
if model == "" {
|
|
return "", "", fmt.Errorf("Error in parsing cpu model from %v", procCPUInfo)
|
|
}
|
|
|
|
return vendor, model, nil
|
|
}
|
|
|
|
func getCPUDetails() (vendor, model string, err error) {
|
|
if vendor, model, err := genericGetCPUDetails(); err == nil {
|
|
return vendor, model, nil
|
|
}
|
|
return getS390xCPUDetails()
|
|
}
|