vmm: Add a VM stop method

In order to transfer the control loop to a separate VMM thread, we want
to shrink the VM control loop to a bare minimum.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz 2019-09-24 16:14:04 +02:00
parent e6ef9ece2c
commit ea7abc6c80
2 changed files with 12 additions and 1 deletions

View File

@ -25,6 +25,9 @@ pub enum Error {
/// Cannot start a VM.
VmStart(vm::Error),
/// Cannot stop a VM.
VmStop(vm::Error),
}
pub type Result<T> = result::Result<T, Error>;
@ -35,6 +38,7 @@ impl Display for Error {
match self {
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,9 +48,12 @@ pub fn start_vm_loop(config: Arc<VmConfig>) -> Result<()> {
let mut vm = Vm::new(config.clone()).map_err(Error::VmNew)?;
if vm.start().map_err(Error::VmStart)? == ExitBehaviour::Shutdown {
vm.stop().map_err(Error::VmStop)?;
break;
}
vm.stop().map_err(Error::VmStop)?;
#[cfg(not(feature = "acpi"))]
break;
}

View File

@ -909,6 +909,10 @@ impl Vm {
}
}
Ok(exit_behaviour)
}
pub fn stop(&mut self) -> Result<()> {
if self.on_tty {
// Don't forget to set the terminal in canonical mode
// before to exit.
@ -941,7 +945,7 @@ impl Vm {
thread.join().map_err(|_| Error::ThreadCleanup)?
}
Ok(exit_behaviour)
Ok(())
}
fn os_signal_handler(signals: Signals, console_input_clone: Arc<Console>) {