agent/device: Use consistent matching for past and future uevents

get_device_name() looks at kernel uevents to work out the device name for
a given PCI (usually) address.  However, when we call it we can't know if
the uevent we're interested in has already happened (in which case it will
have been recorded in Sandbox::uevent_map) or yet to come, in which case
we need to register to watch it.

However, we currently match differently against past and future events.
For past events we simply look for a sysfs path including the address, but
for future events we use a complex bit of logic in the is_match() closure.
Change it to use the exact same matching logic in both cases.

fixes #1397

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2021-03-05 15:47:45 +11:00
parent 4b16681d87
commit 16ed55e440

View File

@ -135,8 +135,8 @@ async fn get_device_name(sandbox: &Arc<Mutex<Sandbox>>, dev_addr: &str) -> Resul
let matcher = DevAddrMatcher::new(dev_addr);
let mut sb = sandbox.lock().await;
for (key, uev) in sb.uevent_map.iter() {
if key.contains(dev_addr) {
for uev in sb.uevent_map.values() {
if matcher.is_match(uev) {
info!(sl!(), "Device {} found in pci device map", dev_addr);
return Ok(format!("{}/{}", SYSTEM_DEV_PATH, uev.devname));
}