mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-23 04:55:22 +00:00
vfio: handle case for missing iommu_group
For cases where IOMMU is not supported, iommu_group will be no present. This could happened because IOMMU is off at kernel level, bios level or is not supported at all. Instead of fail with a generic error handle it as different use case: Before: ReadLink(Os { code: 2, kind: NotFound, message: "No such file or directory"}) After: VfioNoIommuGroup("/sys/bus/pci/devices/0000:03:00.0/iommu_group") Signed-off-by: Jose Carlos Venegas Munoz <jose.carlos.venegas.munoz@intel.com>
This commit is contained in:
parent
cfbebd8852
commit
6539d4a873
@ -53,6 +53,7 @@ pub enum VfioError {
|
||||
IommuDmaUnmap,
|
||||
VfioDeviceGetIrqInfo,
|
||||
VfioDeviceSetIrq,
|
||||
VfioNoIommuGroup(String),
|
||||
ReadLink(io::Error),
|
||||
ParseInt(num::ParseIntError),
|
||||
}
|
||||
@ -104,6 +105,7 @@ impl fmt::Display for VfioError {
|
||||
VfioError::VfioDeviceGetIrqInfo => write!(f, "failed to get vfio device irq info"),
|
||||
VfioError::VfioDeviceSetIrq => write!(f, "failed to set vfio deviece irq"),
|
||||
VfioError::ReadLink(e) => write!(f, "failed to read link from path: {}", e),
|
||||
VfioError::VfioNoIommuGroup(e) => write!(f, "Failed to find iommu_group for: {}", e),
|
||||
VfioError::ParseInt(e) => write!(f, "failed to parse integer: {}", e),
|
||||
}
|
||||
}
|
||||
@ -602,6 +604,11 @@ impl VfioDevice {
|
||||
iommu_attached: bool,
|
||||
) -> Result<Self> {
|
||||
let uuid_path: PathBuf = [sysfspath, Path::new("iommu_group")].iter().collect();
|
||||
if !uuid_path.exists() {
|
||||
return Err(VfioError::VfioNoIommuGroup(
|
||||
uuid_path.to_str().unwrap().to_string(),
|
||||
));
|
||||
}
|
||||
let group_path = uuid_path.read_link().map_err(VfioError::ReadLink)?;
|
||||
let group_osstr = group_path.file_name().ok_or(VfioError::InvalidPath)?;
|
||||
let group_str = group_osstr.to_str().ok_or(VfioError::InvalidPath)?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user