diff --git a/src/tools/kata-ctl/src/arch/s390x/mod.rs b/src/tools/kata-ctl/src/arch/s390x/mod.rs index 7f6a424c3b..20daa49dcd 100644 --- a/src/tools/kata-ctl/src/arch/s390x/mod.rs +++ b/src/tools/kata-ctl/src/arch/s390x/mod.rs @@ -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(()) } } diff --git a/src/tools/kata-ctl/src/check.rs b/src/tools/kata-ctl/src/check.rs index 63e1da5551..0e012cf53d 100644 --- a/src/tools/kata-ctl/src/check.rs +++ b/src/tools/kata-ctl/src/check.rs @@ -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 { 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 { // 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 { 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 Result { 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 { // 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> { let mut missing: Vec = 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::*;