mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 12:44:39 +00:00
kata-ctl: Remove cpu related functions from kata-ctl
Remove cpu related functions which have been moved to kata-sys-util. Change invocations in kata-ctl to make use of functions now moved to kata-sys-util. Signed-off-by: Nathan Whyte <nathanwhyte35@gmail.com> Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
parent
f5d1957174
commit
dacdf7c282
@ -37,9 +37,11 @@ mod arch_specific {
|
|||||||
fn check_cpu() -> Result<()> {
|
fn check_cpu() -> Result<()> {
|
||||||
info!(sl!(), "check CPU: s390x");
|
info!(sl!(), "check CPU: s390x");
|
||||||
|
|
||||||
let cpu_info = check::get_single_cpu_info(check::PROC_CPUINFO, CPUINFO_DELIMITER)?;
|
let cpu_info =
|
||||||
|
kata_sys_util::cpu::get_single_cpu_info(check::PROC_CPUINFO, CPUINFO_DELIMITER)?;
|
||||||
|
|
||||||
let cpu_features = check::get_cpu_flags(&cpu_info, CPUINFO_FEATURES_TAG).map_err(|e| {
|
let cpu_features = kata_sys_util::cpu::get_cpu_flags(&cpu_info, CPUINFO_FEATURES_TAG)
|
||||||
|
.map_err(|e| {
|
||||||
anyhow!(
|
anyhow!(
|
||||||
"Error parsing CPU features, file {:?}, {:?}",
|
"Error parsing CPU features, file {:?}, {:?}",
|
||||||
check::PROC_CPUINFO,
|
check::PROC_CPUINFO,
|
||||||
|
@ -93,9 +93,11 @@ mod arch_specific {
|
|||||||
fn check_cpu(_args: &str) -> Result<()> {
|
fn check_cpu(_args: &str) -> Result<()> {
|
||||||
info!(sl!(), "check CPU: x86_64");
|
info!(sl!(), "check CPU: x86_64");
|
||||||
|
|
||||||
let cpu_info = check::get_single_cpu_info(check::PROC_CPUINFO, CPUINFO_DELIMITER)?;
|
let cpu_info =
|
||||||
|
kata_sys_util::cpu::get_single_cpu_info(check::PROC_CPUINFO, CPUINFO_DELIMITER)?;
|
||||||
|
|
||||||
let cpu_flags = check::get_cpu_flags(&cpu_info, CPUINFO_FLAGS_TAG).map_err(|e| {
|
let cpu_flags =
|
||||||
|
kata_sys_util::cpu::get_cpu_flags(&cpu_info, CPUINFO_FLAGS_TAG).map_err(|e| {
|
||||||
anyhow!(
|
anyhow!(
|
||||||
"Error parsing CPU flags, file {:?}, {:?}",
|
"Error parsing CPU flags, file {:?}, {:?}",
|
||||||
check::PROC_CPUINFO,
|
check::PROC_CPUINFO,
|
||||||
@ -118,20 +120,6 @@ mod arch_specific {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn retrieve_cpu_flags() -> Result<String> {
|
|
||||||
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 {:?}, {:?}",
|
|
||||||
check::PROC_CPUINFO,
|
|
||||||
e
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
Ok(cpu_flags)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_cpu_details() -> Result<(String, String)> {
|
pub fn get_cpu_details() -> Result<(String, String)> {
|
||||||
utils::get_generic_cpu_details(check::PROC_CPUINFO)
|
utils::get_generic_cpu_details(check::PROC_CPUINFO)
|
||||||
}
|
}
|
||||||
@ -206,7 +194,7 @@ mod arch_specific {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn running_on_vmm() -> Result<bool> {
|
fn running_on_vmm() -> Result<bool> {
|
||||||
match check::get_single_cpu_info(check::PROC_CPUINFO, CPUINFO_DELIMITER) {
|
match kata_sys_util::cpu::get_single_cpu_info(check::PROC_CPUINFO, CPUINFO_DELIMITER) {
|
||||||
Ok(cpu_info) => {
|
Ok(cpu_info) => {
|
||||||
// check if the 'hypervisor' flag exist in the cpu features
|
// check if the 'hypervisor' flag exist in the cpu features
|
||||||
let missing_hypervisor_flag = check::check_cpu_attribs(&cpu_info, VMM_FLAGS)?;
|
let missing_hypervisor_flag = check::check_cpu_attribs(&cpu_info, VMM_FLAGS)?;
|
||||||
|
@ -61,57 +61,6 @@ macro_rules! sl {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_file_contents(file_path: &str) -> Result<String> {
|
|
||||||
let contents = std::fs::read_to_string(file_path)?;
|
|
||||||
Ok(contents)
|
|
||||||
}
|
|
||||||
|
|
||||||
// get_single_cpu_info returns the contents of the first cpu from
|
|
||||||
// the specified cpuinfo file by parsing based on a specified delimiter
|
|
||||||
pub fn get_single_cpu_info(cpu_info_file: &str, substring: &str) -> Result<String> {
|
|
||||||
let contents = read_file_contents(cpu_info_file)?;
|
|
||||||
|
|
||||||
if contents.is_empty() {
|
|
||||||
return Err(anyhow!(ERR_NO_CPUINFO));
|
|
||||||
}
|
|
||||||
|
|
||||||
let subcontents: Vec<&str> = contents.split(substring).collect();
|
|
||||||
let result = subcontents
|
|
||||||
.first()
|
|
||||||
.ok_or("error splitting contents of cpuinfo")
|
|
||||||
.map_err(|e| anyhow!(e))?
|
|
||||||
.to_string();
|
|
||||||
Ok(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
// get_cpu_flags returns a string of cpu flags from cpuinfo, passed in
|
|
||||||
// as a string
|
|
||||||
#[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!(ERR_NO_CPUINFO));
|
|
||||||
}
|
|
||||||
|
|
||||||
if cpu_flags_tag.is_empty() {
|
|
||||||
return Err(anyhow!("cpu flags delimiter string is empty"))?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let subcontents: Vec<&str> = cpu_info.split('\n').collect();
|
|
||||||
for line in subcontents {
|
|
||||||
if line.starts_with(cpu_flags_tag) {
|
|
||||||
let line_data: Vec<&str> = line.split(':').collect();
|
|
||||||
let flags = line_data
|
|
||||||
.last()
|
|
||||||
.ok_or("error splitting flags in cpuinfo")
|
|
||||||
.map_err(|e| anyhow!(e))?
|
|
||||||
.to_string();
|
|
||||||
return Ok(flags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
// get_missing_strings searches for required (strings) in data and returns
|
// get_missing_strings searches for required (strings) in data and returns
|
||||||
// a vector containing the missing strings
|
// a vector containing the missing strings
|
||||||
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
|
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
|
||||||
@ -397,6 +346,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
#[cfg(any(target_arch = "x86_64"))]
|
#[cfg(any(target_arch = "x86_64"))]
|
||||||
use crate::types::{KernelModule, KernelParam, KernelParamType};
|
use crate::types::{KernelModule, KernelParam, KernelParamType};
|
||||||
|
use kata_sys_util::cpu::{get_cpu_flags, get_single_cpu_info};
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use slog::warn;
|
use slog::warn;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
use crate::arch::arch_specific;
|
use crate::arch::arch_specific;
|
||||||
use crate::check::get_single_cpu_info;
|
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
@ -106,7 +105,7 @@ pub fn get_distro_details(os_release: &str, os_release_clr: &str) -> Result<(Str
|
|||||||
|
|
||||||
#[cfg(any(target_arch = "s390x", target_arch = "x86_64", target_arch = "aarch64"))]
|
#[cfg(any(target_arch = "s390x", target_arch = "x86_64", target_arch = "aarch64"))]
|
||||||
pub fn get_generic_cpu_details(cpu_info_file: &str) -> Result<(String, String)> {
|
pub fn get_generic_cpu_details(cpu_info_file: &str) -> Result<(String, String)> {
|
||||||
let cpu_info = get_single_cpu_info(cpu_info_file, "\n\n")?;
|
let cpu_info = kata_sys_util::cpu::get_single_cpu_info(cpu_info_file, "\n\n")?;
|
||||||
let lines = cpu_info.lines();
|
let lines = cpu_info.lines();
|
||||||
let mut vendor = String::new();
|
let mut vendor = String::new();
|
||||||
let mut model = String::new();
|
let mut model = String::new();
|
||||||
|
Loading…
Reference in New Issue
Block a user