MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / probe_host_nvidia_vfio_readiness

Function probe_host_nvidia_vfio_readiness

crates/openshell-vfio/src/gpu.rs:27–77  ·  view source on GitHub ↗

Scan sysfs for NVIDIA GPUs eligible for VFIO passthrough.

(sysfs: &SysfsRoot)

Source from the content-addressed store, hash-verified

25
26/// Scan sysfs for NVIDIA GPUs eligible for VFIO passthrough.
27pub fn probe_host_nvidia_vfio_readiness(sysfs: &SysfsRoot) -> Vec<PciInfo> {
28 let devices_dir = sysfs.pci_devices_dir();
29 let entries = match fs::read_dir(&devices_dir) {
30 Ok(e) => e,
31 Err(err) => {
32 tracing::warn!(path = %devices_dir.display(), %err, "cannot read PCI devices directory");
33 return Vec::new();
34 }
35 };
36
37 let mut gpus = Vec::new();
38
39 for entry in entries.filter_map(Result::ok) {
40 let bdf = entry.file_name().to_string_lossy().into_owned();
41 let device = sysfs.pci_device_ref(&bdf);
42
43 let Ok(vendor) = device.vendor() else {
44 continue;
45 };
46 if vendor != NVIDIA_VENDOR_ID {
47 continue;
48 }
49
50 let Ok(class) = device.class() else {
51 continue;
52 };
53 if !is_gpu_class(&class) {
54 continue;
55 }
56
57 let device_id = device.device_id().unwrap_or_default();
58
59 let name = device
60 .read_trimmed("label")
61 .unwrap_or_else(|_| format!("NVIDIA {device_id}"));
62
63 let Ok(iommu_group) = sysfs.iommu_group(&bdf) else {
64 continue;
65 };
66
67 gpus.push(PciInfo {
68 bdf,
69 name,
70 vendor,
71 device: device_id,
72 iommu_group,
73 });
74 }
75
76 gpus
77}
78
79/// Bind a GPU to `vfio-pci`, returning an RAII guard that restores it on drop.
80///

Callers 4

newMethod · 0.85

Calls 9

is_gpu_classFunction · 0.85
pci_devices_dirMethod · 0.80
pci_device_refMethod · 0.80
vendorMethod · 0.80
classMethod · 0.80
device_idMethod · 0.80
read_trimmedMethod · 0.80
iommu_groupMethod · 0.80
pushMethod · 0.80