mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-01 20:06:35 +00:00
Merge pull request #10938 from Apokleos/fix-iommugrp-symlink
runtime-rs: Simplify iommu group base name extraction from symlink
This commit is contained in:
commit
5774f131ec
@ -5,6 +5,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
ffi::OsStr,
|
||||||
fs,
|
fs,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::Command,
|
process::Command,
|
||||||
@ -759,14 +760,21 @@ pub fn get_vfio_iommu_group(bdf: String) -> Result<String> {
|
|||||||
let iommugrp_symlink = fs::read_link(&iommugrp_path)
|
let iommugrp_symlink = fs::read_link(&iommugrp_path)
|
||||||
.map_err(|e| anyhow!("read iommu group symlink failed {:?}", e))?;
|
.map_err(|e| anyhow!("read iommu group symlink failed {:?}", e))?;
|
||||||
|
|
||||||
// get base name from iommu group symlink: X
|
// Just get base name from iommu group symlink is enough as it will be checked
|
||||||
let iommu_group = get_base_name(iommugrp_symlink)?
|
// within the full path /sys/kernel/iommu_groups/$iommu_group in the subsequent step.
|
||||||
.into_string()
|
let iommu_group = iommugrp_symlink
|
||||||
.map_err(|e| anyhow!("failed to get iommu group {:?}", e))?;
|
.file_name()
|
||||||
|
.and_then(OsStr::to_str)
|
||||||
|
.ok_or_else(|| {
|
||||||
|
anyhow!(
|
||||||
|
"failed to get iommu group with symlink {:?}",
|
||||||
|
iommugrp_symlink
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
// we'd better verify the path to ensure it dose exist.
|
// we'd better verify the path to ensure it dose exist.
|
||||||
if !Path::new(SYS_KERN_IOMMU_GROUPS)
|
if !Path::new(SYS_KERN_IOMMU_GROUPS)
|
||||||
.join(&iommu_group)
|
.join(iommu_group)
|
||||||
.join("devices")
|
.join("devices")
|
||||||
.join(dbdf.as_str())
|
.join(dbdf.as_str())
|
||||||
.exists()
|
.exists()
|
||||||
|
Loading…
Reference in New Issue
Block a user