vmm: Create restored Vm as paused

Thanks to the new way of restoring Vm, we can now create the Vm object
directly with the appropriate VmState rather than having to patch it at
a later time.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2022-12-01 17:05:34 +01:00 committed by Bo Chen
parent 2e01bf7f74
commit d98f2618bd

View File

@ -308,9 +308,6 @@ pub enum Error {
#[cfg(feature = "guest_debug")] #[cfg(feature = "guest_debug")]
#[error("Error coredumping VM: {0:?}")] #[error("Error coredumping VM: {0:?}")]
Coredump(GuestDebuggableError), Coredump(GuestDebuggableError),
#[error("Failed taking the RwLock")]
TryRwLock(#[source] anyhow::Error),
} }
pub type Result<T> = result::Result<T, Error>; pub type Result<T> = result::Result<T, Error>;
@ -614,6 +611,12 @@ impl Vm {
None None
}; };
let vm_state = if snapshot.is_some() {
VmState::Paused
} else {
VmState::Created
};
Ok(Vm { Ok(Vm {
#[cfg(feature = "tdx")] #[cfg(feature = "tdx")]
kernel, kernel,
@ -623,7 +626,7 @@ impl Vm {
on_tty, on_tty,
threads: Vec::with_capacity(1), threads: Vec::with_capacity(1),
signals: None, signals: None,
state: RwLock::new(VmState::Created), state: RwLock::new(vm_state),
cpu_manager, cpu_manager,
memory_manager, memory_manager,
vm, vm,
@ -2124,10 +2127,6 @@ impl Vm {
pub fn restore(&mut self) -> Result<()> { pub fn restore(&mut self) -> Result<()> {
event!("vm", "restoring"); event!("vm", "restoring");
let current_state = self.get_state()?;
let new_state = VmState::Paused;
current_state.valid_transition(new_state)?;
// Now we can start all vCPUs from here. // Now we can start all vCPUs from here.
self.cpu_manager self.cpu_manager
.lock() .lock()
@ -2138,12 +2137,6 @@ impl Vm {
self.setup_signal_handler()?; self.setup_signal_handler()?;
self.setup_tty()?; self.setup_tty()?;
let mut state = self
.state
.try_write()
.map_err(|e| Error::TryRwLock(anyhow!("Failed taking the lock: {}", e)))?;
*state = new_state;
event!("vm", "restored"); event!("vm", "restored");
Ok(()) Ok(())
} }