diff --git a/src/agent/src/device.rs b/src/agent/src/device.rs index d6117839c..8d756a9d0 100644 --- a/src/agent/src/device.rs +++ b/src/agent/src/device.rs @@ -17,6 +17,7 @@ use crate::linux_abi::*; use crate::mount::{DRIVER_BLK_TYPE, DRIVER_MMIO_BLK_TYPE, DRIVER_NVDIMM_TYPE, DRIVER_SCSI_TYPE}; use crate::pci; use crate::sandbox::Sandbox; +use crate::uevent::Uevent; use crate::AGENT_CONFIG; use anyhow::{anyhow, Result}; use oci::{LinuxDeviceCgroup, LinuxResources, Spec}; @@ -101,14 +102,14 @@ async fn get_device_name(sandbox: &Arc>, dev_addr: &str) -> Resul // The key of the watchers map is the device we are interested in. // Note this is done inside the lock, not to miss any events from the // global udev listener. - let (tx, rx) = tokio::sync::oneshot::channel::(); + let (tx, rx) = tokio::sync::oneshot::channel::(); sb.dev_watcher.insert(dev_addr.to_string(), tx); drop(sb); // unlock info!(sl!(), "Waiting on channel for device notification\n"); let hotplug_timeout = AGENT_CONFIG.read().await.hotplug_timeout; - let dev_name = match tokio::time::timeout(hotplug_timeout, rx).await { + let uev = match tokio::time::timeout(hotplug_timeout, rx).await { Ok(v) => v?, Err(_) => { let mut sb = sandbox.lock().await; @@ -122,7 +123,7 @@ async fn get_device_name(sandbox: &Arc>, dev_addr: &str) -> Resul } }; - Ok(format!("{}/{}", SYSTEM_DEV_PATH, &dev_name)) + Ok(format!("{}/{}", SYSTEM_DEV_PATH, &uev.devname)) } pub async fn get_scsi_device_name( @@ -796,7 +797,7 @@ mod tests { assert_eq!(name.unwrap(), format!("{}/{}", SYSTEM_DEV_PATH, devname)); let mut sb = sandbox.lock().await; - sb.uevent_map.remove(&devpath); + let uev = sb.uevent_map.remove(&devpath).unwrap(); drop(sb); // unlock let watcher_sandbox = Arc::clone(&sandbox); @@ -812,7 +813,7 @@ mod tests { if let Some(k) = matched_key { let sender = sb.dev_watcher.remove(&k).unwrap(); - let _ = sender.send(devname.to_string()); + let _ = sender.send(uev); return; } drop(sb); // unlock diff --git a/src/agent/src/sandbox.rs b/src/agent/src/sandbox.rs index 8b1c4561c..fd9eab0fb 100644 --- a/src/agent/src/sandbox.rs +++ b/src/agent/src/sandbox.rs @@ -38,7 +38,7 @@ pub struct Sandbox { pub mounts: Vec, pub container_mounts: HashMap>, pub uevent_map: HashMap, - pub dev_watcher: HashMap>, + pub dev_watcher: HashMap>, pub shared_utsns: Namespace, pub shared_ipcns: Namespace, pub sandbox_pidns: Option, diff --git a/src/agent/src/uevent.rs b/src/agent/src/uevent.rs index 78bc400ab..5de4cecb4 100644 --- a/src/agent/src/uevent.rs +++ b/src/agent/src/uevent.rs @@ -98,12 +98,11 @@ impl Uevent { .collect(); for k in keys { - let devname = self.devname.clone(); // unwrap() is safe because logic above ensures k exists // in the map, and it's locked so no-one else can change // that let sender = sb.dev_watcher.remove(&k).unwrap(); - let _ = sender.send(devname); + let _ = sender.send(self.clone()); } }