mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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>
63 lines
1.4 KiB
Rust
63 lines
1.4 KiB
Rust
// Copyright © 2019 Intel Corporation
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
#[macro_use]
|
|
extern crate log;
|
|
|
|
use std::fmt::{self, Display};
|
|
use std::result;
|
|
use std::sync::Arc;
|
|
|
|
pub mod config;
|
|
pub mod device_manager;
|
|
pub mod vm;
|
|
|
|
use self::config::VmConfig;
|
|
use self::vm::{ExitBehaviour, Vm};
|
|
|
|
/// Errors associated with VM management
|
|
#[derive(Debug)]
|
|
pub enum Error {
|
|
/// Cannot create a new VM.
|
|
VmNew(vm::Error),
|
|
|
|
/// Cannot start a VM.
|
|
VmStart(vm::Error),
|
|
|
|
/// Cannot stop a VM.
|
|
VmStop(vm::Error),
|
|
}
|
|
pub type Result<T> = result::Result<T, Error>;
|
|
|
|
impl Display for Error {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
use self::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),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn start_vm_loop(config: Arc<VmConfig>) -> Result<()> {
|
|
loop {
|
|
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;
|
|
}
|
|
|
|
Ok(())
|
|
}
|