vm-virtio: Add notifier to VirtioInterrupt trait

The point is to be able to retrieve directly the event fd related to
the interrupt, as this might optimize the way VirtioDevice devices are
implemented.

For instance, this can be used by vhost-user devices to provide
vhost-user backends directly with the event fd triggering the
interrupt related to a virtqueue.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2020-01-13 20:43:53 +01:00 committed by Samuel Ortiz
parent c396baca46
commit 1f029dd2dc
2 changed files with 23 additions and 0 deletions

View File

@ -23,6 +23,9 @@ 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> {
None
}
}
pub type VirtioIommuRemapping =

View File

@ -517,6 +517,26 @@ impl VirtioInterrupt for VirtioInterruptMsix {
config.irq_routes[vector as usize].irq_fd.write(1)
}
fn notifier(&self, int_type: &VirtioInterruptType, queue: Option<&Queue>) -> Option<EventFd> {
let vector = match int_type {
VirtioInterruptType::Config => self.config_vector.load(Ordering::SeqCst),
VirtioInterruptType::Queue => {
if let Some(q) = queue {
q.vector
} else {
0
}
}
};
Some(
self.msix_config.lock().unwrap().irq_routes[vector as usize]
.irq_fd
.try_clone()
.unwrap(),
)
}
}
impl PciDevice for VirtioPciDevice {