interrupt: Make notifier function return Option<EventFd>

In anticipation for supporting the notifier function for the legacy
interrupt source group, we need this function to return an EventFd
instead of a reference to this same EventFd.

The reason is we can't return a reference when there's an Arc<Mutex<>>
involved in the call chain.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2021-02-09 08:20:45 +01:00 committed by Rob Bradford
parent 62c6efb2e5
commit acfbee5b7a
6 changed files with 16 additions and 16 deletions

View File

@ -476,8 +476,8 @@ mod tests {
Ok(())
}
fn notifier(&self, _index: InterruptIndex) -> Option<&EventFd> {
Some(&self.event_fd)
fn notifier(&self, _index: InterruptIndex) -> Option<EventFd> {
Some(self.event_fd.try_clone().unwrap())
}
}

View File

@ -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<EventFd> = 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<EventFd> = 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);
}
}

View File

@ -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<EventFd> {
None
}
}

View File

@ -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<EventFd> {
let vector = match int_type {
VirtioInterruptType::Config => self.config_vector.load(Ordering::Acquire),
VirtioInterruptType::Queue => {

View File

@ -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<EventFd> {
// One use case of the notifier is to implement vhost user backends.
// For all other implementations we can just return None here.
None

View File

@ -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<EventFd> {
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<EventFd> {
if let Some(route) = self.irq_routes.get(&index) {
return route.notifier();
}