diff --git a/src/agent/src/main.rs b/src/agent/src/main.rs index f82904804c..58c406fe17 100644 --- a/src/agent/src/main.rs +++ b/src/agent/src/main.rs @@ -65,7 +65,7 @@ use tokio::{ io::AsyncWrite, sync::{ watch::{channel, Receiver}, - Mutex, RwLock, + Mutex, }, task::JoinHandle, }; @@ -83,12 +83,11 @@ cfg_if! { const NAME: &str = "kata-agent"; lazy_static! { - static ref AGENT_CONFIG: Arc> = Arc::new(RwLock::new( + static ref AGENT_CONFIG: AgentConfig = // Note: We can't do AgentOpts.parse() here to send through the processed arguments to AgentConfig // clap::Parser::parse() greedily process all command line input including cargo test parameters, // so should only be used inside main. - AgentConfig::from_cmdline("/proc/cmdline", env::args().collect()).unwrap() - )); + AgentConfig::from_cmdline("/proc/cmdline", env::args().collect()).unwrap(); } #[derive(Parser)] @@ -181,13 +180,13 @@ async fn real_main() -> std::result::Result<(), Box> { lazy_static::initialize(&AGENT_CONFIG); - init_agent_as_init(&logger, AGENT_CONFIG.read().await.unified_cgroup_hierarchy)?; + init_agent_as_init(&logger, AGENT_CONFIG.unified_cgroup_hierarchy)?; drop(logger_async_guard); } else { lazy_static::initialize(&AGENT_CONFIG); } - let config = AGENT_CONFIG.read().await; + let config = &AGENT_CONFIG; let log_vport = config.log_vport as u32; let log_handle = tokio::spawn(create_logger_task(rfd, log_vport, shutdown_rx.clone())); @@ -200,7 +199,7 @@ async fn real_main() -> std::result::Result<(), Box> { let (logger, logger_async_guard) = logging::create_logger(NAME, "agent", config.log_level, writer); - announce(&logger, &config); + announce(&logger, config); // This variable is required as it enables the global (and crucially static) logger, // which is required to satisfy the the lifetime constraints of the auto-generated gRPC code. @@ -228,7 +227,7 @@ async fn real_main() -> std::result::Result<(), Box> { let span_guard = root_span.enter(); // Start the sandbox and wait for its ttRPC server to end - start_sandbox(&logger, &config, init_mode, &mut tasks, shutdown_rx.clone()).await?; + start_sandbox(&logger, config, init_mode, &mut tasks, shutdown_rx.clone()).await?; // Install a NOP logger for the remainder of the shutdown sequence // to ensure any log calls made by local crates using the scope logger diff --git a/src/agent/src/rpc.rs b/src/agent/src/rpc.rs index dede3204c8..ed7729855b 100644 --- a/src/agent/src/rpc.rs +++ b/src/agent/src/rpc.rs @@ -126,11 +126,7 @@ macro_rules! ttrpc_error { macro_rules! is_allowed { ($req:ident) => { - if !AGENT_CONFIG - .read() - .await - .is_allowed_endpoint($req.descriptor_dyn().name()) - { + if !AGENT_CONFIG.is_allowed_endpoint($req.descriptor_dyn().name()) { return Err(ttrpc_error!( ttrpc::Code::UNIMPLEMENTED, format!("{} is blocked", $req.descriptor_dyn().name()), @@ -240,7 +236,7 @@ impl AgentService { let mut ctr: LinuxContainer = LinuxContainer::new(cid.as_str(), CONTAINER_BASE, opts, &sl!())?; - let pipe_size = AGENT_CONFIG.read().await.container_pipe_size; + let pipe_size = AGENT_CONFIG.container_pipe_size; let p = if let Some(p) = oci.process { Process::new(&sl!(), &p, cid.as_str(), true, pipe_size)? @@ -374,7 +370,7 @@ impl AgentService { // Apply any necessary corrections for PCI addresses update_env_pci(&mut process.Env, &sandbox.pcimap)?; - let pipe_size = AGENT_CONFIG.read().await.container_pipe_size; + let pipe_size = AGENT_CONFIG.container_pipe_size; let ocip = rustjail::process_grpc_to_oci(&process); let p = Process::new(&sl!(), &ocip, exec_id.as_str(), false, pipe_size)?; diff --git a/src/agent/src/uevent.rs b/src/agent/src/uevent.rs index 5d1f554940..cabdd6235c 100644 --- a/src/agent/src/uevent.rs +++ b/src/agent/src/uevent.rs @@ -141,7 +141,7 @@ pub async fn wait_for_uevent( info!(sl!(), "{}: waiting on channel", logprefix); - let hotplug_timeout = AGENT_CONFIG.read().await.hotplug_timeout; + let hotplug_timeout = AGENT_CONFIG.hotplug_timeout; let uev = match tokio::time::timeout(hotplug_timeout, rx).await { Ok(v) => v?,