mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-05 21:15:45 +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,
|
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);
|
println!("Guest boot failed: {}", e);
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,9 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
extern crate kvm_ioctls;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
|
|
||||||
use kvm_ioctls::*;
|
|
||||||
use std::fmt::{self, Display};
|
use std::fmt::{self, Display};
|
||||||
use std::result;
|
use std::result;
|
||||||
|
|
||||||
@ -40,21 +38,9 @@ impl Display for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Vmm {
|
pub fn start_vm_loop(config: VmConfig) -> Result<()> {
|
||||||
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<()> {
|
|
||||||
loop {
|
loop {
|
||||||
let vmm = Vmm::new()?;
|
let mut vm = Vm::new(&config).map_err(Error::VmNew)?;
|
||||||
let mut vm = Vm::new(&vmm.kvm, &config).map_err(Error::VmNew)?;
|
|
||||||
|
|
||||||
if vm.start().map_err(Error::VmStart)? == ExitBehaviour::Shutdown {
|
if vm.start().map_err(Error::VmStart)? == ExitBehaviour::Shutdown {
|
||||||
break;
|
break;
|
||||||
|
@ -211,6 +211,9 @@ pub enum Error {
|
|||||||
|
|
||||||
/// Failed to join on vCPU threads
|
/// Failed to join on vCPU threads
|
||||||
ThreadCleanup,
|
ThreadCleanup,
|
||||||
|
|
||||||
|
/// Failed to create a new KVM instance
|
||||||
|
KvmNew(io::Error),
|
||||||
}
|
}
|
||||||
pub type Result<T> = result::Result<T, Error>;
|
pub type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
@ -533,7 +536,8 @@ fn get_host_cpu_phys_bits() -> u8 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Vm<'a> {
|
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 kernel = File::open(&config.kernel.path).map_err(Error::KernelFile)?;
|
||||||
let fd = kvm.create_vm().map_err(Error::VmCreate)?;
|
let fd = kvm.create_vm().map_err(Error::VmCreate)?;
|
||||||
let fd = Arc::new(fd);
|
let fd = Arc::new(fd);
|
||||||
|
Loading…
Reference in New Issue
Block a user