mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-01 11:05:46 +00:00
vmm: Simplify the VM start flow
We can integrate the kernel loading into the VM start method. The VM start flow is then: Vm::new() -> vm.start(), which feels more natural. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
b79c1f7722
commit
9c5135da7a
@ -26,9 +26,6 @@ pub enum Error {
|
|||||||
|
|
||||||
/// Cannot start a VM.
|
/// Cannot start a VM.
|
||||||
VmStart(vm::Error),
|
VmStart(vm::Error),
|
||||||
|
|
||||||
/// Cannot load a kernel.
|
|
||||||
LoadKernel(vm::Error),
|
|
||||||
}
|
}
|
||||||
pub type Result<T> = result::Result<T, Error>;
|
pub type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
@ -39,7 +36,6 @@ 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),
|
||||||
LoadKernel(e) => write!(f, "Can not load a guest kernel: {:?}", e),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,9 +56,7 @@ pub fn boot_kernel(config: VmConfig) -> Result<()> {
|
|||||||
let vmm = Vmm::new()?;
|
let vmm = Vmm::new()?;
|
||||||
let mut vm = Vm::new(&vmm.kvm, &config).map_err(Error::VmNew)?;
|
let mut vm = Vm::new(&vmm.kvm, &config).map_err(Error::VmNew)?;
|
||||||
|
|
||||||
let entry = vm.load_kernel().map_err(Error::LoadKernel)?;
|
if vm.start().map_err(Error::VmStart)? == ExitBehaviour::Shutdown {
|
||||||
|
|
||||||
if vm.start(entry).map_err(Error::VmStart)? == ExitBehaviour::Shutdown {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -766,7 +766,7 @@ impl<'a> Vm<'a> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_kernel(&mut self) -> Result<GuestAddress> {
|
fn load_kernel(&mut self) -> Result<GuestAddress> {
|
||||||
let mut cmdline = self.config.cmdline.args.clone();
|
let mut cmdline = self.config.cmdline.args.clone();
|
||||||
for entry in self.devices.cmdline_additions() {
|
for entry in self.devices.cmdline_additions() {
|
||||||
cmdline.insert_str(entry).map_err(|_| Error::CmdLine)?;
|
cmdline.insert_str(entry).map_err(|_| Error::CmdLine)?;
|
||||||
@ -956,10 +956,9 @@ impl<'a> Vm<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(&mut self, entry_addr: GuestAddress) -> Result<ExitBehaviour> {
|
pub fn start(&mut self) -> Result<ExitBehaviour> {
|
||||||
|
let entry_addr = self.load_kernel()?;
|
||||||
let vcpu_count = u8::from(&self.config.cpus);
|
let vcpu_count = u8::from(&self.config.cpus);
|
||||||
|
|
||||||
// let vcpus: Vec<thread::JoinHandle<()>> = Vec::with_capacity(vcpu_count as usize);
|
|
||||||
let vcpu_thread_barrier = Arc::new(Barrier::new((vcpu_count + 1) as usize));
|
let vcpu_thread_barrier = Arc::new(Barrier::new((vcpu_count + 1) as usize));
|
||||||
|
|
||||||
for cpu_id in 0..vcpu_count {
|
for cpu_id in 0..vcpu_count {
|
||||||
|
Loading…
Reference in New Issue
Block a user