mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-25 01:11:16 +00:00
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 <sebastien.boeuf@intel.com>
This commit is contained in:
parent
a16414dc87
commit
8a165b5314
@ -214,10 +214,10 @@ impl VmState {
|
|||||||
fn valid_transition(self, new_state: VmState) -> Result<()> {
|
fn valid_transition(self, new_state: VmState) -> Result<()> {
|
||||||
match self {
|
match self {
|
||||||
VmState::Created => match new_state {
|
VmState::Created => match new_state {
|
||||||
VmState::Created | VmState::Shutdown | VmState::Paused => {
|
VmState::Created | VmState::Shutdown => {
|
||||||
Err(Error::InvalidStateTransition(self, new_state))
|
Err(Error::InvalidStateTransition(self, new_state))
|
||||||
}
|
}
|
||||||
VmState::Running => Ok(()),
|
VmState::Running | VmState::Paused => Ok(()),
|
||||||
},
|
},
|
||||||
|
|
||||||
VmState::Running => match new_state {
|
VmState::Running => match new_state {
|
||||||
@ -1181,7 +1181,7 @@ impl Snapshottable for Vm {
|
|||||||
let current_state = self
|
let current_state = self
|
||||||
.get_state()
|
.get_state()
|
||||||
.map_err(|e| MigratableError::Restore(anyhow!("Could not get VM state: {:#?}", e)))?;
|
.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| {
|
current_state.valid_transition(new_state).map_err(|e| {
|
||||||
MigratableError::Restore(anyhow!("Could not restore VM state: {:#?}", 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::Created).is_err());
|
||||||
assert!(state.valid_transition(VmState::Running).is_ok());
|
assert!(state.valid_transition(VmState::Running).is_ok());
|
||||||
assert!(state.valid_transition(VmState::Shutdown).is_err());
|
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 => {
|
VmState::Running => {
|
||||||
// Check the transitions from Running
|
// Check the transitions from Running
|
||||||
|
Loading…
Reference in New Issue
Block a user