mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-21 20:15:21 +00:00
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:
parent
e6ef9ece2c
commit
ea7abc6c80
@ -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;
|
||||
}
|
||||
|
@ -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>) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user