mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
hypervisor: kvm: introduce a check_extension macro
That reduces code repetition. Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
@@ -106,9 +106,15 @@ pub fn is_system_register(regid: u64) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_required_kvm_extensions(kvm: &Kvm) -> KvmResult<()> {
|
pub fn check_required_kvm_extensions(kvm: &Kvm) -> KvmResult<()> {
|
||||||
if !kvm.check_extension(Cap::OneReg) {
|
macro_rules! check_extension {
|
||||||
return Err(KvmError::CapabilityMissing(Cap::OneReg));
|
($cap:expr) => {
|
||||||
|
if !kvm.check_extension($cap) {
|
||||||
|
return Err(KvmError::CapabilityMissing($cap));
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_extension!(Cap::OneReg);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,24 +32,20 @@ pub use {
|
|||||||
/// Check KVM extension for Linux
|
/// Check KVM extension for Linux
|
||||||
///
|
///
|
||||||
pub fn check_required_kvm_extensions(kvm: &Kvm) -> KvmResult<()> {
|
pub fn check_required_kvm_extensions(kvm: &Kvm) -> KvmResult<()> {
|
||||||
if !kvm.check_extension(Cap::GetTscKhz) {
|
macro_rules! check_extension {
|
||||||
return Err(KvmError::CapabilityMissing(Cap::GetTscKhz));
|
($cap:expr) => {
|
||||||
}
|
if !kvm.check_extension($cap) {
|
||||||
if !kvm.check_extension(Cap::ImmediateExit) {
|
return Err(KvmError::CapabilityMissing($cap));
|
||||||
return Err(KvmError::CapabilityMissing(Cap::ImmediateExit));
|
}
|
||||||
}
|
};
|
||||||
if !kvm.check_extension(Cap::SetIdentityMapAddr) {
|
|
||||||
return Err(KvmError::CapabilityMissing(Cap::SetIdentityMapAddr));
|
|
||||||
}
|
|
||||||
if !kvm.check_extension(Cap::SetTssAddr) {
|
|
||||||
return Err(KvmError::CapabilityMissing(Cap::SetTssAddr));
|
|
||||||
}
|
|
||||||
if !kvm.check_extension(Cap::SplitIrqchip) {
|
|
||||||
return Err(KvmError::CapabilityMissing(Cap::SplitIrqchip));
|
|
||||||
}
|
|
||||||
if !kvm.check_extension(Cap::TscDeadlineTimer) {
|
|
||||||
return Err(KvmError::CapabilityMissing(Cap::TscDeadlineTimer));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_extension!(Cap::GetTscKhz);
|
||||||
|
check_extension!(Cap::ImmediateExit);
|
||||||
|
check_extension!(Cap::SetIdentityMapAddr);
|
||||||
|
check_extension!(Cap::SetTssAddr);
|
||||||
|
check_extension!(Cap::SplitIrqchip);
|
||||||
|
check_extension!(Cap::TscDeadlineTimer);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
|
|||||||
Reference in New Issue
Block a user