mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-14 14:14:15 +00:00
runtime-rs: ch: Change state when VM stopped
Make the CH (Cloud Hypervisor) `stop_vm()` method check the VM state before attempting to stop the VM, and update the state once the VM has stopped. This avoids the method failing if called multiple times which will happen if the workload exits before the container manager requests that the container stop. This change ensures the CH driver finishes cleanly. Fixes: #8629. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
parent
1195692d3c
commit
2a518f0898
@ -631,7 +631,18 @@ impl CloudHypervisorInner {
|
||||
}
|
||||
|
||||
pub(crate) fn stop_vm(&mut self) -> Result<()> {
|
||||
block_on(self.cloud_hypervisor_shutdown())?;
|
||||
// If the container workload exits, this method gets called. However,
|
||||
// the container manager always makes a ShutdownContainer request,
|
||||
// which results in this method being called potentially a second
|
||||
// time. Without this check, we'll return an error representing EPIPE
|
||||
// since the CH API socket is at that point invalid.
|
||||
if self.state != VmmState::VmRunning {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
self.state = VmmState::NotReady;
|
||||
|
||||
block_on(self.cloud_hypervisor_shutdown()).map_err(|e| anyhow!(e))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user