virtio-devices: Simplify virtio device reset

Rather than having to give and return the ioeventfd used for a device
clone them each time. This will make it simpler when we start handling
the driver enabling fewer queues than advertised by the device.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2021-01-18 12:38:08 +00:00
parent c99d3f70ac
commit 23f9ec50fb
16 changed files with 38 additions and 52 deletions

View File

@ -464,7 +464,7 @@ impl VirtioDevice for Balloon {
Ok(())
}
fn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)> {
fn reset(&mut self) -> Option<Arc<dyn VirtioInterrupt>> {
self.common.reset()
}
}

View File

@ -512,7 +512,7 @@ impl<T: 'static + DiskFile + Send> VirtioDevice for Block<T> {
Ok(())
}
fn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)> {
fn reset(&mut self) -> Option<Arc<dyn VirtioInterrupt>> {
self.common.reset()
}

View File

@ -581,7 +581,7 @@ impl VirtioDevice for BlockIoUring {
Ok(())
}
fn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)> {
fn reset(&mut self) -> Option<Arc<dyn VirtioInterrupt>> {
self.common.reset()
}

View File

@ -489,7 +489,7 @@ impl VirtioDevice for Console {
Ok(())
}
fn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)> {
fn reset(&mut self) -> Option<Arc<dyn VirtioInterrupt>> {
self.common.reset()
}
}

View File

@ -116,7 +116,7 @@ pub trait VirtioDevice: Send {
/// Optionally deactivates this device and returns ownership of the guest memory map, interrupt
/// event, and queue events.
fn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)> {
fn reset(&mut self) -> Option<Arc<dyn VirtioInterrupt>> {
None
}
@ -288,7 +288,7 @@ impl VirtioCommon {
Ok(())
}
pub fn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)> {
pub fn reset(&mut self) -> Option<Arc<dyn VirtioInterrupt>> {
// We first must resume the virtio thread if it was paused.
if self.pause_evt.take().is_some() {
self.resume().ok()?;
@ -307,11 +307,8 @@ impl VirtioCommon {
}
}
// Return the interrupt and queue EventFDs
Some((
self.interrupt_cb.take().unwrap(),
self.queue_evts.take().unwrap(),
))
// Return the interrupt
Some(self.interrupt_cb.take().unwrap())
}
}

View File

@ -953,7 +953,7 @@ impl VirtioDevice for Iommu {
Ok(())
}
fn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)> {
fn reset(&mut self) -> Option<Arc<dyn VirtioInterrupt>> {
self.common.reset()
}
}

View File

@ -878,7 +878,7 @@ impl VirtioDevice for Mem {
Ok(())
}
fn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)> {
fn reset(&mut self) -> Option<Arc<dyn VirtioInterrupt>> {
self.common.reset()
}
}

View File

@ -523,7 +523,7 @@ impl VirtioDevice for Net {
Err(ActivateError::BadActivate)
}
fn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)> {
fn reset(&mut self) -> Option<Arc<dyn VirtioInterrupt>> {
self.common.reset()
}

View File

@ -434,7 +434,7 @@ impl VirtioDevice for Pmem {
Err(ActivateError::BadActivate)
}
fn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)> {
fn reset(&mut self) -> Option<Arc<dyn VirtioInterrupt>> {
self.common.reset()
}

View File

@ -279,7 +279,7 @@ impl VirtioDevice for Rng {
Err(ActivateError::BadActivate)
}
fn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)> {
fn reset(&mut self) -> Option<Arc<dyn VirtioInterrupt>> {
self.common.reset()
}
}

View File

