From 1195692d3c1026e523750f910118958284a6f2bd Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Tue, 12 Dec 2023 15:25:27 +0000 Subject: [PATCH 1/2] runtime-rs: ch: Move state handling to top-level APIs Move the state setting to the `Hypervisor` trait calls. This makes the code clearer. Signed-off-by: James O. D. Hunt --- .../crates/hypervisor/src/ch/inner_hypervisor.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/runtime-rs/crates/hypervisor/src/ch/inner_hypervisor.rs b/src/runtime-rs/crates/hypervisor/src/ch/inner_hypervisor.rs index 6aa301495..563a7e323 100644 --- a/src/runtime-rs/crates/hypervisor/src/ch/inner_hypervisor.rs +++ b/src/runtime-rs/crates/hypervisor/src/ch/inner_hypervisor.rs @@ -110,8 +110,6 @@ impl CloudHypervisorInner { } } - self.state = VmmState::VmmServerReady; - Ok(()) } @@ -247,8 +245,6 @@ impl CloudHypervisorInner { debug!(sl!(), "vm start response: {:?}", detail); } - self.state = VmmState::VmRunning; - Ok(()) } @@ -625,8 +621,12 @@ impl CloudHypervisorInner { self.timeout_secs = timeout_secs; self.start_hypervisor(self.timeout_secs).await?; + self.state = VmmState::VmmServerReady; + self.boot_vm().await?; + self.state = VmmState::VmRunning; + Ok(()) } From 2a518f08985035a9e80462fc8cca84a2d6b3c246 Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Tue, 12 Dec 2023 15:26:12 +0000 Subject: [PATCH 2/2] 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 --- .../crates/hypervisor/src/ch/inner_hypervisor.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/runtime-rs/crates/hypervisor/src/ch/inner_hypervisor.rs b/src/runtime-rs/crates/hypervisor/src/ch/inner_hypervisor.rs index 563a7e323..6b8b7a075 100644 --- a/src/runtime-rs/crates/hypervisor/src/ch/inner_hypervisor.rs +++ b/src/runtime-rs/crates/hypervisor/src/ch/inner_hypervisor.rs @@ -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(()) }