mirror of
https://github.com/kata-containers/kata-containers.git
synced 2026-07-02 07:02:16 +00:00
runtime-rs: Move KATA_PATH creation from sb_storage_path() to MgmtServer
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 <alex.lyn@antgroup.com>
This commit is contained in:
@@ -73,11 +73,8 @@ fn get_uds_with_sid(short_id: &str, path: &str) -> Result<String> {
|
||||
}
|
||||
|
||||
// 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<String> {
|
||||
));
|
||||
}
|
||||
|
||||
get_uds_with_sid(sid, sb_storage_path()?)
|
||||
get_uds_with_sid(sid, sb_storage_path())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -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<dyn Sandbox>) -> Result<Self> {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user