From 9c5135da7a241f658ca3666fe6e3cc55eebc0666 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Tue, 24 Sep 2019 01:03:05 +0200 Subject: [PATCH] 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 --- vmm/src/lib.rs | 8 +------- vmm/src/vm.rs | 7 +++---- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs index b47f95cd9..58a53b933 100644 --- a/vmm/src/lib.rs +++ b/vmm/src/lib.rs @@ -26,9 +26,6 @@ pub enum Error { /// Cannot start a VM. VmStart(vm::Error), - - /// Cannot load a kernel. - LoadKernel(vm::Error), } pub type Result = result::Result; @@ -39,7 +36,6 @@ impl Display for 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), } } } @@ -60,9 +56,7 @@ pub fn boot_kernel(config: VmConfig) -> Result<()> { let vmm = Vmm::new()?; let mut vm = Vm::new(&vmm.kvm, &config).map_err(Error::VmNew)?; - let entry = vm.load_kernel().map_err(Error::LoadKernel)?; - - if vm.start(entry).map_err(Error::VmStart)? == ExitBehaviour::Shutdown { + if vm.start().map_err(Error::VmStart)? == ExitBehaviour::Shutdown { break; } diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 9e59827e0..ce6c553cc 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -766,7 +766,7 @@ impl<'a> Vm<'a> { }) } - pub fn load_kernel(&mut self) -> Result { + fn load_kernel(&mut self) -> Result { let mut cmdline = self.config.cmdline.args.clone(); for entry in self.devices.cmdline_additions() { 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 { + pub fn start(&mut self) -> Result { + let entry_addr = self.load_kernel()?; let vcpu_count = u8::from(&self.config.cpus); - - // let vcpus: Vec> = Vec::with_capacity(vcpu_count as usize); let vcpu_thread_barrier = Arc::new(Barrier::new((vcpu_count + 1) as usize)); for cpu_id in 0..vcpu_count {