diff --git a/src/runtime-rs/crates/hypervisor/src/ch/inner.rs b/src/runtime-rs/crates/hypervisor/src/ch/inner.rs index d99321a74a..c8f1c2d905 100644 --- a/src/runtime-rs/crates/hypervisor/src/ch/inner.rs +++ b/src/runtime-rs/crates/hypervisor/src/ch/inner.rs @@ -27,7 +27,7 @@ pub struct CloudHypervisorInner { pub(crate) api_socket: Option, pub(crate) extra_args: Option>, - pub(crate) config: Option, + pub(crate) config: HypervisorConfig, pub(crate) process: Option, pub(crate) pid: Option, @@ -101,7 +101,7 @@ impl CloudHypervisorInner { process: None, pid: None, - config: None, + config: Default::default(), state: VmmState::NotReady, timeout_secs: CH_DEFAULT_TIMEOUT_SECS as i32, id: String::default(), @@ -124,11 +124,11 @@ impl CloudHypervisorInner { } pub fn set_hypervisor_config(&mut self, config: HypervisorConfig) { - self.config = Some(config); + self.config = config; } pub fn hypervisor_config(&self) -> HypervisorConfig { - self.config.clone().unwrap_or_default() + self.config.clone() } } @@ -168,7 +168,7 @@ impl Persist for CloudHypervisorInner { let (tx, rx) = channel(true); let mut ch = Self { - config: Some(hypervisor_state.config), + config: hypervisor_state.config, state: VmmState::NotReady, id: hypervisor_state.id, vm_path: hypervisor_state.vm_path, diff --git a/src/runtime-rs/crates/hypervisor/src/ch/inner_hypervisor.rs b/src/runtime-rs/crates/hypervisor/src/ch/inner_hypervisor.rs index 1d9598b111..841eb97f0c 100644 --- a/src/runtime-rs/crates/hypervisor/src/ch/inner_hypervisor.rs +++ b/src/runtime-rs/crates/hypervisor/src/ch/inner_hypervisor.rs @@ -117,11 +117,7 @@ impl CloudHypervisorInner { } async fn get_kernel_params(&self) -> Result { - let cfg = self - .config - .as_ref() - .ok_or("no hypervisor config for CH") - .map_err(|e| anyhow!(e))?; + let cfg = &self.config; let enable_debug = cfg.debug_info.enable_debug; @@ -200,15 +196,10 @@ impl CloudHypervisorInner { let vsock_socket_path = get_vsock_path(&self.id)?; - let hypervisor_config = self - .config - .as_ref() - .ok_or("no hypervisor config for CH") - .map_err(|e| anyhow!(e))?; - debug!( sl!(), - "generic Hypervisor configuration: {:?}", hypervisor_config + "generic Hypervisor configuration: {:?}", + self.config.clone() ); let kernel_params = self.get_kernel_params().await?; @@ -217,7 +208,7 @@ impl CloudHypervisorInner { kernel_params, sandbox_path, vsock_socket_path, - cfg: hypervisor_config.clone(), + cfg: self.config.clone(), guest_protection_to_use: self.guest_protection_to_use.clone(), shared_fs_devices, network_devices, @@ -324,11 +315,7 @@ impl CloudHypervisorInner { async fn cloud_hypervisor_launch(&mut self, _timeout_secs: i32) -> Result<()> { self.cloud_hypervisor_ensure_not_launched().await?; - let cfg = self - .config - .as_ref() - .ok_or("no hypervisor config for CH") - .map_err(|e| anyhow!(e))?; + let cfg = &self.config; let debug = cfg.debug_info.enable_debug; @@ -338,13 +325,7 @@ impl CloudHypervisorInner { let _ = std::fs::remove_file(api_socket_path.clone()); - let binary_path = self - .config - .as_ref() - .ok_or("no hypervisor config for CH") - .map_err(|e| anyhow!(e))? - .path - .to_string(); + let binary_path = cfg.path.to_string(); let path = Path::new(&binary_path).canonicalize()?; @@ -567,11 +548,7 @@ impl CloudHypervisorInner { // call, if confidential_guest is set, a confidential // guest will be created. async fn handle_guest_protection(&mut self) -> Result<()> { - let cfg = self - .config - .as_ref() - .ok_or("missing hypervisor config") - .map_err(|e| anyhow!(e))?; + let cfg = &self.config; let confidential_guest = cfg.security_info.confidential_guest;