virtio-devices: make ioeventfds() return an iterator

MSHV's SEV-SNP implementation calls ioeventfds whenever there is an
event.

This change removes the need frequent allocation and deallocation of a
vector, while at the same time makes sure other call sites are
unaffected.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2024-04-29 05:39:48 +00:00 committed by Wei Liu
parent d2e798944a
commit a1af4238ae
2 changed files with 8 additions and 12 deletions

View File

@ -9,5 +9,5 @@ pub use pci_common_config::{VirtioPciCommonConfig, VIRTIO_PCI_COMMON_CONFIG_ID};
pub use pci_device::{VirtioPciDevice, VirtioPciDeviceActivator, VirtioPciDeviceError};
pub trait VirtioTransport {
fn ioeventfds(&self, base_addr: u64) -> Vec<(&EventFd, u64)>;
fn ioeventfds(&self, base_addr: u64) -> impl Iterator<Item = (&EventFd, u64)>;
}

View File

@ -830,18 +830,14 @@ impl VirtioPciDevice {
}
impl VirtioTransport for VirtioPciDevice {
fn ioeventfds(&self, base_addr: u64) -> Vec<(&EventFd, u64)> {
fn ioeventfds(&self, base_addr: u64) -> impl Iterator<Item = (&EventFd, u64)> {
let notify_base = base_addr + NOTIFICATION_BAR_OFFSET;
self.queue_evts()
.iter()
.enumerate()
.map(|(i, event)| {
(
event,
notify_base + i as u64 * u64::from(NOTIFY_OFF_MULTIPLIER),
)
})
.collect()
self.queue_evts().iter().enumerate().map(move |(i, event)| {
(
event,
notify_base + i as u64 * u64::from(NOTIFY_OFF_MULTIPLIER),
)
})
}
}