hypervisor: kvm: check API compatibility
Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
parent
559d1840d8
commit
d73971e407
2 changed files with 11 additions and 0 deletions
|
|
@ -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,
|
||||
}
|
||||
|
||||
///
|
||||
|
|
|
|||
|
|
@ -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 })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue