arch/arm64: Fix ARM64 build

Fix ARM64 build which silently broken (as we still don't have an ARM CI).

Fixes #349.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
James O. D. Hunt 2018-06-01 10:27:15 +01:00
parent 2400978f6a
commit 6e161a248e
9 changed files with 106 additions and 28 deletions

View File

@ -45,11 +45,15 @@ type vmContainerCapableDetails struct {
const ( const (
moduleParamDir = "parameters" moduleParamDir = "parameters"
cpuFlagsTag = "flags"
successMessageCapable = "System is capable of running " + project successMessageCapable = "System is capable of running " + project
successMessageCreate = "System can currently create " + project successMessageCreate = "System can currently create " + project
failMessage = "System is not capable of running " + project failMessage = "System is not capable of running " + project
kernelPropertyCorrect = "Kernel property value correct" 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 // variables rather than consts to allow tests to modify them

View File

@ -9,6 +9,12 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
const (
cpuFlagsTag = genericCPUFlagsTag
archCPUVendorField = genericCPUVendorField
archCPUModelField = genericCPUModelField
)
// archRequiredCPUFlags maps a CPU flag value to search for and a // archRequiredCPUFlags maps a CPU flag value to search for and a
// human-readable description of that value. // human-readable description of that value.
var archRequiredCPUFlags = map[string]string{ var archRequiredCPUFlags = map[string]string{

View File

@ -5,6 +5,37 @@
package main 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 // kvmIsUsable determines if it will be possible to create a full virtual machine
// by creating a minimal VM and then deleting it. // by creating a minimal VM and then deleting it.
func kvmIsUsable() error { func kvmIsUsable() error {
@ -20,3 +51,7 @@ func archHostCanCreateVMContainer() error {
func hostIsVMContainerCapable(details vmContainerCapableDetails) error { func hostIsVMContainerCapable(details vmContainerCapableDetails) error {
return genericHostIsVMContainerCapable(details) return genericHostIsVMContainerCapable(details)
} }
func archKernelParamHandler(onVMM bool, fields logrus.Fields, msg string) bool {
return genericArchKernelParamHandler(onVMM, fields, msg)
}

View File

@ -7,9 +7,16 @@ package main
import ( import (
"fmt" "fmt"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
const (
cpuFlagsTag = genericCPUFlagsTag
archCPUVendorField = genericCPUVendorField
archCPUModelField = genericCPUModelField
)
// archRequiredCPUFlags maps a CPU flag value to search for and a // archRequiredCPUFlags maps a CPU flag value to search for and a
// human-readable description of that value. // human-readable description of that value.
var archRequiredCPUFlags = map[string]string{} var archRequiredCPUFlags = map[string]string{}
@ -37,11 +44,6 @@ func archHostCanCreateVMContainer() error {
// hostIsVMContainerCapable checks to see if the host is theoretically capable // hostIsVMContainerCapable checks to see if the host is theoretically capable
// of creating a VM container. // of creating a VM container.
func hostIsVMContainerCapable(details vmContainerCapableDetails) error { func hostIsVMContainerCapable(details vmContainerCapableDetails) error {
_, err := getCPUInfo(details.cpuInfoFile)
if err != nil {
return err
}
count, err := checkKernelModules(details.requiredKernelModules, archKernelParamHandler) count, err := checkKernelModules(details.requiredKernelModules, archKernelParamHandler)
if err != nil { if err != nil {
return err return err

View File

@ -229,10 +229,23 @@ func TestCheckGetCPUFlags(t *testing.T) {
{"foo", ""}, {"foo", ""},
{"foo bar", ""}, {"foo bar", ""},
{":", ""}, {":", ""},
{"flags", ""},
{"flags:", ""}, {
{"flags: a b c", "a b c"}, cpuFlagsTag,
{"flags: a b c foo bar d", "a b c foo bar d"}, "",
},
{
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 { for _, d := range data {

View File

@ -205,9 +205,13 @@ VERSION_ID="%s"
`, expectedDistro.Name, expectedDistro.Version) `, expectedDistro.Name, expectedDistro.Version)
procCPUInfoContents := fmt.Sprintf(` procCPUInfoContents := fmt.Sprintf(`
vendor_id : %s %s : %s
model name : %s %s : %s
`, expectedCPU.Vendor, expectedCPU.Model) `,
archCPUVendorField,
expectedCPU.Vendor,
archCPUModelField,
expectedCPU.Model)
data := []filesToCreate{ data := []filesToCreate{
{procVersion, procVersionContents}, {procVersion, procVersionContents},

View File

@ -108,24 +108,35 @@ func getCPUDetails() (vendor, model string, err error) {
lines := strings.Split(cpuinfo, "\n") lines := strings.Split(cpuinfo, "\n")
for _, line := range lines { for _, line := range lines {
if strings.HasPrefix(line, "vendor_id") { if archCPUVendorField != "" {
if strings.HasPrefix(line, archCPUVendorField) {
fields := strings.Split(line, ":") fields := strings.Split(line, ":")
if len(fields) > 1 { if len(fields) > 1 {
vendor = strings.TrimSpace(fields[1]) vendor = strings.TrimSpace(fields[1])
} }
} else if strings.HasPrefix(line, "model name") { }
}
if archCPUModelField != "" {
if strings.HasPrefix(line, archCPUModelField) {
fields := strings.Split(line, ":") fields := strings.Split(line, ":")
if len(fields) > 1 { if len(fields) > 1 {
model = strings.TrimSpace(fields[1]) model = strings.TrimSpace(fields[1])
} }
} }
} }
if vendor != "" && model != "" {
return vendor, model, nil
} }
return "", "", fmt.Errorf("failed to find expected fields in file %v", procCPUInfo) if vendor == "" {
return "", "", fmt.Errorf("cannot find vendor field 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 // resolvePath returns the fully resolved and expanded value of the

View File

@ -225,10 +225,10 @@ func TestGetCPUDetails(t *testing.T) {
} }
const validVendorName = "a vendor" const validVendorName = "a vendor"
validVendor := fmt.Sprintf(`vendor_id : %s`, validVendorName) validVendor := fmt.Sprintf(`%s : %s`, archCPUVendorField, validVendorName)
const validModelName = "some CPU model" const validModelName = "some CPU model"
validModel := fmt.Sprintf(`model name : %s`, validModelName) validModel := fmt.Sprintf(`%s : %s`, archCPUModelField, validModelName)
validContents := fmt.Sprintf(` validContents := fmt.Sprintf(`
a : b a : b
@ -240,7 +240,7 @@ foo : bar
data := []testData{ data := []testData{
{"", "", "", true}, {"", "", "", true},
{"invalid", "", "", true}, {"invalid", "", "", true},
{"vendor_id", "", "", true}, {archCPUVendorField, "", "", true},
{validVendor, "", "", true}, {validVendor, "", "", true},
{validModel, "", "", true}, {validModel, "", "", true},
{validContents, validVendorName, validModelName, false}, {validContents, validVendorName, validModelName, false},

View File

@ -22,6 +22,9 @@ const defaultQemuMachineType = QemuVirt
const defaultQemuMachineOptions = "gic-version=host,usb=off,accel=kvm" const defaultQemuMachineOptions = "gic-version=host,usb=off,accel=kvm"
// Not used
const defaultPCBridgeBus = ""
var qemuPaths = map[string]string{ var qemuPaths = map[string]string{
QemuVirt: defaultQemuPath, QemuVirt: defaultQemuPath,
} }
@ -47,7 +50,7 @@ func MaxQemuVCPUs() uint32 {
return uint32(runtime.NumCPU()) return uint32(runtime.NumCPU())
} }
func newQemuArch(config HypervisrConfig) qemuArch { func newQemuArch(config HypervisorConfig) qemuArch {
machineType := config.HypervisorMachineType machineType := config.HypervisorMachineType
if machineType == "" { if machineType == "" {
machineType = defaultQemuMachineType machineType = defaultQemuMachineType