diff --git a/cli/kata-check.go b/cli/kata-check.go index 4548df6a3..89c59d33d 100644 --- a/cli/kata-check.go +++ b/cli/kata-check.go @@ -45,11 +45,15 @@ type vmContainerCapableDetails struct { const ( moduleParamDir = "parameters" - cpuFlagsTag = "flags" successMessageCapable = "System is capable of running " + project successMessageCreate = "System can currently create " + project failMessage = "System is not capable of running " + project kernelPropertyCorrect = "Kernel property value correct" + + // these refer to fields in the procCPUINFO file + genericCPUFlagsTag = "flags" + genericCPUVendorField = "vendor_id" + genericCPUModelField = "model name" ) // variables rather than consts to allow tests to modify them diff --git a/cli/kata-check_amd64.go b/cli/kata-check_amd64.go index 7e44a025d..db46e246c 100644 --- a/cli/kata-check_amd64.go +++ b/cli/kata-check_amd64.go @@ -9,6 +9,12 @@ import ( "github.com/sirupsen/logrus" ) +const ( + cpuFlagsTag = genericCPUFlagsTag + archCPUVendorField = genericCPUVendorField + archCPUModelField = genericCPUModelField +) + // archRequiredCPUFlags maps a CPU flag value to search for and a // human-readable description of that value. var archRequiredCPUFlags = map[string]string{ diff --git a/cli/kata-check_arm64.go b/cli/kata-check_arm64.go index c55d80991..ab73393df 100644 --- a/cli/kata-check_arm64.go +++ b/cli/kata-check_arm64.go @@ -5,6 +5,37 @@ package main +import "github.com/sirupsen/logrus" + +const ( + cpuFlagsTag = "Features" + archCPUVendorField = "CPU implementer" + archCPUModelField = "CPU variant" +) + +// 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", + }, + "vhost": { + desc: "Host kernel accelerator for virtio", + }, + "vhost_net": { + desc: "Host kernel accelerator for virtio network", + }, +} + // 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 { @@ -20,3 +51,7 @@ func archHostCanCreateVMContainer() error { func hostIsVMContainerCapable(details vmContainerCapableDetails) error { return genericHostIsVMContainerCapable(details) } + +func archKernelParamHandler(onVMM bool, fields logrus.Fields, msg string) bool { + return genericArchKernelParamHandler(onVMM, fields, msg) +} diff --git a/cli/kata-check_ppc64le.go b/cli/kata-check_ppc64le.go index ce2777743..750338fdb 100644 --- a/cli/kata-check_ppc64le.go +++ b/cli/kata-check_ppc64le.go @@ -7,9 +7,16 @@ package main import ( "fmt" + "github.com/sirupsen/logrus" ) +const ( + cpuFlagsTag = genericCPUFlagsTag + archCPUVendorField = genericCPUVendorField + archCPUModelField = genericCPUModelField +) + // archRequiredCPUFlags maps a CPU flag value to search for and a // human-readable description of that value. var archRequiredCPUFlags = map[string]string{} @@ -37,11 +44,6 @@ func archHostCanCreateVMContainer() error { // 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 diff --git a/cli/kata-check_test.go b/cli/kata-check_test.go index 4a68ac605..bc3ea2a3e 100644 --- a/cli/kata-check_test.go +++ b/cli/kata-check_test.go @@ -229,10 +229,23 @@ func TestCheckGetCPUFlags(t *testing.T) { {"foo", ""}, {"foo bar", ""}, {":", ""}, - {"flags", ""}, - {"flags:", ""}, - {"flags: a b c", "a b c"}, - {"flags: a b c foo bar d", "a b c foo bar d"}, + + { + cpuFlagsTag, + "", + }, + { + cpuFlagsTag + ":", + "", + }, + { + fmt.Sprintf("%s: a b c", cpuFlagsTag), + "a b c", + }, + { + fmt.Sprintf("%s: a b c foo bar d", cpuFlagsTag), + "a b c foo bar d", + }, } for _, d := range data { diff --git a/cli/kata-env_test.go b/cli/kata-env_test.go index 281d9b062..c86fe4ef2 100644 --- a/cli/kata-env_test.go +++ b/cli/kata-env_test.go @@ -205,9 +205,13 @@ VERSION_ID="%s" `, expectedDistro.Name, expectedDistro.Version) procCPUInfoContents := fmt.Sprintf(` -vendor_id : %s -model name : %s -`, expectedCPU.Vendor, expectedCPU.Model) +%s : %s +%s : %s +`, + archCPUVendorField, + expectedCPU.Vendor, + archCPUModelField, + expectedCPU.Model) data := []filesToCreate{ {procVersion, procVersionContents}, diff --git a/cli/utils.go b/cli/utils.go index 6c4dd9b9e..df83a1aa8 100644 --- a/cli/utils.go +++ b/cli/utils.go @@ -108,24 +108,35 @@ func getCPUDetails() (vendor, model string, err error) { lines := strings.Split(cpuinfo, "\n") for _, line := range lines { - if strings.HasPrefix(line, "vendor_id") { - fields := strings.Split(line, ":") - if len(fields) > 1 { - vendor = strings.TrimSpace(fields[1]) + if archCPUVendorField != "" { + if strings.HasPrefix(line, archCPUVendorField) { + fields := strings.Split(line, ":") + if len(fields) > 1 { + vendor = strings.TrimSpace(fields[1]) + } } - } else if strings.HasPrefix(line, "model name") { - fields := strings.Split(line, ":") - if len(fields) > 1 { - model = strings.TrimSpace(fields[1]) + } + + if archCPUModelField != "" { + if strings.HasPrefix(line, archCPUModelField) { + fields := strings.Split(line, ":") + if len(fields) > 1 { + model = strings.TrimSpace(fields[1]) + } } } } - if vendor != "" && model != "" { - return vendor, model, nil + if vendor == "" { + return "", "", fmt.Errorf("cannot find vendor field in file %v", procCPUInfo) } - return "", "", fmt.Errorf("failed to find expected fields in file %v", procCPUInfo) + // model name is optional + if archCPUModelField != "" && model == "" { + return "", "", fmt.Errorf("cannot find model field in file %v", procCPUInfo) + } + + return vendor, model, nil } // resolvePath returns the fully resolved and expanded value of the diff --git a/cli/utils_test.go b/cli/utils_test.go index ed709fbab..69a131c9f 100644 --- a/cli/utils_test.go +++ b/cli/utils_test.go @@ -225,10 +225,10 @@ func TestGetCPUDetails(t *testing.T) { } const validVendorName = "a vendor" - validVendor := fmt.Sprintf(`vendor_id : %s`, validVendorName) + validVendor := fmt.Sprintf(`%s : %s`, archCPUVendorField, validVendorName) const validModelName = "some CPU model" - validModel := fmt.Sprintf(`model name : %s`, validModelName) + validModel := fmt.Sprintf(`%s : %s`, archCPUModelField, validModelName) validContents := fmt.Sprintf(` a : b @@ -240,7 +240,7 @@ foo : bar data := []testData{ {"", "", "", true}, {"invalid", "", "", true}, - {"vendor_id", "", "", true}, + {archCPUVendorField, "", "", true}, {validVendor, "", "", true}, {validModel, "", "", true}, {validContents, validVendorName, validModelName, false}, diff --git a/virtcontainers/qemu_arm64.go b/virtcontainers/qemu_arm64.go index 42ae76718..8c6090fea 100644 --- a/virtcontainers/qemu_arm64.go +++ b/virtcontainers/qemu_arm64.go @@ -22,6 +22,9 @@ const defaultQemuMachineType = QemuVirt const defaultQemuMachineOptions = "gic-version=host,usb=off,accel=kvm" +// Not used +const defaultPCBridgeBus = "" + var qemuPaths = map[string]string{ QemuVirt: defaultQemuPath, } @@ -47,7 +50,7 @@ func MaxQemuVCPUs() uint32 { return uint32(runtime.NumCPU()) } -func newQemuArch(config HypervisrConfig) qemuArch { +func newQemuArch(config HypervisorConfig) qemuArch { machineType := config.HypervisorMachineType if machineType == "" { machineType = defaultQemuMachineType