From 65e908a584c0a56e6e9520d3c8ae9cf1fc4cc820 Mon Sep 17 00:00:00 2001 From: Fupan Li Date: Wed, 5 Feb 2025 11:24:10 +0800 Subject: [PATCH] runtime-rs: add the sandbox init for sandbox api For the processing of init sandbox, the init of task api has some more special processing procedures than the init of sandbox api, so these two types of init are separated here. Signed-off-by: Fupan Li --- src/runtime-rs/crates/runtimes/src/manager.rs | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/runtime-rs/crates/runtimes/src/manager.rs b/src/runtime-rs/crates/runtimes/src/manager.rs index a729e0d349..8187798948 100644 --- a/src/runtime-rs/crates/runtimes/src/manager.rs +++ b/src/runtime-rs/crates/runtimes/src/manager.rs @@ -145,11 +145,6 @@ impl RuntimeHandlerManagerInner { spec: Option<&oci::Spec>, options: &Option>, ) -> Result<()> { - // return if runtime instance has init - if self.runtime_instance.is_some() { - return Ok(()); - } - #[cfg(feature = "linux")] LinuxContainer::init().context("init linux container")?; #[cfg(feature = "wasm")] @@ -299,6 +294,7 @@ impl RuntimeHandlerManager { Ok(inner.get_kata_tracer()) } + //init the sandbox for the normal task api #[instrument] async fn task_init_runtime_instance( &self, @@ -306,6 +302,14 @@ impl RuntimeHandlerManager { state: &spec::State, options: &Option>, ) -> Result<()> { + let mut inner: tokio::sync::RwLockWriteGuard<'_, RuntimeHandlerManagerInner> = + self.inner.write().await; + + // return if runtime instance has init + if inner.runtime_instance.is_some() { + return Ok(()); + } + let mut dns: Vec = vec![]; let spec_mounts = spec.mounts().clone().unwrap_or_default(); @@ -345,9 +349,6 @@ impl RuntimeHandlerManager { network_created, }; - let mut inner: tokio::sync::RwLockWriteGuard<'_, RuntimeHandlerManagerInner> = - self.inner.write().await; - let sandbox_config = SandboxConfig { sandbox_id: inner.id.clone(), dns, @@ -361,15 +362,15 @@ impl RuntimeHandlerManager { inner.try_init(sandbox_config, Some(spec), options).await } + //init the sandbox for the sandbox api #[instrument] - async fn init_runtime_instance( - &self, - sandbox_config: SandboxConfig, - spec: Option<&oci::Spec>, - options: &Option>, - ) -> Result<()> { + async fn sandbox_init_runtime_instance(&self, sandbox_config: SandboxConfig) -> Result<()> { let mut inner = self.inner.write().await; - inner.try_init(sandbox_config, spec, options).await + // return if runtime instance has init + if inner.runtime_instance.is_some() { + return Ok(()); + } + inner.try_init(sandbox_config, None, &None).await } #[instrument(parent = &*(ROOTSPAN))]