From 11e24aa42de9d3c5b91924d0b1cd6717b0b2ef19 Mon Sep 17 00:00:00 2001 From: Nitesh Konkar Date: Wed, 9 Jan 2019 15:18:09 +0530 Subject: [PATCH 1/2] kata-runtime: Return correct kata-env on ppc64le The contents of /proc/cpuinfo were trimmed and hence the "model" field could not be parsed despite being a field in /proc/cpuinfo. Fix this issue. Fixes: #1089 Signed-off-by: Nitesh Konkar niteshkonkar@in.ibm.com --- cli/kata-check_ppc64le.go | 59 +++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/cli/kata-check_ppc64le.go b/cli/kata-check_ppc64le.go index 06c584358..0bf35ea28 100644 --- a/cli/kata-check_ppc64le.go +++ b/cli/kata-check_ppc64le.go @@ -97,12 +97,61 @@ func archKernelParamHandler(onVMM bool, fields logrus.Fields, msg string) bool { return genericArchKernelParamHandler(onVMM, fields, msg) } -func getCPUDetails() (vendor, model string, err error) { - vendor, model, err = genericGetCPUDetails() - if err == nil { - model = "POWER8" +func getPPC64leCPUInfo(cpuInfoFile string) (string, error) { + text, err := katautils.GetFileContents(cpuInfoFile) + if err != nil { + return "", err } - return vendor, model, err + + if len(strings.TrimSpace(text)) == 0 { + return "", fmt.Errorf("Cannot determine CPU details") + } + + return text, nil +} + +func getCPUDetails() (vendor, model string, err error) { + + if vendor, model, err := genericGetCPUDetails(); err == nil { + return vendor, model, nil + } + + cpuinfo, err := getPPC64leCPUInfo(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, archCPUModelField) { + fields := strings.Split(line, ":") + if len(fields) > 1 { + model = strings.TrimSpace(fields[1]) + } + } + } + } + + if archCPUVendorField != "" && vendor == "" { + return "", "", fmt.Errorf("cannot find vendor field in file %v", procCPUInfo) + } + + if archCPUModelField != "" && model == "" { + return "", "", fmt.Errorf("cannot find model field in file %v", procCPUInfo) + } + + return vendor, model, nil } func isSMTOff() bool { From db33d7110208ad8c24999bfbbbafbbd23065e870 Mon Sep 17 00:00:00 2001 From: Nitesh Konkar Date: Wed, 9 Jan 2019 15:19:22 +0530 Subject: [PATCH 2/2] Kata-runtime: Use correct model name for TestGetCPUDetails Use the correct model name for ppc64le TestGetCPUDetails model name. Fixes: #1089 Signed-off-by: Nitesh Konkar niteshkonkar@in.ibm.com --- cli/kata-check_ppc64le_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/kata-check_ppc64le_test.go b/cli/kata-check_ppc64le_test.go index 5d0f2d974..6c1bd1299 100644 --- a/cli/kata-check_ppc64le_test.go +++ b/cli/kata-check_ppc64le_test.go @@ -220,7 +220,7 @@ func TestGetCPUDetails(t *testing.T) { const validVendorName = "" validVendor := fmt.Sprintf(`%s : %s`, archCPUVendorField, validVendorName) - const validModelName = "POWER8" + const validModelName = "8247-22L" validModel := fmt.Sprintf(`%s : %s`, archCPUModelField, validModelName) validContents := fmt.Sprintf(`