mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
vmm: Remove the Vmm structure
The Vmm structure is just a placeholder for the KVM instance. We can create it directly from the VM creation routine instead. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
9c5135da7a
commit
bdfd1a3f38
@ -285,7 +285,7 @@ fn main() {
|
||||
vm_config.disks,
|
||||
);
|
||||
|
||||
if let Err(e) = vmm::boot_kernel(vm_config) {
|
||||
if let Err(e) = vmm::start_vm_loop(vm_config) {
|
||||
println!("Guest boot failed: {}", e);
|
||||
process::exit(1);
|
||||
}
|
||||
|
@ -3,11 +3,9 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
extern crate kvm_ioctls;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
use kvm_ioctls::*;
|
||||
use std::fmt::{self, Display};
|
||||
use std::result;
|
||||
|
||||
@ -40,21 +38,9 @@ impl Display for Error {
|
||||
}
|
||||
}
|
||||
|
||||
struct Vmm {
|
||||
kvm: Kvm,
|
||||
}
|
||||
|
||||
impl Vmm {
|
||||
fn new() -> Result<Self> {
|
||||
let kvm = Kvm::new().expect("new KVM instance creation failed");
|
||||
Ok(Vmm { kvm })
|
||||
}
|
||||
}
|
||||
|
||||
pub fn boot_kernel(config: VmConfig) -> Result<()> {
|
||||
pub fn start_vm_loop(config: VmConfig) -> Result<()> {
|
||||
loop {
|
||||
let vmm = Vmm::new()?;
|
||||
let mut vm = Vm::new(&vmm.kvm, &config).map_err(Error::VmNew)?;
|
||||
let mut vm = Vm::new(&config).map_err(Error::VmNew)?;
|
||||
|
||||
if vm.start().map_err(Error::VmStart)? == ExitBehaviour::Shutdown {
|
||||
break;
|
||||
|
@ -211,6 +211,9 @@ pub enum Error {
|
||||
|
||||
/// Failed to join on vCPU threads
|
||||
ThreadCleanup,
|
||||
|
||||
/// Failed to create a new KVM instance
|
||||
KvmNew(io::Error),
|
||||
}
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
||||
@ -533,7 +536,8 @@ fn get_host_cpu_phys_bits() -> u8 {
|
||||
}
|
||||
|
||||
impl<'a> Vm<'a> {
|
||||
pub fn new(kvm: &Kvm, config: &'a VmConfig) -> Result<Self> {
|
||||
pub fn new(config: &'a VmConfig) -> Result<Self> {
|
||||
let kvm = Kvm::new().map_err(Error::KvmNew)?;
|
||||
let kernel = File::open(&config.kernel.path).map_err(Error::KernelFile)?;
|
||||
let fd = kvm.create_vm().map_err(Error::VmCreate)?;
|
||||
let fd = Arc::new(fd);
|
||||
|
Loading…
Reference in New Issue
Block a user