kata-ctl: let check framework arch-agnostic

The current check framwork is specific for x86. Refactor the code
to let it arch-agnostic.

Fixes: #5923
Signed-off-by: Jianyong Wu <jianyong.wu@arm.com>
This commit is contained in:
Jianyong Wu 2022-12-17 13:03:38 +08:00
parent 2e54c8e887
commit 1bd533f10b
2 changed files with 12 additions and 12 deletions

View File

@ -25,8 +25,8 @@ mod arch_specific {
perm: PermissionType::NonPrivileged,
}];
pub fn get_checks() -> &'static [CheckItem<'static>] {
CHECK_LIST
pub fn get_checks() -> Option<&'static [CheckItem<'static>]> {
Some(CHECK_LIST)
}
fn check_cpu(_args: &str) -> Result<()> {

View File

@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0
//
use crate::arch::x86_64::get_checks;
use crate::arch::arch_specific::get_checks;
use crate::args::{CheckArgument, CheckSubCommand, IptablesCommand, MetricsCommand};
@ -19,11 +19,11 @@ const NAME: &str = "kata-ctl";
// This function retrieves the cmd function passes as argument
fn get_builtin_check_func(name: CheckType) -> Result<BuiltinCmdFp> {
let check_list = get_checks();
for check in check_list {
if check.name.eq(&name) {
return Ok(check.fp);
if let Some(check_list) = get_checks() {
for check in check_list {
if check.name.eq(&name) {
return Ok(check.fp);
}
}
}
@ -42,10 +42,10 @@ fn handle_builtin_check(check: CheckType, args: &str) -> Result<()> {
fn get_client_cmd_details() -> Vec<String> {
let mut cmds = Vec::new();
let check_list = get_checks();
for cmd in check_list {
cmds.push(format!("{} ({}. Mode: {})", cmd.name, cmd.descr, cmd.perm));
if let Some(check_list) = get_checks() {
for cmd in check_list {
cmds.push(format!("{} ({}. Mode: {})", cmd.name, cmd.descr, cmd.perm));
}
}
cmds