diff --git a/src/agent/src/uevent.rs b/src/agent/src/uevent.rs index 9d7a39fbf3..7f6269ddef 100644 --- a/src/agent/src/uevent.rs +++ b/src/agent/src/uevent.rs @@ -51,20 +51,34 @@ impl Uevent { event } - // Check whether this is a block device hot-add event. - fn is_block_add_event(&self) -> bool { + async fn process_add(&self, logger: &Logger, sandbox: &Arc>) { + // Special case for memory hot-adds first + let online_path = format!("{}/{}/online", SYSFS_DIR, &self.devpath); + if online_path.starts_with(SYSFS_MEMORY_ONLINE_PATH) { + let _ = online_device(online_path.as_ref()).map_err(|e| { + error!( + *logger, + "failed to online device"; + "device" => &self.devpath, + "error" => format!("{}", e), + ) + }); + return; + } + let pci_root_bus_path = create_pci_root_bus_path(); - self.action == U_EVENT_ACTION_ADD - && self.subsystem == "block" + + // Check whether this is a block device hot-add event. + if !(self.subsystem == "block" && { self.devpath.starts_with(pci_root_bus_path.as_str()) || self.devpath.starts_with(ACPI_DEV_PATH) // NVDIMM/PMEM devices } - && !self.devname.is_empty() - } + && !self.devname.is_empty()) + { + return; + } - async fn handle_block_add_event(&self, sandbox: &Arc>) { - let pci_root_bus_path = create_pci_root_bus_path(); let mut sb = sandbox.lock().await; // Record the event by sysfs path @@ -95,22 +109,8 @@ impl Uevent { } async fn process(&self, logger: &Logger, sandbox: &Arc>) { - if self.is_block_add_event() { - return self.handle_block_add_event(sandbox).await; - } else if self.action == U_EVENT_ACTION_ADD { - let online_path = format!("{}/{}/online", SYSFS_DIR, &self.devpath); - // It's a memory hot-add event. - if online_path.starts_with(SYSFS_MEMORY_ONLINE_PATH) { - let _ = online_device(online_path.as_ref()).map_err(|e| { - error!( - *logger, - "failed to online device"; - "device" => &self.devpath, - "error" => format!("{}", e), - ) - }); - return; - } + if self.action == U_EVENT_ACTION_ADD { + return self.process_add(logger, sandbox).await; } debug!(*logger, "ignoring event"; "uevent" => format!("{:?}", self)); }