From 67e3bc754dbec6b20c8a58046d5963b64a50f4ee Mon Sep 17 00:00:00 2001 From: Alex Lyn Date: Mon, 18 May 2026 14:37:50 +0800 Subject: [PATCH] runtime-rs: Move KATA_PATH creation from sb_storage_path() to MgmtServer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sb_storage_path() is a path accessor shared by both server (shim) and client (kata-ctl). Having it call create_dir_all(KATA_PATH) on every invocation is incorrect: the client side should never create directories — if /run/kata/ does not exist, no shim is running. Move the directory creation to MgmtServer::new(), which is the server- side component that manages the shim management socket under KATA_PATH. Make sb_storage_path() a pure accessor returning &'static str directly. Signed-off-by: Alex Lyn --- src/libs/shim-interface/src/lib.rs | 9 +++------ .../crates/runtimes/src/shim_mgmt/server.rs | 14 +++++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/libs/shim-interface/src/lib.rs b/src/libs/shim-interface/src/lib.rs index dec5d1dcda..69d3059e74 100644 --- a/src/libs/shim-interface/src/lib.rs +++ b/src/libs/shim-interface/src/lib.rs @@ -73,11 +73,8 @@ fn get_uds_with_sid(short_id: &str, path: &str) -> Result { } // return sandbox's storage path -pub fn sb_storage_path() -> Result<&'static str> { - //make sure the path existed - std::fs::create_dir_all(KATA_PATH).context(format!("failed to create dir: {KATA_PATH}"))?; - - Ok(KATA_PATH) +pub fn sb_storage_path() -> &'static str { + KATA_PATH } // returns the address of the unix domain socket(UDS) for communication with shim @@ -90,7 +87,7 @@ pub fn mgmt_socket_addr(sid: &str) -> Result { )); } - get_uds_with_sid(sid, sb_storage_path()?) + get_uds_with_sid(sid, sb_storage_path()) } #[cfg(test)] diff --git a/src/runtime-rs/crates/runtimes/src/shim_mgmt/server.rs b/src/runtime-rs/crates/runtimes/src/shim_mgmt/server.rs index 08ad681ffe..3484e9e826 100644 --- a/src/runtime-rs/crates/runtimes/src/shim_mgmt/server.rs +++ b/src/runtime-rs/crates/runtimes/src/shim_mgmt/server.rs @@ -16,7 +16,7 @@ use std::{fs, path::Path, sync::Arc}; use anyhow::{Context, Result}; use common::Sandbox; use hyper::{server::conn::Http, service::service_fn}; -use shim_interface::{mgmt_socket_addr, shim_mgmt::ERR_NO_SHIM_SERVER}; +use shim_interface::{sb_storage_path, SHIM_MGMT_SOCK_NAME}; use tokio::net::UnixListener; use super::handlers::handler_mux; @@ -33,10 +33,14 @@ pub struct MgmtServer { impl MgmtServer { /// construct a new management server pub fn new(sid: &str, sandbox: Arc) -> Result { - Ok(Self { - s_addr: mgmt_socket_addr(sid).context(ERR_NO_SHIM_SERVER)?, - sandbox, - }) + // make sure the storage path exists, and the socket file will be created in that path + let kata_path = sb_storage_path(); + fs::create_dir_all(kata_path) + .context(format!("failed to create kata path directory {kata_path}"))?; + + let s_addr = format!("unix://{kata_path}/{sid}/{SHIM_MGMT_SOCK_NAME}"); + + Ok(Self { s_addr, sandbox }) } // TODO(when metrics is supported): write metric addresses to fs