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:
Muminul Islam
2025-10-07 16:46:18 -07:00
committed by Rob Bradford
parent 6897c2a462
commit deaf660a52
2 changed files with 17 additions and 30 deletions
+15 -6
View File
@@ -210,6 +210,20 @@ pub enum Error {
#[error("Error applying landlock")]
ApplyLandlock(#[source] LandlockError),
}
impl From<&VmConfig> for hypervisor::HypervisorVmConfig {
fn from(_value: &VmConfig) -> Self {
hypervisor::HypervisorVmConfig {
#[cfg(feature = "tdx")]
tdx_enabled: _value.platform.as_ref().map(|p| p.tdx).unwrap_or(false),
#[cfg(feature = "sev_snp")]
sev_snp_enabled: _value.is_sev_snp_enabled(),
#[cfg(feature = "sev_snp")]
mem_size: _value.memory.total_size(),
}
}
}
pub type Result<T> = result::Result<T, Error>;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -1006,12 +1020,7 @@ impl Vmm {
let vm = Vm::create_hypervisor_vm(
self.hypervisor.as_ref(),
#[cfg(feature = "tdx")]
false,
#[cfg(feature = "sev_snp")]
false,
#[cfg(feature = "sev_snp")]
config.lock().unwrap().memory.total_size(),
(&*self.vm_config.as_ref().unwrap().lock().unwrap()).into(),
)
.map_err(|e| {
MigratableError::MigrateReceive(anyhow!(