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