mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-09-12 10:04:51 +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,
|
IommuDmaUnmap,
|
||||||
VfioDeviceGetIrqInfo,
|
VfioDeviceGetIrqInfo,
|
||||||
VfioDeviceSetIrq,
|
VfioDeviceSetIrq,
|
||||||
|
VfioNoIommuGroup(String),
|
||||||
ReadLink(io::Error),
|
ReadLink(io::Error),
|
||||||
ParseInt(num::ParseIntError),
|
ParseInt(num::ParseIntError),
|
||||||
}
|
}
|
||||||
@ -104,6 +105,7 @@ impl fmt::Display for VfioError {
|
|||||||
VfioError::VfioDeviceGetIrqInfo => write!(f, "failed to get vfio device irq info"),
|
VfioError::VfioDeviceGetIrqInfo => write!(f, "failed to get vfio device irq info"),
|
||||||
VfioError::VfioDeviceSetIrq => write!(f, "failed to set vfio deviece irq"),
|
VfioError::VfioDeviceSetIrq => write!(f, "failed to set vfio deviece irq"),
|
||||||
VfioError::ReadLink(e) => write!(f, "failed to read link from path: {}", e),
|
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),
|
VfioError::ParseInt(e) => write!(f, "failed to parse integer: {}", e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -602,6 +604,11 @@ impl VfioDevice {
|
|||||||
iommu_attached: bool,
|
iommu_attached: bool,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let uuid_path: PathBuf = [sysfspath, Path::new("iommu_group")].iter().collect();
|
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_path = uuid_path.read_link().map_err(VfioError::ReadLink)?;
|
||||||
let group_osstr = group_path.file_name().ok_or(VfioError::InvalidPath)?;
|
let group_osstr = group_path.file_name().ok_or(VfioError::InvalidPath)?;
|
||||||
let group_str = group_osstr.to_str().ok_or(VfioError::InvalidPath)?;
|
let group_str = group_osstr.to_str().ok_or(VfioError::InvalidPath)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user