mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 04:34:27 +00:00
agent: change AGENT_CONFIG
's lazy type to just AgentConfig
Since it is never modified, it doesn't really need a lock of any kind. Removing the `RwLock` wrapper allows us to remove all `.read().await` calls when accessing it. Additionally, `AGENT_CONFIG` already has a static lifetime, so there is no need to wrap it in a ref-counted heap allocation. Fixes: #5409 Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com>
This commit is contained in:
parent
469c678425
commit
f680fc52be
@ -65,7 +65,7 @@ use tokio::{
|
|||||||
io::AsyncWrite,
|
io::AsyncWrite,
|
||||||
sync::{
|
sync::{
|
||||||
watch::{channel, Receiver},
|
watch::{channel, Receiver},
|
||||||
Mutex, RwLock,
|
Mutex,
|
||||||
},
|
},
|
||||||
task::JoinHandle,
|
task::JoinHandle,
|
||||||
};
|
};
|
||||||
@ -83,12 +83,11 @@ cfg_if! {
|
|||||||
const NAME: &str = "kata-agent";
|
const NAME: &str = "kata-agent";
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref AGENT_CONFIG: Arc<RwLock<AgentConfig>> = 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
|
// 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,
|
// clap::Parser::parse() greedily process all command line input including cargo test parameters,
|
||||||
// so should only be used inside main.
|
// 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)]
|
#[derive(Parser)]
|
||||||
@ -181,13 +180,13 @@ async fn real_main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
lazy_static::initialize(&AGENT_CONFIG);
|
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);
|
drop(logger_async_guard);
|
||||||
} else {
|
} else {
|
||||||
lazy_static::initialize(&AGENT_CONFIG);
|
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_vport = config.log_vport as u32;
|
||||||
|
|
||||||
let log_handle = tokio::spawn(create_logger_task(rfd, log_vport, shutdown_rx.clone()));
|
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<dyn std::error::Error>> {
|
|||||||
let (logger, logger_async_guard) =
|
let (logger, logger_async_guard) =
|
||||||
logging::create_logger(NAME, "agent", config.log_level, writer);
|
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,
|
// 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.
|
// 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<dyn std::error::Error>> {
|
|||||||
let span_guard = root_span.enter();
|
let span_guard = root_span.enter();
|
||||||
|
|
||||||
// Start the sandbox and wait for its ttRPC server to end
|
// 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
|
// Install a NOP logger for the remainder of the shutdown sequence
|
||||||
// to ensure any log calls made by local crates using the scope logger
|
// to ensure any log calls made by local crates using the scope logger
|
||||||
|
@ -126,11 +126,7 @@ macro_rules! ttrpc_error {
|
|||||||
|
|
||||||
macro_rules! is_allowed {
|
macro_rules! is_allowed {
|
||||||
($req:ident) => {
|
($req:ident) => {
|
||||||
if !AGENT_CONFIG
|
if !AGENT_CONFIG.is_allowed_endpoint($req.descriptor_dyn().name()) {
|
||||||
.read()
|
|
||||||
.await
|
|
||||||
.is_allowed_endpoint($req.descriptor_dyn().name())
|
|
||||||
{
|
|
||||||
return Err(ttrpc_error!(
|
return Err(ttrpc_error!(
|
||||||
ttrpc::Code::UNIMPLEMENTED,
|
ttrpc::Code::UNIMPLEMENTED,
|
||||||
format!("{} is blocked", $req.descriptor_dyn().name()),
|
format!("{} is blocked", $req.descriptor_dyn().name()),
|
||||||
@ -240,7 +236,7 @@ impl AgentService {
|
|||||||
let mut ctr: LinuxContainer =
|
let mut ctr: LinuxContainer =
|
||||||
LinuxContainer::new(cid.as_str(), CONTAINER_BASE, opts, &sl!())?;
|
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 {
|
let p = if let Some(p) = oci.process {
|
||||||
Process::new(&sl!(), &p, cid.as_str(), true, pipe_size)?
|
Process::new(&sl!(), &p, cid.as_str(), true, pipe_size)?
|
||||||
@ -374,7 +370,7 @@ impl AgentService {
|
|||||||
// Apply any necessary corrections for PCI addresses
|
// Apply any necessary corrections for PCI addresses
|
||||||
update_env_pci(&mut process.Env, &sandbox.pcimap)?;
|
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 ocip = rustjail::process_grpc_to_oci(&process);
|
||||||
let p = Process::new(&sl!(), &ocip, exec_id.as_str(), false, pipe_size)?;
|
let p = Process::new(&sl!(), &ocip, exec_id.as_str(), false, pipe_size)?;
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ pub async fn wait_for_uevent(
|
|||||||
|
|
||||||
info!(sl!(), "{}: waiting on channel", logprefix);
|
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 {
|
let uev = match tokio::time::timeout(hotplug_timeout, rx).await {
|
||||||
Ok(v) => v?,
|
Ok(v) => v?,
|
||||||
|
Loading…
Reference in New Issue
Block a user