mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-22 04:25: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.
|
/// Cannot start a VM.
|
||||||
VmStart(vm::Error),
|
VmStart(vm::Error),
|
||||||
|
|
||||||
|
/// Cannot stop a VM.
|
||||||
|
VmStop(vm::Error),
|
||||||
}
|
}
|
||||||
pub type Result<T> = result::Result<T, Error>;
|
pub type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
@ -35,6 +38,7 @@ impl Display for Error {
|
|||||||
match self {
|
match self {
|
||||||
VmNew(e) => write!(f, "Can not create a new virtual machine: {:?}", 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),
|
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)?;
|
let mut vm = Vm::new(config.clone()).map_err(Error::VmNew)?;
|
||||||
|
|
||||||
if vm.start().map_err(Error::VmStart)? == ExitBehaviour::Shutdown {
|
if vm.start().map_err(Error::VmStart)? == ExitBehaviour::Shutdown {
|
||||||
|
vm.stop().map_err(Error::VmStop)?;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vm.stop().map_err(Error::VmStop)?;
|
||||||
|
|
||||||
#[cfg(not(feature = "acpi"))]
|
#[cfg(not(feature = "acpi"))]
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -909,6 +909,10 @@ impl Vm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(exit_behaviour)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn stop(&mut self) -> Result<()> {
|
||||||
if self.on_tty {
|
if self.on_tty {
|
||||||
// Don't forget to set the terminal in canonical mode
|
// Don't forget to set the terminal in canonical mode
|
||||||
// before to exit.
|
// before to exit.
|
||||||
@ -941,7 +945,7 @@ impl Vm {
|
|||||||
thread.join().map_err(|_| Error::ThreadCleanup)?
|
thread.join().map_err(|_| Error::ThreadCleanup)?
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(exit_behaviour)
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn os_signal_handler(signals: Signals, console_input_clone: Arc<Console>) {
|
fn os_signal_handler(signals: Signals, console_input_clone: Arc<Console>) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user