hypervisor: pick the available hypervisor automatically

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2022-07-22 11:10:16 +00:00 committed by Liu Wei
parent aa66526ea0
commit bb19c3d2b7

View File

@ -69,12 +69,18 @@ pub enum HypervisorType {
pub fn new() -> std::result::Result<Arc<dyn Hypervisor>, HypervisorError> {
#[cfg(feature = "kvm")]
let hv = kvm::KvmHypervisor::new()?;
if kvm::KvmHypervisor::is_available()? {
return kvm::KvmHypervisor::new();
}
#[cfg(feature = "mshv")]
let hv = mshv::MshvHypervisor::new()?;
if mshv::MshvHypervisor::is_available()? {
return mshv::MshvHypervisor::new();
}
Ok(hv)
Err(HypervisorError::HypervisorCreate(anyhow!(
"no supported hypervisor"
)))
}
// Returns a `Vec<T>` with a size in bytes at least as large as `size_in_bytes`.