From 8a165b5314d445592831a54f949b86b66c79a306 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 22 Jun 2020 15:35:27 +0200 Subject: [PATCH] vmm: Restore the VM in "paused" state Because we need to pause the VM before it is snapshot, it should be restored in a paused state to keep the sequence symmetrical. That's the reason why the state machine regarding the valid VM's state transition needed to be updated accordingly. Signed-off-by: Sebastien Boeuf --- vmm/src/vm.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 5875ffa88..f20fe7901 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -214,10 +214,10 @@ impl VmState { fn valid_transition(self, new_state: VmState) -> Result<()> { match self { VmState::Created => match new_state { - VmState::Created | VmState::Shutdown | VmState::Paused => { + VmState::Created | VmState::Shutdown => { Err(Error::InvalidStateTransition(self, new_state)) } - VmState::Running => Ok(()), + VmState::Running | VmState::Paused => Ok(()), }, VmState::Running => match new_state { @@ -1181,7 +1181,7 @@ impl Snapshottable for Vm { let current_state = self .get_state() .map_err(|e| MigratableError::Restore(anyhow!("Could not get VM state: {:#?}", e)))?; - let new_state = VmState::Running; + let new_state = VmState::Paused; current_state.valid_transition(new_state).map_err(|e| { MigratableError::Restore(anyhow!("Could not restore VM state: {:#?}", e)) })?; @@ -1336,7 +1336,7 @@ mod tests { assert!(state.valid_transition(VmState::Created).is_err()); assert!(state.valid_transition(VmState::Running).is_ok()); assert!(state.valid_transition(VmState::Shutdown).is_err()); - assert!(state.valid_transition(VmState::Paused).is_err()); + assert!(state.valid_transition(VmState::Paused).is_ok()); } VmState::Running => { // Check the transitions from Running