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:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user