hypervisor: kvm: check API compatibility

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2020-09-07 10:10:58 +00:00 committed by Rob Bradford
parent 559d1840d8
commit d73971e407
2 changed files with 11 additions and 0 deletions

View File

@ -55,6 +55,11 @@ pub enum HypervisorError {
///
#[error("Failed to get the list of supported MSRs: {0}")]
GetMsrList(#[source] anyhow::Error),
///
/// API version is not compatible
///
#[error("Incompatible API version")]
IncompatibleApiVersion,
}
///

View File

@ -345,6 +345,12 @@ impl KvmHypervisor {
/// Create a hypervisor based on Kvm
pub fn new() -> hypervisor::Result<KvmHypervisor> {
let kvm_obj = Kvm::new().map_err(|e| hypervisor::HypervisorError::VmCreate(e.into()))?;
let api_version = kvm_obj.get_api_version();
if api_version != kvm_bindings::KVM_API_VERSION as i32 {
return Err(hypervisor::HypervisorError::IncompatibleApiVersion);
}
Ok(KvmHypervisor { kvm: kvm_obj })
}
}