From 066ce7ab51220caf76bbcf53a61f9fffd8f55899 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 9 Feb 2021 10:58:30 +1100 Subject: [PATCH] agent/device: Pass root bus sysfs path to pcipath_to_sysfs() Currently pcipath_to_sysfs() generates the path to the root bus node in sysfs via create_pci_root_bus_path(). This is inconvenient for testing, though, so instead make it take this as a parameter and generate the path in the (single) caller. As a bonus this will make life a bit easier when we want to support machines with multiple PCI roots. Signed-off-by: David Gibson --- src/agent/src/device.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/agent/src/device.rs b/src/agent/src/device.rs index a8c49b123..b4d10a36d 100644 --- a/src/agent/src/device.rs +++ b/src/agent/src/device.rs @@ -50,10 +50,9 @@ pub fn online_device(path: &str) -> Result<()> { // pciPathToSysfs fetches the sysfs path for a PCI path, relative to // the syfs path for the PCI host bridge, based on the PCI path // provided. -fn pcipath_to_sysfs(pcipath: &pci::Path) -> Result { +fn pcipath_to_sysfs(root_bus_sysfs: &str, pcipath: &pci::Path) -> Result { let mut bus = "0000:00".to_string(); let mut relpath = String::new(); - let root_bus_sysfs = format!("{}{}", SYSFS_DIR, create_pci_root_bus_path()); for i in 0..pcipath.len() { let bdf = format!("{}:{}.0", bus, pcipath[i]); @@ -148,7 +147,8 @@ pub async fn get_pci_device_name( sandbox: &Arc>, pcipath: &pci::Path, ) -> Result { - let sysfs_rel_path = pcipath_to_sysfs(pcipath)?; + let root_bus_sysfs = format!("{}{}", SYSFS_DIR, create_pci_root_bus_path()); + let sysfs_rel_path = pcipath_to_sysfs(&root_bus_sysfs, pcipath)?; rescan_pci_bus()?; get_device_name(sandbox, &sysfs_rel_path).await