mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
virtio-devices: introduce ActivationContext for device activation
Signed-off-by: Peter Oskolkov <posk@google.com>
This commit is contained in:
@@ -95,15 +95,15 @@ fuzz_target!(|bytes: &[u8]| -> Corpus {
|
||||
reporting_queue_evt.write(1).unwrap();
|
||||
|
||||
balloon
|
||||
.activate(
|
||||
guest_memory,
|
||||
Arc::new(NoopVirtioInterrupt {}),
|
||||
vec![
|
||||
.activate(virtio_devices::ActivationContext {
|
||||
mem: guest_memory,
|
||||
interrupt_cb: Arc::new(NoopVirtioInterrupt {}),
|
||||
queues: vec![
|
||||
(0, inflate_q, inflate_evt),
|
||||
(1, deflate_q, deflate_evt),
|
||||
(2, reporting_q, reporting_evt),
|
||||
],
|
||||
)
|
||||
})
|
||||
.ok();
|
||||
|
||||
// Wait for the events to finish and balloon device worker thread to return
|
||||
|
||||
@@ -91,11 +91,11 @@ fuzz_target!(|bytes: &[u8]| -> Corpus {
|
||||
queue_evt.write(1).unwrap();
|
||||
|
||||
block
|
||||
.activate(
|
||||
guest_memory,
|
||||
Arc::new(NoopVirtioInterrupt {}),
|
||||
vec![(0, q, evt)],
|
||||
)
|
||||
.activate(virtio_devices::ActivationContext {
|
||||
mem: guest_memory,
|
||||
interrupt_cb: Arc::new(NoopVirtioInterrupt {}),
|
||||
queues: vec![(0, q, evt)],
|
||||
})
|
||||
.ok();
|
||||
|
||||
// Wait for the events to finish and block device worker thread to return
|
||||
|
||||
@@ -128,11 +128,11 @@ fuzz_target!(|bytes: &[u8]| -> Corpus {
|
||||
pipe_tx.write_all(console_input_bytes).unwrap(); // To use fuzzed data;
|
||||
|
||||
console
|
||||
.activate(
|
||||
guest_memory,
|
||||
Arc::new(NoopVirtioInterrupt {}),
|
||||
vec![(0, input_queue, input_evt), (1, output_queue, output_evt)],
|
||||
)
|
||||
.activate(virtio_devices::ActivationContext {
|
||||
mem: guest_memory,
|
||||
interrupt_cb: Arc::new(NoopVirtioInterrupt {}),
|
||||
queues: vec![(0, input_queue, input_evt), (1, output_queue, output_evt)],
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
// Wait for the events to finish and console device worker thread to return
|
||||
|
||||
@@ -107,14 +107,14 @@ fuzz_target!(|bytes: &[u8]| -> Corpus {
|
||||
request_queue_evt.write(1).unwrap();
|
||||
|
||||
iommu
|
||||
.activate(
|
||||
guest_memory,
|
||||
Arc::new(NoopVirtioInterrupt {}),
|
||||
vec![
|
||||
.activate(virtio_devices::ActivationContext {
|
||||
mem: guest_memory,
|
||||
interrupt_cb: Arc::new(NoopVirtioInterrupt {}),
|
||||
queues: vec![
|
||||
(0, request_queue, request_evt),
|
||||
(0, _event_queue, _event_evt),
|
||||
],
|
||||
)
|
||||
})
|
||||
.ok();
|
||||
|
||||
// Wait for the events to finish and vIOMMU device worker thread to return
|
||||
|
||||
@@ -105,11 +105,11 @@ fuzz_target!(|bytes: &[u8]| -> Corpus {
|
||||
queue_evt.write(1).unwrap();
|
||||
|
||||
virtio_mem
|
||||
.activate(
|
||||
guest_memory,
|
||||
Arc::new(NoopVirtioInterrupt {}),
|
||||
vec![(0, q, evt)],
|
||||
)
|
||||
.activate(virtio_devices::ActivationContext {
|
||||
mem: guest_memory,
|
||||
interrupt_cb: Arc::new(NoopVirtioInterrupt {}),
|
||||
queues: vec![(0, q, evt)],
|
||||
})
|
||||
.ok();
|
||||
|
||||
// Wait for the events to finish and virtio-mem device worker thread to return
|
||||
|
||||
@@ -143,11 +143,11 @@ fuzz_target!(|bytes: &[u8]| -> Corpus {
|
||||
input_queue_evt.write(1).unwrap();
|
||||
output_queue_evt.write(1).unwrap();
|
||||
|
||||
net.activate(
|
||||
guest_memory,
|
||||
Arc::new(NoopVirtioInterrupt {}),
|
||||
vec![(0, input_queue, input_evt), (1, output_queue, output_evt)],
|
||||
)
|
||||
net.activate(virtio_devices::ActivationContext {
|
||||
mem: guest_memory,
|
||||
interrupt_cb: Arc::new(NoopVirtioInterrupt {}),
|
||||
queues: vec![(0, input_queue, input_evt), (1, output_queue, output_evt)],
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
// Wait for the events to finish and net device worker thread to return
|
||||
|
||||
@@ -61,11 +61,11 @@ fuzz_target!(|bytes: &[u8]| -> Corpus {
|
||||
// Kick the 'queue' event before activate the pmem device
|
||||
queue_evt.write(1).unwrap();
|
||||
|
||||
pmem.activate(
|
||||
guest_memory,
|
||||
Arc::new(NoopVirtioInterrupt {}),
|
||||
vec![(0, q, evt)],
|
||||
)
|
||||
pmem.activate(virtio_devices::ActivationContext {
|
||||
mem: guest_memory,
|
||||
interrupt_cb: Arc::new(NoopVirtioInterrupt {}),
|
||||
queues: vec![(0, q, evt)],
|
||||
})
|
||||
.ok();
|
||||
|
||||
// Wait for the events to finish and pmem device worker thread to return
|
||||
|
||||
@@ -99,11 +99,11 @@ fuzz_target!(|bytes: &[u8]| -> Corpus {
|
||||
// Kick the 'queue' event before activate the rng device
|
||||
queue_evt.write(1).unwrap();
|
||||
|
||||
rng.activate(
|
||||
guest_memory,
|
||||
Arc::new(NoopVirtioInterrupt {}),
|
||||
vec![(0, q, evt)],
|
||||
)
|
||||
rng.activate(virtio_devices::ActivationContext {
|
||||
mem: guest_memory,
|
||||
interrupt_cb: Arc::new(NoopVirtioInterrupt {}),
|
||||
queues: vec![(0, q, evt)],
|
||||
})
|
||||
.ok();
|
||||
|
||||
// Wait for the events to finish and rng device worker thread to return
|
||||
|
||||
@@ -108,11 +108,11 @@ fuzz_target!(|bytes: &[u8]| -> Corpus {
|
||||
.unwrap();
|
||||
|
||||
vsock
|
||||
.activate(
|
||||
guest_memory,
|
||||
Arc::new(NoopVirtioInterrupt {}),
|
||||
vec![(0, q, evt)],
|
||||
)
|
||||
.activate(virtio_devices::ActivationContext {
|
||||
mem: guest_memory,
|
||||
interrupt_cb: Arc::new(NoopVirtioInterrupt {}),
|
||||
queues: vec![(0, q, evt)],
|
||||
})
|
||||
.ok();
|
||||
|
||||
// Wait for the events to finish and vsock device worker thread to return
|
||||
|
||||
@@ -64,11 +64,11 @@ fuzz_target!(|bytes: &[u8]| -> Corpus {
|
||||
queue_evt.write(1).unwrap();
|
||||
|
||||
watchdog
|
||||
.activate(
|
||||
guest_memory,
|
||||
Arc::new(NoopVirtioInterrupt {}),
|
||||
vec![(0, q, evt)],
|
||||
)
|
||||
.activate(virtio_devices::ActivationContext {
|
||||
mem: guest_memory,
|
||||
interrupt_cb: Arc::new(NoopVirtioInterrupt {}),
|
||||
queues: vec![(0, q, evt)],
|
||||
})
|
||||
.ok();
|
||||
|
||||
// Wait for the events to finish and watchdog device worker thread to return
|
||||
|
||||
@@ -590,12 +590,13 @@ impl VirtioDevice for Balloon {
|
||||
}
|
||||
}
|
||||
|
||||
fn activate(
|
||||
&mut self,
|
||||
mem: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||
interrupt_cb: Arc<dyn VirtioInterrupt>,
|
||||
mut queues: Vec<(usize, Queue, EventFd)>,
|
||||
) -> ActivateResult {
|
||||
fn activate(&mut self, context: crate::device::ActivationContext) -> ActivateResult {
|
||||
let crate::device::ActivationContext {
|
||||
mem,
|
||||
interrupt_cb,
|
||||
mut queues,
|
||||
..
|
||||
} = context;
|
||||
self.common.activate(&queues, interrupt_cb.clone())?;
|
||||
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||
|
||||
|
||||
@@ -1008,12 +1008,12 @@ impl VirtioDevice for Block {
|
||||
self.update_writeback();
|
||||
}
|
||||
|
||||
fn activate(
|
||||
&mut self,
|
||||
mem: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||
interrupt_cb: Arc<dyn VirtioInterrupt>,
|
||||
mut queues: Vec<(usize, Queue, EventFd)>,
|
||||
) -> ActivateResult {
|
||||
fn activate(&mut self, context: crate::device::ActivationContext) -> ActivateResult {
|
||||
let crate::device::ActivationContext {
|
||||
mem,
|
||||
interrupt_cb,
|
||||
mut queues,
|
||||
} = context;
|
||||
// See if the guest didn't ack the device being read-only.
|
||||
// If so, warn and pretend it did.
|
||||
let original_acked_features = self.common.acked_features;
|
||||
|
||||
@@ -710,12 +710,13 @@ impl VirtioDevice for Console {
|
||||
self.read_config_from_slice(self.config.lock().unwrap().as_slice(), offset, data);
|
||||
}
|
||||
|
||||
fn activate(
|
||||
&mut self,
|
||||
mem: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||
interrupt_cb: Arc<dyn VirtioInterrupt>,
|
||||
mut queues: Vec<(usize, Queue, EventFd)>,
|
||||
) -> ActivateResult {
|
||||
fn activate(&mut self, context: crate::device::ActivationContext) -> ActivateResult {
|
||||
let crate::device::ActivationContext {
|
||||
mem,
|
||||
interrupt_cb,
|
||||
mut queues,
|
||||
..
|
||||
} = context;
|
||||
self.common.activate(&queues, interrupt_cb.clone())?;
|
||||
self.resizer
|
||||
.acked_features
|
||||
|
||||
@@ -53,6 +53,12 @@ pub struct VirtioSharedMemoryList {
|
||||
pub region_list: Vec<VirtioSharedMemory>,
|
||||
}
|
||||
|
||||
pub struct ActivationContext {
|
||||
pub mem: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||
pub interrupt_cb: Arc<dyn VirtioInterrupt>,
|
||||
pub queues: Vec<(usize, Queue, EventFd)>,
|
||||
}
|
||||
|
||||
/// Trait for virtio devices to be driven by a virtio transport.
|
||||
///
|
||||
/// The lifecycle of a virtio device is to be moved to a virtio transport, which will then query the
|
||||
@@ -94,12 +100,7 @@ pub trait VirtioDevice: Send {
|
||||
}
|
||||
|
||||
/// Activates this device for real usage.
|
||||
fn activate(
|
||||
&mut self,
|
||||
mem: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||
interrupt_evt: Arc<dyn VirtioInterrupt>,
|
||||
queues: Vec<(usize, Queue, EventFd)>,
|
||||
) -> ActivateResult;
|
||||
fn activate(&mut self, context: ActivationContext) -> ActivateResult;
|
||||
|
||||
/// Optionally deactivates this device and returns ownership of the guest memory map, interrupt
|
||||
/// event, and queue events.
|
||||
|
||||
@@ -1075,12 +1075,13 @@ impl VirtioDevice for Iommu {
|
||||
self.update_bypass();
|
||||
}
|
||||
|
||||
fn activate(
|
||||
&mut self,
|
||||
mem: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||
interrupt_cb: Arc<dyn VirtioInterrupt>,
|
||||
mut queues: Vec<(usize, Queue, EventFd)>,
|
||||
) -> ActivateResult {
|
||||
fn activate(&mut self, context: crate::device::ActivationContext) -> ActivateResult {
|
||||
let crate::device::ActivationContext {
|
||||
mem,
|
||||
interrupt_cb,
|
||||
mut queues,
|
||||
..
|
||||
} = context;
|
||||
self.common.activate(&queues, interrupt_cb.clone())?;
|
||||
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||
|
||||
|
||||
@@ -42,8 +42,8 @@ pub use self::balloon::Balloon;
|
||||
pub use self::block::{Block, BlockState};
|
||||
pub use self::console::{Console, ConsoleResizer, Endpoint};
|
||||
pub use self::device::{
|
||||
DmaRemapping, VirtioCommon, VirtioDevice, VirtioInterrupt, VirtioInterruptType,
|
||||
VirtioSharedMemoryList,
|
||||
ActivationContext, DmaRemapping, VirtioCommon, VirtioDevice, VirtioInterrupt,
|
||||
VirtioInterruptType, VirtioSharedMemoryList,
|
||||
};
|
||||
pub use self::epoll_helper::{
|
||||
EPOLL_HELPER_EVENT_LAST, EpollHelper, EpollHelperError, EpollHelperHandler,
|
||||
|
||||
@@ -950,12 +950,13 @@ impl VirtioDevice for Mem {
|
||||
self.read_config_from_slice(self.config.lock().unwrap().as_slice(), offset, data);
|
||||
}
|
||||
|
||||
fn activate(
|
||||
&mut self,
|
||||
mem: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||
interrupt_cb: Arc<dyn VirtioInterrupt>,
|
||||
mut queues: Vec<(usize, Queue, EventFd)>,
|
||||
) -> ActivateResult {
|
||||
fn activate(&mut self, context: crate::device::ActivationContext) -> ActivateResult {
|
||||
let crate::device::ActivationContext {
|
||||
mem,
|
||||
interrupt_cb,
|
||||
mut queues,
|
||||
..
|
||||
} = context;
|
||||
self.common.activate(&queues, interrupt_cb.clone())?;
|
||||
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||
|
||||
|
||||
@@ -693,12 +693,12 @@ impl VirtioDevice for Net {
|
||||
self.read_config_from_slice(self.config.as_slice(), offset, data);
|
||||
}
|
||||
|
||||
fn activate(
|
||||
&mut self,
|
||||
mem: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||
interrupt_cb: Arc<dyn VirtioInterrupt>,
|
||||
mut queues: Vec<(usize, Queue, EventFd)>,
|
||||
) -> ActivateResult {
|
||||
fn activate(&mut self, context: crate::device::ActivationContext) -> ActivateResult {
|
||||
let crate::device::ActivationContext {
|
||||
mem,
|
||||
interrupt_cb,
|
||||
mut queues,
|
||||
} = context;
|
||||
self.common.activate(&queues, interrupt_cb.clone())?;
|
||||
|
||||
let num_queues = queues.len();
|
||||
|
||||
@@ -377,12 +377,13 @@ impl VirtioDevice for Pmem {
|
||||
self.read_config_from_slice(self.config.as_slice(), offset, data);
|
||||
}
|
||||
|
||||
fn activate(
|
||||
&mut self,
|
||||
mem: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||
interrupt_cb: Arc<dyn VirtioInterrupt>,
|
||||
mut queues: Vec<(usize, Queue, EventFd)>,
|
||||
) -> ActivateResult {
|
||||
fn activate(&mut self, context: crate::device::ActivationContext) -> ActivateResult {
|
||||
let crate::device::ActivationContext {
|
||||
mem,
|
||||
interrupt_cb,
|
||||
mut queues,
|
||||
..
|
||||
} = context;
|
||||
self.common.activate(&queues, interrupt_cb.clone())?;
|
||||
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||
if let Some(disk) = self.disk.as_ref() {
|
||||
|
||||
@@ -244,12 +244,13 @@ impl VirtioDevice for Rng {
|
||||
self.common.ack_features(value);
|
||||
}
|
||||
|
||||
fn activate(
|
||||
&mut self,
|
||||
mem: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||
interrupt_cb: Arc<dyn VirtioInterrupt>,
|
||||
mut queues: Vec<(usize, Queue, EventFd)>,
|
||||
) -> ActivateResult {
|
||||
fn activate(&mut self, context: crate::device::ActivationContext) -> ActivateResult {
|
||||
let crate::device::ActivationContext {
|
||||
mem,
|
||||
interrupt_cb,
|
||||
mut queues,
|
||||
..
|
||||
} = context;
|
||||
self.common.activate(&queues, interrupt_cb.clone())?;
|
||||
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||
|
||||
|
||||
@@ -404,11 +404,8 @@ impl Snapshottable for VirtioPciCommonConfig {
|
||||
|
||||
#[cfg(test)]
|
||||
mod unit_tests {
|
||||
use vm_memory::GuestMemoryAtomic;
|
||||
use vmm_sys_util::eventfd::EventFd;
|
||||
|
||||
use super::*;
|
||||
use crate::{ActivateResult, GuestMemoryMmap, VirtioInterrupt};
|
||||
use crate::{ActivateResult, ActivationContext};
|
||||
|
||||
struct DummyDevice(u32);
|
||||
const QUEUE_SIZE: u16 = 256;
|
||||
@@ -421,12 +418,7 @@ mod unit_tests {
|
||||
fn queue_max_sizes(&self) -> &[u16] {
|
||||
QUEUE_SIZES
|
||||
}
|
||||
fn activate(
|
||||
&mut self,
|
||||
_mem: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||
_interrupt_evt: Arc<dyn VirtioInterrupt>,
|
||||
_queues: Vec<(usize, Queue, EventFd)>,
|
||||
) -> ActivateResult {
|
||||
fn activate(&mut self, _context: ActivationContext) -> ActivateResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -309,12 +309,13 @@ pub struct VirtioPciDeviceActivator {
|
||||
}
|
||||
|
||||
impl VirtioPciDeviceActivator {
|
||||
pub fn activate(&mut self) -> ActivateResult {
|
||||
self.device.lock().unwrap().activate(
|
||||
self.memory.take().unwrap(),
|
||||
self.interrupt.take().unwrap(),
|
||||
self.queues.take().unwrap(),
|
||||
)?;
|
||||
pub fn activate(mut self) -> ActivateResult {
|
||||
let mut locked_device = self.device.lock().unwrap();
|
||||
locked_device.activate(crate::device::ActivationContext {
|
||||
mem: self.memory.take().unwrap(),
|
||||
interrupt_cb: self.interrupt.take().unwrap(),
|
||||
queues: self.queues.take().unwrap(),
|
||||
})?;
|
||||
self.device_activated.store(true, Ordering::SeqCst);
|
||||
|
||||
if let Some(barrier) = self.barrier.take() {
|
||||
|
||||
@@ -428,12 +428,13 @@ impl VirtioDevice for Vdpa {
|
||||
}
|
||||
}
|
||||
|
||||
fn activate(
|
||||
&mut self,
|
||||
mem: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||
virtio_interrupt: Arc<dyn VirtioInterrupt>,
|
||||
queues: Vec<(usize, Queue, EventFd)>,
|
||||
) -> ActivateResult {
|
||||
fn activate(&mut self, context: crate::device::ActivationContext) -> ActivateResult {
|
||||
let crate::device::ActivationContext {
|
||||
mem,
|
||||
interrupt_cb: virtio_interrupt,
|
||||
queues,
|
||||
..
|
||||
} = context;
|
||||
self.activate_vdpa(&mem.memory(), virtio_interrupt.as_ref(), &queues)
|
||||
.map_err(ActivateError::ActivateVdpa)?;
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ use virtio_bindings::virtio_blk::{
|
||||
VIRTIO_BLK_F_GEOMETRY, VIRTIO_BLK_F_MQ, VIRTIO_BLK_F_RO, VIRTIO_BLK_F_SEG_MAX,
|
||||
VIRTIO_BLK_F_SIZE_MAX, VIRTIO_BLK_F_TOPOLOGY, VIRTIO_BLK_F_WRITE_ZEROES,
|
||||
};
|
||||
use virtio_queue::Queue;
|
||||
use vm_memory::{ByteValued, GuestMemoryAtomic};
|
||||
use vm_migration::protocol::MemoryRangeTable;
|
||||
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
|
||||
@@ -279,12 +278,13 @@ impl VirtioDevice for Blk {
|
||||
}
|
||||
}
|
||||
|
||||
fn activate(
|
||||
&mut self,
|
||||
mem: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||
interrupt_cb: Arc<dyn VirtioInterrupt>,
|
||||
queues: Vec<(usize, Queue, EventFd)>,
|
||||
) -> ActivateResult {
|
||||
fn activate(&mut self, context: crate::device::ActivationContext) -> ActivateResult {
|
||||
let crate::device::ActivationContext {
|
||||
mem,
|
||||
interrupt_cb,
|
||||
queues,
|
||||
..
|
||||
} = context;
|
||||
self.common.activate(&queues, interrupt_cb.clone())?;
|
||||
self.guest_memory = Some(mem.clone());
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ use serde::{Deserialize, Serialize};
|
||||
use serde_with::{Bytes, serde_as};
|
||||
use vhost::vhost_user::message::{VhostUserProtocolFeatures, VhostUserVirtioFeatures};
|
||||
use vhost::vhost_user::{FrontendReqHandler, VhostUserFrontend, VhostUserFrontendReqHandler};
|
||||
use virtio_queue::Queue;
|
||||
use vm_device::UserspaceMapping;
|
||||
use vm_memory::{ByteValued, GuestMemoryAtomic};
|
||||
use vm_migration::protocol::MemoryRangeTable;
|
||||
@@ -261,12 +260,13 @@ impl VirtioDevice for Fs {
|
||||
self.read_config_from_slice(self.config.as_slice(), offset, data);
|
||||
}
|
||||
|
||||
fn activate(
|
||||
&mut self,
|
||||
mem: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||
interrupt_cb: Arc<dyn VirtioInterrupt>,
|
||||
queues: Vec<(usize, Queue, EventFd)>,
|
||||
) -> ActivateResult {
|
||||
fn activate(&mut self, context: crate::device::ActivationContext) -> ActivateResult {
|
||||
let crate::device::ActivationContext {
|
||||
mem,
|
||||
interrupt_cb,
|
||||
queues,
|
||||
..
|
||||
} = context;
|
||||
self.common.activate(&queues, interrupt_cb.clone())?;
|
||||
self.guest_memory = Some(mem.clone());
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ use vhost::vhost_user::message::{
|
||||
VhostUserConfigFlags, VhostUserProtocolFeatures, VhostUserVirtioFeatures,
|
||||
};
|
||||
use vhost::vhost_user::{FrontendReqHandler, VhostUserFrontend, VhostUserFrontendReqHandler};
|
||||
use virtio_queue::Queue;
|
||||
use vm_device::UserspaceMapping;
|
||||
use vm_memory::GuestMemoryAtomic;
|
||||
use vm_migration::protocol::MemoryRangeTable;
|
||||
@@ -277,12 +276,13 @@ impl VirtioDevice for GenericVhostUser {
|
||||
}
|
||||
}
|
||||
|
||||
fn activate(
|
||||
&mut self,
|
||||
mem: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||
interrupt_cb: Arc<dyn VirtioInterrupt>,
|
||||
queues: Vec<(usize, Queue, EventFd)>,
|
||||
) -> ActivateResult {
|
||||
fn activate(&mut self, context: crate::device::ActivationContext) -> ActivateResult {
|
||||
let crate::device::ActivationContext {
|
||||
mem,
|
||||
interrupt_cb,
|
||||
queues,
|
||||
..
|
||||
} = context;
|
||||
self.common.activate(&queues, interrupt_cb.clone())?;
|
||||
self.guest_memory = Some(mem.clone());
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ use virtio_bindings::virtio_net::{
|
||||
VIRTIO_NET_F_MAC, VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_MTU,
|
||||
};
|
||||
use virtio_bindings::virtio_ring::VIRTIO_RING_F_EVENT_IDX;
|
||||
use virtio_queue::{Queue, QueueT};
|
||||
use virtio_queue::QueueT;
|
||||
use vm_memory::{ByteValued, GuestMemoryAtomic};
|
||||
use vm_migration::protocol::MemoryRangeTable;
|
||||
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
|
||||
@@ -288,12 +288,13 @@ impl VirtioDevice for Net {
|
||||
self.read_config_from_slice(self.config.as_slice(), offset, data);
|
||||
}
|
||||
|
||||
fn activate(
|
||||
&mut self,
|
||||
mem: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||
interrupt_cb: Arc<dyn VirtioInterrupt>,
|
||||
mut queues: Vec<(usize, Queue, EventFd)>,
|
||||
) -> ActivateResult {
|
||||
fn activate(&mut self, context: crate::device::ActivationContext) -> ActivateResult {
|
||||
let crate::device::ActivationContext {
|
||||
mem,
|
||||
interrupt_cb,
|
||||
mut queues,
|
||||
..
|
||||
} = context;
|
||||
self.common.activate(&queues, interrupt_cb.clone())?;
|
||||
self.guest_memory = Some(mem.clone());
|
||||
|
||||
|
||||
@@ -435,12 +435,13 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn activate(
|
||||
&mut self,
|
||||
mem: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||
interrupt_cb: Arc<dyn VirtioInterrupt>,
|
||||
queues: Vec<(usize, Queue, EventFd)>,
|
||||
) -> ActivateResult {
|
||||
fn activate(&mut self, context: crate::device::ActivationContext) -> ActivateResult {
|
||||
let crate::device::ActivationContext {
|
||||
mem,
|
||||
interrupt_cb,
|
||||
queues,
|
||||
..
|
||||
} = context;
|
||||
self.common.activate(&queues, interrupt_cb.clone())?;
|
||||
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||
|
||||
@@ -593,9 +594,11 @@ mod unit_tests {
|
||||
let memory = GuestMemoryAtomic::new(ctx.mem.clone());
|
||||
|
||||
// Test a bad activation.
|
||||
let bad_activate =
|
||||
ctx.device
|
||||
.activate(memory.clone(), Arc::new(NoopVirtioInterrupt {}), Vec::new());
|
||||
let bad_activate = ctx.device.activate(crate::device::ActivationContext {
|
||||
mem: memory.clone(),
|
||||
interrupt_cb: Arc::new(NoopVirtioInterrupt {}),
|
||||
queues: Vec::new(),
|
||||
});
|
||||
match bad_activate {
|
||||
Err(ActivateError::BadActivate) => (),
|
||||
other => panic!("{other:?}"),
|
||||
@@ -603,10 +606,10 @@ mod unit_tests {
|
||||
|
||||
// Test a correct activation.
|
||||
ctx.device
|
||||
.activate(
|
||||
memory,
|
||||
Arc::new(NoopVirtioInterrupt {}),
|
||||
vec![
|
||||
.activate(crate::device::ActivationContext {
|
||||
mem: memory,
|
||||
interrupt_cb: Arc::new(NoopVirtioInterrupt {}),
|
||||
queues: vec![
|
||||
(
|
||||
0,
|
||||
Queue::new(256).unwrap(),
|
||||
@@ -623,7 +626,7 @@ mod unit_tests {
|
||||
EventFd::new(EFD_NONBLOCK).unwrap(),
|
||||
),
|
||||
],
|
||||
)
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
|
||||
@@ -326,12 +326,13 @@ impl VirtioDevice for Watchdog {
|
||||
self.common.ack_features(value);
|
||||
}
|
||||
|
||||
fn activate(
|
||||
&mut self,
|
||||
mem: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||
interrupt_cb: Arc<dyn VirtioInterrupt>,
|
||||
mut queues: Vec<(usize, Queue, EventFd)>,
|
||||
) -> ActivateResult {
|
||||
fn activate(&mut self, context: crate::device::ActivationContext) -> ActivateResult {
|
||||
let crate::device::ActivationContext {
|
||||
mem,
|
||||
interrupt_cb,
|
||||
mut queues,
|
||||
..
|
||||
} = context;
|
||||
self.common.activate(&queues, interrupt_cb.clone())?;
|
||||
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||
|
||||
|
||||
@@ -4543,7 +4543,7 @@ impl DeviceManager {
|
||||
}
|
||||
|
||||
pub fn activate_virtio_devices(&self) -> DeviceManagerResult<()> {
|
||||
for mut activator in self.pending_activations.lock().unwrap().drain(..) {
|
||||
for activator in self.pending_activations.lock().unwrap().drain(..) {
|
||||
activator
|
||||
.activate()
|
||||
.map_err(DeviceManagerError::VirtioActivate)?;
|
||||
|
||||
Reference in New Issue
Block a user