kata-ctl: add basic cpu check for s390x

Add a basic s390x cpu check for the "sie" feature to be present.
Also re-enable cpu check testing.

Fixes: #5438

Signed-off-by: Hendrik Brueckner <brueckner@linux.ibm.com>
This commit is contained in:
Hendrik Brueckner 2022-10-18 17:23:28 +00:00
parent 871d2cf2c0
commit e95089b716
2 changed files with 44 additions and 8 deletions

View File

@ -1,4 +1,5 @@
// Copyright (c) 2022 Intel Corporation
// Copyright (c) 2022 IBM Corp.
//
// SPDX-License-Identifier: Apache-2.0
//
@ -7,9 +8,44 @@
pub use arch_specific::*;
mod arch_specific {
use anyhow::Result;
use crate::check;
use anyhow::{anyhow, Result};
const PROC_CPUINFO: &str = "/proc/cpuinfo";
const CPUINFO_DELIMITER: &str = "processor ";
const CPUINFO_FEATURES_TAG: &str = "features";
const CPU_FEATURES_REQ: &[&str] = &["sie"];
// check cpu
fn check_cpu() -> Result<()> {
println!("INFO: check CPU: s390x");
let cpu_info = check::get_single_cpu_info(PROC_CPUINFO, CPUINFO_DELIMITER)?;
let cpu_features = check::get_cpu_flags(&cpu_info, CPUINFO_FEATURES_TAG).map_err(|e| {
anyhow!(
"Error parsing CPU features, file {:?}, {:?}",
PROC_CPUINFO,
e
)
})?;
let missing_cpu_features = check::check_cpu_flags(&cpu_features, CPU_FEATURES_REQ)?;
if !missing_cpu_features.is_empty() {
eprintln!("WARNING: Missing CPU flags {:?}", missing_cpu_features);
}
Ok(())
}
pub fn check() -> Result<()> {
unimplemented!("Check not implemented in s390x");
println!("INFO: check: s390x");
let _cpu_result = check_cpu();
// TODO: add additional checks, e.g, kernel modules as in go runtime
// TODO: collect outcome of tests to determine if checks pass or not
Ok(())
}
}

View File

@ -13,7 +13,7 @@ use std::collections::HashMap;
const KATA_GITHUB_URL: &str =
"https://api.github.com/repos/kata-containers/kata-containers/releases/latest";
#[cfg(any(target_arch = "x86_64"))]
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
fn get_cpu_info(cpu_info_file: &str) -> Result<String> {
let contents = std::fs::read_to_string(cpu_info_file)?;
Ok(contents)
@ -21,7 +21,7 @@ fn get_cpu_info(cpu_info_file: &str) -> Result<String> {
// get_single_cpu_info returns the contents of the first cpu from
// the specified cpuinfo file by parsing based on a specified delimiter
#[cfg(any(target_arch = "x86_64"))]
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
pub fn get_single_cpu_info(cpu_info_file: &str, substring: &str) -> Result<String> {
let contents = get_cpu_info(cpu_info_file)?;
@ -41,7 +41,7 @@ pub fn get_single_cpu_info(cpu_info_file: &str, substring: &str) -> Result<Strin
// get_cpu_flags returns a string of cpu flags from cpuinfo, passed in
// as a string
#[cfg(any(target_arch = "x86_64"))]
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
pub fn get_cpu_flags(cpu_info: &str, cpu_flags_tag: &str) -> Result<String> {
if cpu_info.is_empty() {
return Err(anyhow!("cpu_info string is empty"))?;
@ -65,7 +65,7 @@ pub fn get_cpu_flags(cpu_info: &str, cpu_flags_tag: &str) -> Result<String> {
// get_missing_strings searches for required (strings) in data and returns
// a vector containing the missing strings
#[cfg(any(target_arch = "x86_64"))]
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
fn get_missing_strings(data: &str, required: &'static [&'static str]) -> Result<Vec<String>> {
let mut missing: Vec<String> = Vec::new();
@ -78,7 +78,7 @@ fn get_missing_strings(data: &str, required: &'static [&'static str]) -> Result<
Ok(missing)
}
#[cfg(any(target_arch = "x86_64"))]
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
pub fn check_cpu_flags(
retrieved_flags: &str,
required_flags: &'static [&'static str],
@ -144,7 +144,7 @@ pub fn check_version() -> Result<()> {
Ok(())
}
#[cfg(any(target_arch = "x86_64"))]
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
#[cfg(test)]
mod tests {
use super::*;