mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-05-02 05:34:46 +00:00
kata-ctl:Implement functionality to check host is capable of running VM
Implement functionality to add to the env output if the host is capable of running a VM. Fixes: #6727 Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
parent
56d2ea9b78
commit
1b406b9d0c
@ -80,6 +80,11 @@ mod arch_specific {
|
|||||||
Some(CHECK_LIST)
|
Some(CHECK_LIST)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn host_is_vmcontainer_capable() -> Result<bool> {
|
||||||
|
// TODO: Not implemented
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
// Guest protection is not supported on ARM64.
|
// Guest protection is not supported on ARM64.
|
||||||
pub fn available_guest_protection() -> Result<check::GuestProtection, check::ProtectionError> {
|
pub fn available_guest_protection() -> Result<check::GuestProtection, check::ProtectionError> {
|
||||||
|
@ -33,6 +33,11 @@ mod arch_specific {
|
|||||||
// to the goloang implementation of function getCPUDetails()
|
// to the goloang implementation of function getCPUDetails()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn host_is_vmcontainer_capable() -> Result<bool> {
|
||||||
|
// TODO: Not implemented
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn available_guest_protection() -> Result<check::GuestProtection, check::ProtectionError> {
|
pub fn available_guest_protection() -> Result<check::GuestProtection, check::ProtectionError> {
|
||||||
if !Uid::effective().is_root() {
|
if !Uid::effective().is_root() {
|
||||||
return Err(check::ProtectionError::NoPerms);
|
return Err(check::ProtectionError::NoPerms);
|
||||||
|
@ -78,6 +78,21 @@ mod arch_specific {
|
|||||||
Some(CHECK_LIST)
|
Some(CHECK_LIST)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn host_is_vmcontainer_capable() -> Result<bool> {
|
||||||
|
let mut count = 0;
|
||||||
|
if check_cpu().is_err() {
|
||||||
|
count += 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: Add additional checks for kernel modules
|
||||||
|
|
||||||
|
if count == 0 {
|
||||||
|
return Ok(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
Err(anyhow!("System is not capable of running a VM"))
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn retrieve_cpu_facilities() -> Result<HashMap<i32, bool>> {
|
fn retrieve_cpu_facilities() -> Result<HashMap<i32, bool>> {
|
||||||
let f = std::fs::File::open(check::PROC_CPUINFO)?;
|
let f = std::fs::File::open(check::PROC_CPUINFO)?;
|
||||||
|
@ -343,6 +343,23 @@ mod arch_specific {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn host_is_vmcontainer_capable() -> Result<bool> {
|
||||||
|
let mut count = 0;
|
||||||
|
if check_cpu("check_cpu").is_err() {
|
||||||
|
count += 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
if check_kernel_modules("check_modules").is_err() {
|
||||||
|
count += 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
if count == 0 {
|
||||||
|
return Ok(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
Err(anyhow!("System is not capable of running a VM"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
@ -5,7 +5,9 @@
|
|||||||
|
|
||||||
// Contains checks that are not architecture-specific
|
// Contains checks that are not architecture-specific
|
||||||
|
|
||||||
|
#[cfg(any(target_arch = "x86_64"))]
|
||||||
use crate::types::KernelModule;
|
use crate::types::KernelModule;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use nix::fcntl::{open, OFlag};
|
use nix::fcntl::{open, OFlag};
|
||||||
use nix::sys::stat::Mode;
|
use nix::sys::stat::Mode;
|
||||||
@ -393,6 +395,7 @@ pub fn check_kernel_module_loaded(kernel_module: &KernelModule) -> Result<(), St
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
#[cfg(any(target_arch = "x86_64"))]
|
||||||
use crate::types::{KernelModule, KernelParam, KernelParamType};
|
use crate::types::{KernelModule, KernelParam, KernelParamType};
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use slog::warn;
|
use slog::warn;
|
||||||
|
@ -255,6 +255,12 @@ fn get_host_info() -> Result<HostInfo> {
|
|||||||
|
|
||||||
let guest_protection = guest_protection.to_string();
|
let guest_protection = guest_protection.to_string();
|
||||||
|
|
||||||
|
let mut vm_container_capable = true;
|
||||||
|
|
||||||
|
if arch_specific::host_is_vmcontainer_capable().is_err() {
|
||||||
|
vm_container_capable = false;
|
||||||
|
}
|
||||||
|
|
||||||
let support_vsocks = utils::supports_vsocks(utils::VHOST_VSOCK_DEVICE)?;
|
let support_vsocks = utils::supports_vsocks(utils::VHOST_VSOCK_DEVICE)?;
|
||||||
|
|
||||||
Ok(HostInfo {
|
Ok(HostInfo {
|
||||||
@ -264,8 +270,7 @@ fn get_host_info() -> Result<HostInfo> {
|
|||||||
cpu: host_cpu,
|
cpu: host_cpu,
|
||||||
memory: memory_info,
|
memory: memory_info,
|
||||||
available_guest_protection: guest_protection,
|
available_guest_protection: guest_protection,
|
||||||
// TODO: See https://github.com/kata-containers/kata-containers/issues/6727
|
vm_container_capable,
|
||||||
vm_container_capable: true,
|
|
||||||
support_vsocks,
|
support_vsocks,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user