mirror of
				https://github.com/kata-containers/kata-containers.git
				synced 2025-10-31 09:26:52 +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:
		| @@ -80,6 +80,11 @@ mod arch_specific { | ||||
|         Some(CHECK_LIST) | ||||
|     } | ||||
|  | ||||
|     pub fn host_is_vmcontainer_capable() -> Result<bool> { | ||||
|         // TODO: Not implemented | ||||
|         Ok(true) | ||||
|     } | ||||
|  | ||||
|     #[allow(dead_code)] | ||||
|     // Guest protection is not supported on ARM64. | ||||
|     pub fn available_guest_protection() -> Result<check::GuestProtection, check::ProtectionError> { | ||||
|   | ||||
| @@ -33,6 +33,11 @@ mod arch_specific { | ||||
|         // 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> { | ||||
|         if !Uid::effective().is_root() { | ||||
|             return Err(check::ProtectionError::NoPerms); | ||||
|   | ||||
| @@ -78,6 +78,21 @@ mod arch_specific { | ||||
|         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)] | ||||
|     fn retrieve_cpu_facilities() -> Result<HashMap<i32, bool>> { | ||||
|         let f = std::fs::File::open(check::PROC_CPUINFO)?; | ||||
|   | ||||
| @@ -343,6 +343,23 @@ mod arch_specific { | ||||
|         } | ||||
|         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")] | ||||
|   | ||||
| @@ -5,7 +5,9 @@ | ||||
|  | ||||
| // Contains checks that are not architecture-specific | ||||
|  | ||||
| #[cfg(any(target_arch = "x86_64"))] | ||||
| use crate::types::KernelModule; | ||||
|  | ||||
| use anyhow::{anyhow, Result}; | ||||
| use nix::fcntl::{open, OFlag}; | ||||
| use nix::sys::stat::Mode; | ||||
| @@ -393,6 +395,7 @@ pub fn check_kernel_module_loaded(kernel_module: &KernelModule) -> Result<(), St | ||||
| #[cfg(test)] | ||||
| mod tests { | ||||
|     use super::*; | ||||
|     #[cfg(any(target_arch = "x86_64"))] | ||||
|     use crate::types::{KernelModule, KernelParam, KernelParamType}; | ||||
|     use semver::Version; | ||||
|     use slog::warn; | ||||
|   | ||||
| @@ -255,6 +255,12 @@ fn get_host_info() -> Result<HostInfo> { | ||||
|  | ||||
|     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)?; | ||||
|  | ||||
|     Ok(HostInfo { | ||||
| @@ -264,8 +270,7 @@ fn get_host_info() -> Result<HostInfo> { | ||||
|         cpu: host_cpu, | ||||
|         memory: memory_info, | ||||
|         available_guest_protection: guest_protection, | ||||
|         // TODO: See https://github.com/kata-containers/kata-containers/issues/6727 | ||||
|         vm_container_capable: true, | ||||
|         vm_container_capable, | ||||
|         support_vsocks, | ||||
|     }) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user