diff --git a/devices/src/legacy/rtc_pl031.rs b/devices/src/legacy/rtc_pl031.rs index 2793642e8..e77726cd0 100644 --- a/devices/src/legacy/rtc_pl031.rs +++ b/devices/src/legacy/rtc_pl031.rs @@ -476,8 +476,8 @@ mod tests { Ok(()) } - fn notifier(&self, _index: InterruptIndex) -> Option<&EventFd> { - Some(&self.event_fd) + fn notifier(&self, _index: InterruptIndex) -> Option { + Some(self.event_fd.try_clone().unwrap()) } } diff --git a/pci/src/vfio.rs b/pci/src/vfio.rs index 2ef93e83c..3868930ba 100644 --- a/pci/src/vfio.rs +++ b/pci/src/vfio.rs @@ -429,7 +429,7 @@ impl VfioPciDevice { match self.interrupt.update_msi(offset, data) { Some(InterruptUpdateAction::EnableMsi) => { if let Some(msi) = &self.interrupt.msi { - let mut irq_fds: Vec<&EventFd> = Vec::new(); + let mut irq_fds: Vec = Vec::new(); for i in 0..msi.cfg.num_enabled_vectors() { if let Some(eventfd) = msi.interrupt_source_group.notifier(i as InterruptIndex) @@ -440,7 +440,7 @@ impl VfioPciDevice { } } - if let Err(e) = self.device.enable_msi(irq_fds) { + if let Err(e) = self.device.enable_msi(irq_fds.iter().collect()) { warn!("Could not enable MSI: {}", e); } } @@ -460,7 +460,7 @@ impl VfioPciDevice { match self.interrupt.update_msix(offset, data) { Some(InterruptUpdateAction::EnableMsix) => { if let Some(msix) = &self.interrupt.msix { - let mut irq_fds: Vec<&EventFd> = Vec::new(); + let mut irq_fds: Vec = Vec::new(); for i in 0..msix.bar.table_entries.len() { if let Some(eventfd) = msix.interrupt_source_group.notifier(i as InterruptIndex) @@ -471,7 +471,7 @@ impl VfioPciDevice { } } - if let Err(e) = self.device.enable_msix(irq_fds) { + if let Err(e) = self.device.enable_msix(irq_fds.iter().collect()) { warn!("Could not enable MSI-X: {}", e); } } diff --git a/virtio-devices/src/device.rs b/virtio-devices/src/device.rs index 11587e327..bbe457861 100644 --- a/virtio-devices/src/device.rs +++ b/virtio-devices/src/device.rs @@ -32,11 +32,7 @@ pub trait VirtioInterrupt: Send + Sync { int_type: &VirtioInterruptType, queue: Option<&Queue>, ) -> std::result::Result<(), std::io::Error>; - fn notifier( - &self, - _int_type: &VirtioInterruptType, - _queue: Option<&Queue>, - ) -> Option<&EventFd> { + fn notifier(&self, _int_type: &VirtioInterruptType, _queue: Option<&Queue>) -> Option { None } } diff --git a/virtio-devices/src/transport/pci_device.rs b/virtio-devices/src/transport/pci_device.rs index 3397f4c83..ca9615794 100644 --- a/virtio-devices/src/transport/pci_device.rs +++ b/virtio-devices/src/transport/pci_device.rs @@ -755,7 +755,7 @@ impl VirtioInterrupt for VirtioInterruptMsix { .trigger(vector as InterruptIndex) } - fn notifier(&self, int_type: &VirtioInterruptType, queue: Option<&Queue>) -> Option<&EventFd> { + fn notifier(&self, int_type: &VirtioInterruptType, queue: Option<&Queue>) -> Option { let vector = match int_type { VirtioInterruptType::Config => self.config_vector.load(Ordering::Acquire), VirtioInterruptType::Queue => { diff --git a/vm-device/src/interrupt/mod.rs b/vm-device/src/interrupt/mod.rs index 360d52b48..9aedcfdbf 100644 --- a/vm-device/src/interrupt/mod.rs +++ b/vm-device/src/interrupt/mod.rs @@ -169,7 +169,7 @@ pub trait InterruptSourceGroup: Send + Sync { /// to inject interrupts into a guest, by writing to the file returned /// by this method. #[allow(unused_variables)] - fn notifier(&self, index: InterruptIndex) -> Option<&EventFd> { + fn notifier(&self, index: InterruptIndex) -> Option { // One use case of the notifier is to implement vhost user backends. // For all other implementations we can just return None here. None diff --git a/vmm/src/interrupt.rs b/vmm/src/interrupt.rs index 0c4756cb2..d597597e7 100644 --- a/vmm/src/interrupt.rs +++ b/vmm/src/interrupt.rs @@ -74,8 +74,12 @@ impl InterruptRoute { self.irq_fd.write(1) } - pub fn notifier(&self) -> Option<&EventFd> { - Some(&self.irq_fd) + pub fn notifier(&self) -> Option { + Some( + self.irq_fd + .try_clone() + .expect("Failed cloning interrupt's EventFd"), + ) } } @@ -149,7 +153,7 @@ where )) } - fn notifier(&self, index: InterruptIndex) -> Option<&EventFd> { + fn notifier(&self, index: InterruptIndex) -> Option { if let Some(route) = self.irq_routes.get(&index) { return route.notifier(); }