kata-sys-util: Complete code move

In #7236 the guest protection code was moved to kata-sys-utils,
but some of it was left behind, and the adjustment to the new
location wasn't completed, so the powerpc64 code doesn't
build now we've fixed the cfg to test it.

Signed-off-by: stevenhorsman <steven@uk.ibm.com>
This commit is contained in:
stevenhorsman 2025-01-31 12:00:59 +00:00
parent 9f865f5bad
commit bd3c93713f
3 changed files with 17 additions and 9 deletions

View File

@ -9,6 +9,8 @@ use anyhow::anyhow;
use anyhow::Result;
use serde::{Deserialize, Serialize};
use std::fmt;
#[cfg(all(target_arch = "powerpc64", target_endian = "little"))]
use std::fs;
#[cfg(target_arch = "x86_64")]
use std::path::Path;
use std::path::PathBuf;
@ -201,7 +203,6 @@ pub fn arch_guest_protection(
#[cfg(target_arch = "s390x")]
#[allow(dead_code)]
// Guest protection is not supported on ARM64.
pub fn available_guest_protection() -> Result<GuestProtection, ProtectionError> {
if !Uid::effective().is_root() {
return Err(ProtectionError::NoPerms)?;
@ -237,18 +238,21 @@ pub fn available_guest_protection() -> Result<GuestProtection, ProtectionError>
Ok(GuestProtection::Se)
}
#[cfg(all(target_arch = "powerpc64", target_endian = "little"))]
const PEF_SYS_FIRMWARE_DIR: &str = "/sys/firmware/ultravisor/";
#[cfg(all(target_arch = "powerpc64", target_endian = "little"))]
pub fn available_guest_protection() -> Result<GuestProtection, ProtectionError> {
if !Uid::effective().is_root() {
return Err(check::ProtectionError::NoPerms);
return Err(ProtectionError::NoPerms);
}
let metadata = fs::metadata(PEF_SYS_FIRMWARE_DIR);
if metadata.is_ok() && metadata.unwrap().is_dir() {
Ok(check::GuestProtection::Pef)
return Ok(GuestProtection::Pef);
}
Ok(check::GuestProtection::NoProtection)
Ok(GuestProtection::NoProtection)
}
#[cfg(target_arch = "aarch64")]

View File

@ -3,28 +3,27 @@
// SPDX-License-Identifier: Apache-2.0
//
use crate::types::*;
#[cfg(all(target_arch = "powerpc64", target_endian = "little"))]
pub use arch_specific::*;
mod arch_specific {
use crate::check;
use crate::types::CheckItem;
use crate::utils;
use anyhow::Result;
pub const ARCH_CPU_VENDOR_FIELD: &str = "";
pub const ARCH_CPU_MODEL_FIELD: &str = "model";
#[allow(dead_code)]
pub fn check() -> Result<()> {
unimplemented!("Check not implemented in powerpc64le");
unimplemented!("Check not implemented in powerpc64");
}
pub fn get_checks() -> Option<&'static [CheckItem<'static>]> {
None
}
const PEF_SYS_FIRMWARE_DIR: &str = "/sys/firmware/ultravisor/";
pub fn get_cpu_details() -> Result<(String, String)> {
utils::get_generic_cpu_details(check::PROC_CPUINFO)

View File

@ -105,7 +105,12 @@ pub fn get_distro_details(os_release: &str, os_release_clr: &str) -> Result<(Str
Ok((name, version))
}
#[cfg(any(target_arch = "s390x", target_arch = "x86_64", target_arch = "aarch64"))]
#[cfg(any(
target_arch = "s390x",
target_arch = "x86_64",
target_arch = "aarch64",
all(target_arch = "powerpc64", target_endian = "little"),
))]
pub fn get_generic_cpu_details(cpu_info_file: &str) -> Result<(String, String)> {
let cpu_info = kata_sys_util::cpu::get_single_cpu_info(cpu_info_file, "\n\n")?;
let lines = cpu_info.lines();