From ea7abc6c8074c81184cb5b48466ef29102efb40d Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Tue, 24 Sep 2019 16:14:04 +0200 Subject: [PATCH] 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 --- vmm/src/lib.rs | 7 +++++++ vmm/src/vm.rs | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs index 2cdedd199..29b3f3f7a 100644 --- a/vmm/src/lib.rs +++ b/vmm/src/lib.rs @@ -25,6 +25,9 @@ pub enum Error { /// Cannot start a VM. VmStart(vm::Error), + + /// Cannot stop a VM. + VmStop(vm::Error), } pub type Result = result::Result; @@ -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) -> 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; } diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 92dd364b6..f6989be3a 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -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) {