mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
vmm: Propagate boot_kernel errors properly
So that our error traces are more meaningful. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
43965eda6f
commit
2c94529660
@ -120,5 +120,7 @@ fn main() {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
vmm::boot_kernel(vm_config).unwrap();
|
||||
if let Err(e) = vmm::boot_kernel(vm_config) {
|
||||
println!("Guest boot failed: {}", e);
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,38 @@
|
||||
extern crate kvm_ioctls;
|
||||
|
||||
use kvm_ioctls::*;
|
||||
use std::fmt::{self, Display};
|
||||
use std::result;
|
||||
|
||||
pub mod vm;
|
||||
|
||||
use self::vm::{Result, Vm, VmConfig};
|
||||
use self::vm::{Vm, VmConfig};
|
||||
|
||||
/// 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 load a kernel.
|
||||
LoadKernel(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),
|
||||
LoadKernel(e) => write!(f, "Can not load a guest kernel: {:?}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Vmm {
|
||||
kvm: Kvm,
|
||||
@ -24,10 +52,10 @@ impl Vmm {
|
||||
|
||||
pub fn boot_kernel(config: VmConfig) -> Result<()> {
|
||||
let vmm = Vmm::new()?;
|
||||
let mut vm = Vm::new(&vmm.kvm, config)?;
|
||||
let mut vm = Vm::new(&vmm.kvm, config).map_err(Error::VmNew)?;
|
||||
|
||||
let entry = vm.load_kernel()?;
|
||||
vm.start(entry)?;
|
||||
let entry = vm.load_kernel().map_err(Error::LoadKernel)?;
|
||||
vm.start(entry).map_err(Error::VmStart)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user