Skip to content

Commit

Permalink
check: Move PROC_CPUINFO from architecture specific files
Browse files Browse the repository at this point in the history
Move PROC_CPUINFO into check.rs. This file is used accross
architectures and does not need to be in arch-specific files.

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
  • Loading branch information
amshinde committed Jan 9, 2023
1 parent 6628891 commit d33e343
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/tools/kata-ctl/src/arch/s390x/mod.rs
Expand Up @@ -12,7 +12,6 @@ mod arch_specific {
use crate::types::*;
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"];
Expand All @@ -21,12 +20,12 @@ mod arch_specific {
fn check_cpu() -> Result<()> {
println!("INFO: check CPU: s390x");

let cpu_info = check::get_single_cpu_info(PROC_CPUINFO, CPUINFO_DELIMITER)?;
let cpu_info = check::get_single_cpu_info(check::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,
check::PROC_CPUINFO,
e
)
})?;
Expand Down
12 changes: 8 additions & 4 deletions src/tools/kata-ctl/src/arch/x86_64/mod.rs
Expand Up @@ -11,7 +11,6 @@ mod arch_specific {
use crate::types::*;
use anyhow::{anyhow, Result};

const PROC_CPUINFO: &str = "/proc/cpuinfo";
const CPUINFO_DELIMITER: &str = "\nprocessor";
const CPUINFO_FLAGS_TAG: &str = "flags";
const CPU_FLAGS_INTEL: &[&str] = &["lm", "sse4_1", "vmx"];
Expand All @@ -32,10 +31,15 @@ mod arch_specific {
fn check_cpu(_args: &str) -> Result<()> {
println!("INFO: check CPU: x86_64");

let cpu_info = check::get_single_cpu_info(PROC_CPUINFO, CPUINFO_DELIMITER)?;
let cpu_info = check::get_single_cpu_info(check::PROC_CPUINFO, CPUINFO_DELIMITER)?;

let cpu_flags = check::get_cpu_flags(&cpu_info, CPUINFO_FLAGS_TAG)
.map_err(|e| anyhow!("Error parsing CPU flags, file {:?}, {:?}", PROC_CPUINFO, e))?;
let cpu_flags = check::get_cpu_flags(&cpu_info, CPUINFO_FLAGS_TAG).map_err(|e| {
anyhow!(
"Error parsing CPU flags, file {:?}, {:?}",
check::PROC_CPUINFO,
e
)
})?;

// perform checks
// TODO: Perform checks based on hypervisor type
Expand Down
2 changes: 2 additions & 0 deletions src/tools/kata-ctl/src/check.rs
Expand Up @@ -23,6 +23,8 @@ const JSON_TYPE: &str = "application/json";

const USER_AGT: &str = "kata";

pub const PROC_CPUINFO: &str = "/proc/cpuinfo";

#[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)?;
Expand Down

0 comments on commit d33e343

Please sign in to comment.