From 228adebc328ee4c06aebf5e50af46d3f46aa4062 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Tue, 8 Oct 2019 11:20:09 +0200 Subject: [PATCH] vmm: Unreference the VM when shutting down This way, we are forced to re-create the VM object when moving from shutdown to boot. Fixes: #321 Signed-off-by: Samuel Ortiz --- vmm/src/lib.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs index f1f94a156..8cf7b136c 100644 --- a/vmm/src/lib.rs +++ b/vmm/src/lib.rs @@ -252,7 +252,7 @@ impl Vmm { } fn vm_shutdown(&mut self) -> result::Result<(), VmError> { - if let Some(ref mut vm) = self.vm { + if let Some(ref mut vm) = self.vm.take() { vm.shutdown() } else { Err(VmError::VmNotBooted) @@ -312,13 +312,10 @@ impl Vmm { return Ok(()); } - self.vm_config = None; + // First we try to shut the current VM down. + self.vm_shutdown()?; - // First we shut the current VM down if necessary. - if let Some(ref mut vm) = self.vm { - vm.shutdown()?; - self.vm = None; - } + self.vm_config = None; Ok(()) }