@ -659,13 +659,13 @@ impl VirtioPciDevice {
if self.memory.is_some() {
let mem = self.memory.as_ref().unwrap().clone();
let mut device = self.device.lock().unwrap();
let mut queue_evts = Vec::new();
let queues = self.queues.clone();
for i in 0..queues.len() {
queue_evts.push(self.queue_evts[i].try_clone().unwrap());
}
device
.activate(
mem,
virtio_interrupt,
self.queues.clone(),
self.queue_evts.split_off(0),
)
.activate(mem, virtio_interrupt, queues, queue_evts)
.expect("Failed to activate device");
self.device_activated.store(true, Ordering::SeqCst);
info!("{}: Waiting for barrier", self.id);
@ -1032,11 +1032,9 @@ impl PciDevice for VirtioPciDevice {
// Device has been reset by the driver
if self.device_activated.load(Ordering::SeqCst) && self.is_driver_init() {
let mut device = self.device.lock().unwrap();
if let Some((virtio_interrupt, mut queue_evts)) = device.reset() {
// Upon reset the device returns its interrupt EventFD and it's queue EventFDs
if let Some(virtio_interrupt) = device.reset() {
// Upon reset the device returns its interrupt EventFD
self.virtio_interrupt = Some(virtio_interrupt);
self.queue_evts.append(&mut queue_evts);
self.device_activated.store(false, Ordering::SeqCst);
// Reset queue readiness (changes queue_enable), queue sizes
@ -1162,13 +1160,13 @@ impl Snapshottable for VirtioPciDevice {
if self.memory.is_some() {
let mem = self.memory.as_ref().unwrap().clone();
let mut device = self.device.lock().unwrap();
let mut queue_evts = Vec::new();
let queues = self.queues.clone();
for i in 0..queues.len() {
queue_evts.push(self.queue_evts[i].try_clone().unwrap());
}
device
.activate(
mem,
virtio_interrupt,
self.queues.clone(),
self.queue_evts.split_off(0),
)
.activate(mem, virtio_interrupt, queues, queue_evts)
.map_err(|e| {
MigratableError::Restore(anyhow!(
"Failed activating the device: {:?}",

View File

@ -274,7 +274,7 @@ impl VirtioDevice for Blk {
Ok(())
}
fn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)> {
fn reset(&mut self) -> Option<Arc<dyn VirtioInterrupt>> {
// We first must resume the virtio thread if it was paused.
if self.common.pause_evt.take().is_some() {
self.common.resume().ok()?;
@ -290,11 +290,8 @@ impl VirtioDevice for Blk {
let _ = kill_evt.write(1);
}
// Return the interrupt and queue EventFDs
Some((
self.common.interrupt_cb.take().unwrap(),
self.common.queue_evts.take().unwrap(),
))
// Return the interrupt
Some(self.common.interrupt_cb.take().unwrap())
}
fn shutdown(&mut self) {

View File

@ -494,7 +494,7 @@ impl VirtioDevice for Fs {
Ok(())
}
fn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)> {
fn reset(&mut self) -> Option<Arc<dyn VirtioInterrupt>> {
// We first must resume the virtio thread if it was paused.
if self.common.pause_evt.take().is_some() {
self.common.resume().ok()?;
@ -510,11 +510,8 @@ impl VirtioDevice for Fs {
let _ = kill_evt.write(1);
}
// Return the interrupt and queue EventFDs
Some((
self.common.interrupt_cb.take().unwrap(),
self.common.queue_evts.take().unwrap(),
))
// Return the interrupt
Some(self.common.interrupt_cb.take().unwrap())
}
fn shutdown(&mut self) {

View File

@ -330,7 +330,7 @@ impl VirtioDevice for Net {
Ok(())
}
fn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)> {
fn reset(&mut self) -> Option<Arc<dyn VirtioInterrupt>> {
// We first must resume the virtio thread if it was paused.
if self.common.pause_evt.take().is_some() {
self.common.resume().ok()?;
@ -346,11 +346,8 @@ impl VirtioDevice for Net {
let _ = kill_evt.write(1);
}
// Return the interrupt and queue EventFDs
Some((
self.common.interrupt_cb.take().unwrap(),
self.common.queue_evts.take().unwrap(),
))
// Return the interrupt
Some(self.common.interrupt_cb.take().unwrap())
}
fn shutdown(&mut self) {

View File

@ -475,7 +475,7 @@ where
Ok(())
}
fn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)> {
fn reset(&mut self) -> Option<Arc<dyn VirtioInterrupt>> {
self.common.reset()
}

View File

@ -358,7 +358,7 @@ impl VirtioDevice for Watchdog {
Ok(())
}
fn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)> {
fn reset(&mut self) -> Option<Arc<dyn VirtioInterrupt>> {
self.common.reset()
}
}