From 72044180e48eb11f0c5d53f8243fd0cb0e03ae84 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 5 Oct 2021 14:33:03 +1100 Subject: [PATCH] agent/device: Return PCI address from wait_for_pci_device() wait_for_pci_device() waits for the PCI device at the given path to become ready, but it doesn't currently give you any meaningful handle on that device. Change the signature, so that it returns the PCI address of the device. Signed-off-by: David Gibson --- src/agent/src/device.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/agent/src/device.rs b/src/agent/src/device.rs index 93cf50cd5..3258be116 100644 --- a/src/agent/src/device.rs +++ b/src/agent/src/device.rs @@ -277,13 +277,23 @@ impl UeventMatcher for PciMatcher { } } -pub async fn wait_for_pci_device(sandbox: &Arc>, pcipath: &pci::Path) -> Result<()> { +pub async fn wait_for_pci_device( + sandbox: &Arc>, + pcipath: &pci::Path, +) -> Result { let root_bus_sysfs = format!("{}{}", SYSFS_DIR, create_pci_root_bus_path()); let sysfs_rel_path = pcipath_to_sysfs(&root_bus_sysfs, pcipath)?; let matcher = PciMatcher::new(&sysfs_rel_path)?; - let _ = wait_for_uevent(sandbox, matcher).await?; - Ok(()) + let uev = wait_for_uevent(sandbox, matcher).await?; + + let addr = uev + .devpath + .rsplit('/') + .next() + .ok_or_else(|| anyhow!("Bad device path {:?} in uevent", &uev.devpath))?; + let addr = pci::Address::from_str(addr)?; + Ok(addr) } /// Scan SCSI bus for the given SCSI address(SCSI-Id and LUN)