runtime-rs: CloudHypervisorInner: Change config type

This commit change config in CloudHypervisorInner to normal
HypervisorConfig to decrease the change of its type.

Fixes: #10849

Signed-off-by: Hui Zhu <teawater@antgroup.com>
This commit is contained in:
Hui Zhu 2025-02-06 17:30:38 +08:00
parent c9f5966f56
commit e4cbc6abce
2 changed files with 12 additions and 35 deletions

View File

@ -27,7 +27,7 @@ pub struct CloudHypervisorInner {
pub(crate) api_socket: Option<UnixStream>,
pub(crate) extra_args: Option<Vec<String>>,
pub(crate) config: Option<HypervisorConfig>,
pub(crate) config: HypervisorConfig,
pub(crate) process: Option<Child>,
pub(crate) pid: Option<u32>,
@ -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,

View File

@ -117,11 +117,7 @@ impl CloudHypervisorInner {
}
async fn get_kernel_params(&self) -> Result<String> {
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;