vmm: Pass the exit and reset fds to the vm creation method

As we're going to move the control loop to the VMM thread, the exit and
reset EventFds are no longer going to be owned by the VM.
We pass a copy of them when creating the Vm instead.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz 2019-09-25 14:09:33 +02:00
parent feb1c33084
commit 6710a39b5a
2 changed files with 18 additions and 7 deletions

View File

@ -5,10 +5,14 @@
#[macro_use]
extern crate log;
extern crate vmm_sys_util;
use libc::EFD_NONBLOCK;
use std::fmt::{self, Display};
use std::io;
use std::result;
use std::sync::Arc;
use vmm_sys_util::eventfd::EventFd;
pub mod config;
pub mod device_manager;
@ -20,6 +24,9 @@ use self::vm::{ExitBehaviour, Vm};
/// Errors associated with VM management
#[derive(Debug)]
pub enum Error {
/// Cannot create EventFd.
EventFd(io::Error),
/// Cannot create a new VM.
VmNew(vm::Error),
@ -36,6 +43,7 @@ impl Display for Error {
use self::Error::*;
match self {
EventFd(e) => write!(f, "Can not create EventFd: {:?}", e),
VmNew(e) => write!(f, "Can not create a new virtual machine: {:?}", e),
VmStart(e) => write!(f, "Can not start a new virtual machine: {:?}", e),
VmStop(e) => write!(f, "Can not stop a virtual machine: {:?}", e),
@ -44,8 +52,16 @@ impl Display for Error {
}
pub fn start_vm_loop(config: Arc<VmConfig>) -> Result<()> {
let exit_evt = EventFd::new(EFD_NONBLOCK).map_err(Error::EventFd)?;
let reset_evt = EventFd::new(EFD_NONBLOCK).map_err(Error::EventFd)?;
loop {
let mut vm = Vm::new(config.clone()).map_err(Error::VmNew)?;
let mut vm = Vm::new(
config.clone(),
exit_evt.try_clone().unwrap(),
reset_evt.try_clone().unwrap(),
)
.map_err(Error::VmNew)?;
if vm.start().map_err(Error::VmStart)? == ExitBehaviour::Shutdown {
vm.stop().map_err(Error::VmStop)?;

View File

@ -22,7 +22,6 @@ extern crate vfio;
extern crate vm_allocator;
extern crate vm_memory;
extern crate vm_virtio;
extern crate vmm_sys_util;
use crate::config::{ConsoleOutputMode, VmConfig};
use crate::device_manager::{get_win_size, Console, DeviceManager, DeviceManagerError};
@ -33,7 +32,6 @@ use kvm_bindings::{
KVM_PIT_SPEAKER_DUMMY,
};
use kvm_ioctls::*;
use libc::EFD_NONBLOCK;
use libc::{c_void, siginfo_t};
use linux_loader::loader::KernelLoader;
use signal_hook::{iterator::Signals, SIGWINCH};
@ -536,7 +534,7 @@ fn get_host_cpu_phys_bits() -> u8 {
}
impl Vm {
pub fn new(config: Arc<VmConfig>) -> Result<Self> {
pub fn new(config: Arc<VmConfig>, exit_evt: EventFd, reset_evt: EventFd) -> Result<Self> {
let kvm = Kvm::new().map_err(Error::KvmNew)?;
let kernel = File::open(&config.kernel.path).map_err(Error::KernelFile)?;
let fd = kvm.create_vm().map_err(Error::VmCreate)?;
@ -720,9 +718,6 @@ impl Vm {
vm_cfg: &config,
};
let exit_evt = EventFd::new(EFD_NONBLOCK).map_err(Error::EventFd)?;
let reset_evt = EventFd::new(EFD_NONBLOCK).map_err(Error::EventFd)?;
let device_manager = DeviceManager::new(
&vm_info,
&mut allocator,