mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-01 17:35:19 +00:00
hypervisor: Remove panic from Hypervisor::check_required_extensions()
Remove the panic by replacing the .expect() with a cleaner error handling. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
a335cbb8d5
commit
84454f142d
@ -54,6 +54,11 @@ pub enum HypervisorError {
|
||||
///
|
||||
#[error("Incompatible API version")]
|
||||
IncompatibleApiVersion,
|
||||
///
|
||||
/// Checking extensions failed
|
||||
///
|
||||
#[error("Checking extensions:{0}")]
|
||||
CheckExtensions(#[source] anyhow::Error),
|
||||
}
|
||||
|
||||
///
|
||||
|
@ -70,9 +70,9 @@ pub use kvm_ioctls;
|
||||
pub use kvm_ioctls::{Cap, Kvm};
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
use std::mem;
|
||||
use thiserror::Error;
|
||||
#[cfg(feature = "tdx")]
|
||||
use vmm_sys_util::{ioctl::ioctl_with_val, ioctl_expr, ioctl_ioc_nr, ioctl_iowr_nr};
|
||||
|
||||
///
|
||||
/// Export generically-named wrappers of kvm-bindings for Unix-based platforms
|
||||
///
|
||||
@ -465,8 +465,9 @@ pub struct KvmHypervisor {
|
||||
kvm: Kvm,
|
||||
}
|
||||
/// Enum for KVM related error
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum KvmError {
|
||||
#[error("Capability missing: {0:?}")]
|
||||
CapabilityMissing(Cap),
|
||||
}
|
||||
pub type KvmResult<T> = result::Result<T, KvmError>;
|
||||
@ -561,8 +562,8 @@ impl hypervisor::Hypervisor for KvmHypervisor {
|
||||
}
|
||||
|
||||
fn check_required_extensions(&self) -> hypervisor::Result<()> {
|
||||
check_required_kvm_extensions(&self.kvm).expect("Missing KVM capabilities");
|
||||
Ok(())
|
||||
check_required_kvm_extensions(&self.kvm)
|
||||
.map_err(|e| hypervisor::HypervisorError::CheckExtensions(e.into()))
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
|
Loading…
x
Reference in New Issue
Block a user