mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-04-01 20:04:37 +00:00
hypervisor: kvm: check API compatibility
Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
parent
559d1840d8
commit
d73971e407
@ -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…
x
Reference in New Issue
Block a user