mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: simplify VM creation API
Create HypervisorVmConfig early and pass the struct to VM creation API in the vmm crate. Getting rid of multiple conditional parameter. Signed-off-by: Muminul Islam <muislam@microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
6897c2a462
commit
deaf660a52
+2
-24
@@ -1009,21 +1009,9 @@ impl Vm {
|
||||
vm_config.lock().unwrap().is_tdx_enabled()
|
||||
};
|
||||
|
||||
#[cfg(feature = "sev_snp")]
|
||||
let sev_snp_enabled = if snapshot.is_some() {
|
||||
false
|
||||
} else {
|
||||
vm_config.lock().unwrap().is_sev_snp_enabled()
|
||||
};
|
||||
|
||||
let vm = Self::create_hypervisor_vm(
|
||||
hypervisor.as_ref(),
|
||||
#[cfg(feature = "tdx")]
|
||||
tdx_enabled,
|
||||
#[cfg(feature = "sev_snp")]
|
||||
sev_snp_enabled,
|
||||
#[cfg(feature = "sev_snp")]
|
||||
vm_config.lock().unwrap().memory.total_size(),
|
||||
vm_config.as_ref().lock().unwrap().deref().into(),
|
||||
)?;
|
||||
|
||||
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
|
||||
@@ -1083,19 +1071,9 @@ impl Vm {
|
||||
|
||||
pub fn create_hypervisor_vm(
|
||||
hypervisor: &dyn hypervisor::Hypervisor,
|
||||
#[cfg(feature = "tdx")] tdx_enabled: bool,
|
||||
#[cfg(feature = "sev_snp")] sev_snp_enabled: bool,
|
||||
#[cfg(feature = "sev_snp")] mem_size: u64,
|
||||
config: HypervisorVmConfig,
|
||||
) -> Result<Arc<dyn hypervisor::Vm>> {
|
||||
hypervisor.check_required_extensions().unwrap();
|
||||
let config = HypervisorVmConfig {
|
||||
#[cfg(feature = "tdx")]
|
||||
tdx_enabled,
|
||||
#[cfg(feature = "sev_snp")]
|
||||
sev_snp_enabled,
|
||||
#[cfg(feature = "sev_snp")]
|
||||
mem_size,
|
||||
};
|
||||
|
||||
let vm = hypervisor.create_vm(config).unwrap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user