From fb27de3561bd4afba07c1a1ec6275c4ac0209ca0 Mon Sep 17 00:00:00 2001 From: Fupan Li Date: Sun, 22 Sep 2024 14:34:20 +0800 Subject: [PATCH] runtime-rs: fix the issue of using block_on Since the block_on would block on the current thread which would prevent other async tasks to be run on this worker thread, thus change it to use the async task for this task. Signed-off-by: Fupan Li --- src/runtime-rs/crates/hypervisor/src/ch/inner_hypervisor.rs | 5 ++--- src/runtime-rs/crates/hypervisor/src/ch/mod.rs | 2 +- 2 files changed, 3 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 ac15e81479..255e8dff90 100644 --- a/src/runtime-rs/crates/hypervisor/src/ch/inner_hypervisor.rs +++ b/src/runtime-rs/crates/hypervisor/src/ch/inner_hypervisor.rs @@ -19,7 +19,6 @@ use ch_config::ch_api::{ }; use ch_config::{guest_protection_is_tdx, NamedHypervisorConfig, VmConfig}; use core::future::poll_fn; -use futures::executor::block_on; use futures::future::join_all; use kata_sys_util::protection::{available_guest_protection, GuestProtection}; use kata_types::capabilities::{Capabilities, CapabilityBits}; @@ -640,7 +639,7 @@ impl CloudHypervisorInner { Ok(()) } - pub(crate) fn stop_vm(&mut self) -> Result<()> { + pub(crate) async fn stop_vm(&mut self) -> Result<()> { // 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 @@ -652,7 +651,7 @@ impl CloudHypervisorInner { self.state = VmmState::NotReady; - block_on(self.cloud_hypervisor_shutdown()).map_err(|e| anyhow!(e))?; + self.cloud_hypervisor_shutdown().await?; Ok(()) } diff --git a/src/runtime-rs/crates/hypervisor/src/ch/mod.rs b/src/runtime-rs/crates/hypervisor/src/ch/mod.rs index 7617646ea4..42f8883b60 100644 --- a/src/runtime-rs/crates/hypervisor/src/ch/mod.rs +++ b/src/runtime-rs/crates/hypervisor/src/ch/mod.rs @@ -61,7 +61,7 @@ impl Hypervisor for CloudHypervisor { async fn stop_vm(&self) -> Result<()> { let mut inner = self.inner.write().await; - inner.stop_vm() + inner.stop_vm().await } async fn wait_vm(&self) -> Result {