Inner restore implementation. When `skip_deregister` is `true` the caller has already removed the device's vendor:device ID from vfio-pci's match table (e.g. via a cached value), so we skip the sysfs-based deregistration.
(
sysfs: &SysfsRoot,
bdf: &str,
skip_deregister: bool,
)
| 211 | /// device's vendor:device ID from vfio-pci's match table (e.g. via a cached |
| 212 | /// value), so we skip the sysfs-based deregistration. |
| 213 | pub(crate) fn restore_to_host_driver_ex( |
| 214 | sysfs: &SysfsRoot, |
| 215 | bdf: &str, |
| 216 | skip_deregister: bool, |
| 217 | ) -> Result<(), VfioError> { |
| 218 | let device = sysfs.pci_device_ref(bdf); |
| 219 | |
| 220 | if !skip_deregister { |
| 221 | // Deregister the device ID from vfio-pci's match table before |
| 222 | // unbind+reprobe. Without this, drivers_probe re-binds to vfio-pci |
| 223 | // via the still-registered new_id entry. |
| 224 | deregister_vfio_new_id(sysfs, bdf); |
| 225 | } |
| 226 | |
| 227 | let unbind_path = device.driver_unbind_path(); |
| 228 | if unbind_path.exists() { |
| 229 | write_sysfs(&unbind_path, bdf).map_err(|e| VfioError::UnbindFailed { |
| 230 | bdf: bdf.to_string(), |
| 231 | reason: format!("unbind: {e}"), |
| 232 | })?; |
| 233 | } |
| 234 | |
| 235 | if device.driver_override_path().exists() { |
| 236 | device |
| 237 | .clear_driver_override() |
| 238 | .map_err(|e| VfioError::UnbindFailed { |
| 239 | bdf: bdf.to_string(), |
| 240 | reason: format!("clear driver_override: {e}"), |
| 241 | })?; |
| 242 | } |
| 243 | |
| 244 | let probe = sysfs.drivers_probe(); |
| 245 | if probe.exists() { |
| 246 | write_sysfs(&probe, bdf).map_err(|e| VfioError::UnbindFailed { |
| 247 | bdf: bdf.to_string(), |
| 248 | reason: format!("drivers_probe: {e}"), |
| 249 | })?; |
| 250 | } |
| 251 | |
| 252 | tracing::info!(bdf, "PCI device restored to host driver"); |
| 253 | Ok(()) |
| 254 | } |
| 255 | |
| 256 | /// Process-local reference counter for vendor:device ID registrations in the |
| 257 | /// vfio-pci match table. Multiple devices may share the same vendor:device |
no test coverage detected