mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Activate virtio device from VMM thread
When a device is ready to be activated signal to the VMM thread via an EventFd that there is a device to be activated. When the VMM receives a notification on the EventFd that there is a device to be activated notify the device manager to attempt to activate any devices that have not been activated. As a side effect the VMM thread will create the virtio device threads. Fixes: #1863 Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
@@ -131,6 +131,10 @@ pub enum Error {
|
||||
/// Cannot apply seccomp filter
|
||||
#[error("Error applying seccomp filter: {0}")]
|
||||
ApplySeccompFilter(seccomp::Error),
|
||||
|
||||
/// Error activating virtio devices
|
||||
#[error("Error activating virtio devices: {0:?}")]
|
||||
ActivateVirtioDevices(VmError),
|
||||
}
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
||||
@@ -140,6 +144,7 @@ pub enum EpollDispatch {
|
||||
Reset,
|
||||
Stdin,
|
||||
Api,
|
||||
ActivateVirtioDevices,
|
||||
}
|
||||
|
||||
pub struct EpollContext {
|
||||
@@ -281,6 +286,7 @@ pub struct Vmm {
|
||||
vm_config: Option<Arc<Mutex<VmConfig>>>,
|
||||
seccomp_action: SeccompAction,
|
||||
hypervisor: Arc<dyn hypervisor::Hypervisor>,
|
||||
activate_evt: EventFd,
|
||||
}
|
||||
|
||||
impl Vmm {
|
||||
@@ -293,6 +299,7 @@ impl Vmm {
|
||||
let mut epoll = EpollContext::new().map_err(Error::Epoll)?;
|
||||
let exit_evt = EventFd::new(EFD_NONBLOCK).map_err(Error::EventFdCreate)?;
|
||||
let reset_evt = EventFd::new(EFD_NONBLOCK).map_err(Error::EventFdCreate)?;
|
||||
let activate_evt = EventFd::new(EFD_NONBLOCK).map_err(Error::EventFdCreate)?;
|
||||
|
||||
if unsafe { libc::isatty(libc::STDIN_FILENO as i32) } != 0 {
|
||||
epoll.add_stdin().map_err(Error::Epoll)?;
|
||||
@@ -306,6 +313,10 @@ impl Vmm {
|
||||
.add_event(&reset_evt, EpollDispatch::Reset)
|
||||
.map_err(Error::Epoll)?;
|
||||
|
||||
epoll
|
||||
.add_event(&activate_evt, EpollDispatch::ActivateVirtioDevices)
|
||||
.map_err(Error::Epoll)?;
|
||||
|
||||
epoll
|
||||
.add_event(&api_evt, EpollDispatch::Api)
|
||||
.map_err(Error::Epoll)?;
|
||||
@@ -320,6 +331,7 @@ impl Vmm {
|
||||
vm_config: None,
|
||||
seccomp_action,
|
||||
hypervisor,
|
||||
activate_evt,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -328,6 +340,10 @@ impl Vmm {
|
||||
if self.vm.is_none() {
|
||||
let exit_evt = self.exit_evt.try_clone().map_err(VmError::EventFdClone)?;
|
||||
let reset_evt = self.reset_evt.try_clone().map_err(VmError::EventFdClone)?;
|
||||
let activate_evt = self
|
||||
.activate_evt
|
||||
.try_clone()
|
||||
.map_err(VmError::EventFdClone)?;
|
||||
|
||||
if let Some(ref vm_config) = self.vm_config {
|
||||
let vm = Vm::new(
|
||||
@@ -336,6 +352,7 @@ impl Vmm {
|
||||
reset_evt,
|
||||
&self.seccomp_action,
|
||||
self.hypervisor.clone(),
|
||||
activate_evt,
|
||||
)?;
|
||||
self.vm = Some(vm);
|
||||
}
|
||||
@@ -397,6 +414,10 @@ impl Vmm {
|
||||
|
||||
let exit_evt = self.exit_evt.try_clone().map_err(VmError::EventFdClone)?;
|
||||
let reset_evt = self.reset_evt.try_clone().map_err(VmError::EventFdClone)?;
|
||||
let activate_evt = self
|
||||
.activate_evt
|
||||
.try_clone()
|
||||
.map_err(VmError::EventFdClone)?;
|
||||
|
||||
let vm = Vm::new_from_snapshot(
|
||||
&snapshot,
|
||||
@@ -406,6 +427,7 @@ impl Vmm {
|
||||
restore_cfg.prefault,
|
||||
&self.seccomp_action,
|
||||
self.hypervisor.clone(),
|
||||
activate_evt,
|
||||
)?;
|
||||
self.vm = Some(vm);
|
||||
|
||||
@@ -443,6 +465,10 @@ impl Vmm {
|
||||
|
||||
let exit_evt = self.exit_evt.try_clone().map_err(VmError::EventFdClone)?;
|
||||
let reset_evt = self.reset_evt.try_clone().map_err(VmError::EventFdClone)?;
|
||||
let activate_evt = self
|
||||
.activate_evt
|
||||
.try_clone()
|
||||
.map_err(VmError::EventFdClone)?;
|
||||
|
||||
// The Linux kernel fires off an i8042 reset after doing the ACPI reset so there may be
|
||||
// an event sitting in the shared reset_evt. Without doing this we get very early reboots
|
||||
@@ -456,6 +482,7 @@ impl Vmm {
|
||||
reset_evt,
|
||||
&self.seccomp_action,
|
||||
self.hypervisor.clone(),
|
||||
activate_evt,
|
||||
)?);
|
||||
}
|
||||
|
||||
@@ -676,6 +703,10 @@ impl Vmm {
|
||||
let reset_evt = self.reset_evt.try_clone().map_err(|e| {
|
||||
MigratableError::MigrateReceive(anyhow!("Error cloning reset EventFd: {}", e))
|
||||
})?;
|
||||
let activate_evt = self.activate_evt.try_clone().map_err(|e| {
|
||||
MigratableError::MigrateReceive(anyhow!("Error cloning activate EventFd: {}", e))
|
||||
})?;
|
||||
|
||||
self.vm_config = Some(Arc::new(Mutex::new(config)));
|
||||
let vm = Vm::new_from_migration(
|
||||
self.vm_config.clone().unwrap(),
|
||||
@@ -683,6 +714,7 @@ impl Vmm {
|
||||
reset_evt,
|
||||
&self.seccomp_action,
|
||||
self.hypervisor.clone(),
|
||||
activate_evt,
|
||||
)
|
||||
.map_err(|e| {
|
||||
MigratableError::MigrateReceive(anyhow!("Error creating VM from snapshot: {:?}", e))
|
||||
@@ -1065,6 +1097,13 @@ impl Vmm {
|
||||
vm.handle_stdin().map_err(Error::Stdin)?;
|
||||
}
|
||||
}
|
||||
EpollDispatch::ActivateVirtioDevices => {
|
||||
if let Some(ref vm) = self.vm {
|
||||
vm.activate_virtio_devices()
|
||||
.map_err(Error::ActivateVirtioDevices)?;
|
||||
}
|
||||
self.activate_evt.read().map_err(Error::EventFdRead)?;
|
||||
}
|
||||
EpollDispatch::Api => {
|
||||
// Consume the event.
|
||||
self.api_evt.read().map_err(Error::EventFdRead)?;
|
||||
|
||||
Reference in New Issue
Block a user