diff --git a/hypervisor/src/lib.rs b/hypervisor/src/lib.rs index 118b8d414..3d36794cd 100644 --- a/hypervisor/src/lib.rs +++ b/hypervisor/src/lib.rs @@ -69,12 +69,18 @@ pub enum HypervisorType { pub fn new() -> std::result::Result, 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` with a size in bytes at least as large as `size_in_bytes`.