diff --git a/src/agent/src/config.rs b/src/agent/src/config.rs index 6441b07a19..99822e459f 100644 --- a/src/agent/src/config.rs +++ b/src/agent/src/config.rs @@ -27,7 +27,7 @@ const SERVER_ADDR_ENV_VAR: &str = "KATA_AGENT_SERVER_ADDR"; const LOG_LEVEL_ENV_VAR: &str = "KATA_AGENT_LOG_LEVEL"; #[derive(Debug)] -pub struct agentConfig { +pub struct AgentConfig { pub debug_console: bool, pub dev_mode: bool, pub log_level: slog::Level, @@ -69,9 +69,9 @@ macro_rules! parse_cmdline_param { }; } -impl agentConfig { - pub fn new() -> agentConfig { - agentConfig { +impl AgentConfig { + pub fn new() -> AgentConfig { + AgentConfig { debug_console: false, dev_mode: false, log_level: DEFAULT_LOG_LEVEL, @@ -311,7 +311,7 @@ mod tests { #[test] fn test_new() { - let config = agentConfig::new(); + let config = AgentConfig::new(); assert_eq!(config.debug_console, false); assert_eq!(config.dev_mode, false); assert_eq!(config.log_level, DEFAULT_LOG_LEVEL); @@ -818,7 +818,7 @@ mod tests { let filename = file_path.to_str().expect("failed to create filename"); - let mut config = agentConfig::new(); + let mut config = AgentConfig::new(); let result = config.parse_cmdline(&filename.to_owned()); assert!(result.is_err()); @@ -850,7 +850,7 @@ mod tests { vars_to_unset.push(name); } - let mut config = agentConfig::new(); + let mut config = AgentConfig::new(); assert_eq!(config.debug_console, false, "{}", msg); assert_eq!(config.dev_mode, false, "{}", msg); assert_eq!(config.unified_cgroup_hierarchy, false, "{}", msg); diff --git a/src/agent/src/main.rs b/src/agent/src/main.rs index f048bb7ed1..84ca33821f 100644 --- a/src/agent/src/main.rs +++ b/src/agent/src/main.rs @@ -3,7 +3,6 @@ // SPDX-License-Identifier: Apache-2.0 // -#![allow(non_camel_case_types)] #[macro_use] extern crate lazy_static; extern crate oci; @@ -83,11 +82,11 @@ const DEFAULT_BUF_SIZE: usize = 8 * 1024; lazy_static! { static ref GLOBAL_DEVICE_WATCHER: Arc>>>> = Arc::new(Mutex::new(HashMap::new())); - static ref AGENT_CONFIG: Arc> = - Arc::new(RwLock::new(config::agentConfig::new())); + static ref AGENT_CONFIG: Arc> = + Arc::new(RwLock::new(config::AgentConfig::new())); } -fn announce(logger: &Logger, config: &agentConfig) { +fn announce(logger: &Logger, config: &AgentConfig) { info!(logger, "announce"; "agent-commit" => version::VERSION_COMMIT, @@ -247,7 +246,7 @@ fn main() -> std::result::Result<(), Box> { }) } -async fn start_sandbox(logger: &Logger, config: &agentConfig, init_mode: bool) -> Result<()> { +async fn start_sandbox(logger: &Logger, config: &AgentConfig, init_mode: bool) -> Result<()> { let shells = SHELLS.clone(); let debug_console_vport = config.debug_console_vport as u32; @@ -446,7 +445,7 @@ lazy_static! { }; } -use crate::config::agentConfig; +use crate::config::AgentConfig; use nix::sys::stat::Mode; use std::os::unix::io::{FromRawFd, RawFd}; use std::path::PathBuf; diff --git a/src/agent/src/mount.rs b/src/agent/src/mount.rs index 89a187ebb8..8073d96f04 100644 --- a/src/agent/src/mount.rs +++ b/src/agent/src/mount.rs @@ -84,7 +84,7 @@ lazy_static! { } #[derive(Debug, PartialEq)] -pub struct INIT_MOUNT { +pub struct InitMount { fstype: &'static str, src: &'static str, dest: &'static str, @@ -114,13 +114,13 @@ lazy_static!{ #[rustfmt::skip] lazy_static! { - pub static ref INIT_ROOTFS_MOUNTS: Vec = vec![ - INIT_MOUNT{fstype: "proc", src: "proc", dest: "/proc", options: vec!["nosuid", "nodev", "noexec"]}, - INIT_MOUNT{fstype: "sysfs", src: "sysfs", dest: "/sys", options: vec!["nosuid", "nodev", "noexec"]}, - INIT_MOUNT{fstype: "devtmpfs", src: "dev", dest: "/dev", options: vec!["nosuid"]}, - INIT_MOUNT{fstype: "tmpfs", src: "tmpfs", dest: "/dev/shm", options: vec!["nosuid", "nodev"]}, - INIT_MOUNT{fstype: "devpts", src: "devpts", dest: "/dev/pts", options: vec!["nosuid", "noexec"]}, - INIT_MOUNT{fstype: "tmpfs", src: "tmpfs", dest: "/run", options: vec!["nosuid", "nodev"]}, + pub static ref INIT_ROOTFS_MOUNTS: Vec = vec![ + InitMount{fstype: "proc", src: "proc", dest: "/proc", options: vec!["nosuid", "nodev", "noexec"]}, + InitMount{fstype: "sysfs", src: "sysfs", dest: "/sys", options: vec!["nosuid", "nodev", "noexec"]}, + InitMount{fstype: "devtmpfs", src: "dev", dest: "/dev", options: vec!["nosuid"]}, + InitMount{fstype: "tmpfs", src: "tmpfs", dest: "/dev/shm", options: vec!["nosuid", "nodev"]}, + InitMount{fstype: "devpts", src: "devpts", dest: "/dev/pts", options: vec!["nosuid", "noexec"]}, + InitMount{fstype: "tmpfs", src: "tmpfs", dest: "/run", options: vec!["nosuid", "nodev"]}, ]; } @@ -492,7 +492,7 @@ pub async fn add_storages( Ok(mount_list) } -fn mount_to_rootfs(logger: &Logger, m: &INIT_MOUNT) -> Result<()> { +fn mount_to_rootfs(logger: &Logger, m: &InitMount) -> Result<()> { let options_vec: Vec<&str> = m.options.clone(); let (flags, options) = parse_mount_flags_and_options(options_vec); @@ -568,11 +568,11 @@ pub fn get_cgroup_mounts( logger: &Logger, cg_path: &str, unified_cgroup_hierarchy: bool, -) -> Result> { +) -> Result> { // cgroup v2 // https://github.com/kata-containers/agent/blob/8c9bbadcd448c9a67690fbe11a860aaacc69813c/agent.go#L1249 if unified_cgroup_hierarchy { - return Ok(vec![INIT_MOUNT { + return Ok(vec![InitMount { fstype: "cgroup2", src: "cgroup2", dest: "/sys/fs/cgroup", @@ -584,7 +584,7 @@ pub fn get_cgroup_mounts( let reader = BufReader::new(file); let mut has_device_cgroup = false; - let mut cg_mounts: Vec = vec![INIT_MOUNT { + let mut cg_mounts: Vec = vec![InitMount { fstype: "tmpfs", src: "tmpfs", dest: SYSFS_CGROUPPATH, @@ -630,7 +630,7 @@ pub fn get_cgroup_mounts( if let Some(value) = CGROUPS.get(&fields[0]) { let key = CGROUPS.keys().find(|&&f| f == fields[0]).unwrap(); - cg_mounts.push(INIT_MOUNT { + cg_mounts.push(InitMount { fstype: "cgroup", src: "cgroup", dest: *value, @@ -644,7 +644,7 @@ pub fn get_cgroup_mounts( return Ok(Vec::new()); } - cg_mounts.push(INIT_MOUNT { + cg_mounts.push(InitMount { fstype: "tmpfs", src: "tmpfs", dest: SYSFS_CGROUPPATH, @@ -1142,21 +1142,21 @@ mod tests { let drain = slog::Discard; let logger = slog::Logger::root(drain, o!()); - let first_mount = INIT_MOUNT { + let first_mount = InitMount { fstype: "tmpfs", src: "tmpfs", dest: SYSFS_CGROUPPATH, options: vec!["nosuid", "nodev", "noexec", "mode=755"], }; - let last_mount = INIT_MOUNT { + let last_mount = InitMount { fstype: "tmpfs", src: "tmpfs", dest: SYSFS_CGROUPPATH, options: vec!["remount", "ro", "nosuid", "nodev", "noexec", "mode=755"], }; - let cg_devices_mount = INIT_MOUNT { + let cg_devices_mount = InitMount { fstype: "cgroup", src: "cgroup", dest: "/sys/fs/cgroup/devices", diff --git a/src/agent/src/netlink.rs b/src/agent/src/netlink.rs index a851c5ae77..b0500be635 100644 --- a/src/agent/src/netlink.rs +++ b/src/agent/src/netlink.rs @@ -45,7 +45,7 @@ pub enum AddressFilter { } /// A high level wrapper for netlink (and `rtnetlink` crate) for use by the Agent's RPC. -/// It is expected to be consumed by the `agentService`, so it operates with protobuf +/// It is expected to be consumed by the `AgentService`, so it operates with protobuf /// structures directly for convenience. #[derive(Debug)] pub struct Handle { diff --git a/src/agent/src/rpc.rs b/src/agent/src/rpc.rs index 785a9fc9c4..05d7f77bf7 100644 --- a/src/agent/src/rpc.rs +++ b/src/agent/src/rpc.rs @@ -76,11 +76,11 @@ macro_rules! sl { } #[derive(Clone)] -pub struct agentService { +pub struct AgentService { sandbox: Arc>, } -impl agentService { +impl AgentService { async fn do_create_container( &self, req: protocols::agent::CreateContainerRequest, @@ -493,7 +493,7 @@ impl agentService { } #[async_trait] -impl protocols::agent_ttrpc::AgentService for agentService { +impl protocols::agent_ttrpc::AgentService for AgentService { async fn create_container( &self, _ctx: &TtrpcContext, @@ -1203,10 +1203,10 @@ impl protocols::agent_ttrpc::AgentService for agentService { } #[derive(Clone)] -struct healthService; +struct HealthService; #[async_trait] -impl protocols::health_ttrpc::Health for healthService { +impl protocols::health_ttrpc::Health for HealthService { async fn check( &self, _ctx: &TtrpcContext, @@ -1334,13 +1334,13 @@ fn find_process<'a>( } pub fn start(s: Arc>, server_address: &str) -> TtrpcServer { - let agent_service = Box::new(agentService { sandbox: s }) + let agent_service = Box::new(AgentService { sandbox: s }) as Box; let agent_worker = Arc::new(agent_service); let health_service = - Box::new(healthService {}) as Box; + Box::new(HealthService {}) as Box; let health_worker = Arc::new(health_service); let aservice = protocols::agent_ttrpc::create_agent_service(agent_worker); @@ -1670,7 +1670,7 @@ fn load_kernel_module(module: &protocols::agent::KernelModule) -> Result<()> { #[cfg(test)] mod tests { use super::*; - use crate::protocols::agent_ttrpc::AgentService; + use crate::protocols::agent_ttrpc::AgentService as _; use oci::{Hook, Hooks}; use ttrpc::{r#async::TtrpcContext, MessageHeader}; @@ -1725,7 +1725,7 @@ mod tests { let logger = slog::Logger::root(slog::Discard, o!()); let sandbox = Sandbox::new(&logger).unwrap(); - let agent_service = Box::new(agentService { + let agent_service = Box::new(AgentService { sandbox: Arc::new(Mutex::new(sandbox)), }); @@ -1742,7 +1742,7 @@ mod tests { let logger = slog::Logger::root(slog::Discard, o!()); let sandbox = Sandbox::new(&logger).unwrap(); - let agent_service = Box::new(agentService { + let agent_service = Box::new(AgentService { sandbox: Arc::new(Mutex::new(sandbox)), }); @@ -1759,7 +1759,7 @@ mod tests { let logger = slog::Logger::root(slog::Discard, o!()); let sandbox = Sandbox::new(&logger).unwrap(); - let agent_service = Box::new(agentService { + let agent_service = Box::new(AgentService { sandbox: Arc::new(Mutex::new(sandbox)), });