From ed0b40eea79a6cb5266a5eb7dabf2a86fbfeb3aa Mon Sep 17 00:00:00 2001 From: Lei Liu Date: Mon, 28 Oct 2024 13:14:52 +0800 Subject: [PATCH] fix: remove meaningless input from other_error macro Signed-off-by: Lei Liu --- crates/runc-shim/src/cgroup_memory.rs | 4 +-- crates/runc-shim/src/common.rs | 2 +- crates/runc-shim/src/runc.rs | 2 +- crates/runc-shim/src/task.rs | 2 +- crates/shim/src/asynchronous/monitor.rs | 2 +- crates/shim/src/asynchronous/util.rs | 6 ++--- crates/shim/src/cgroup.rs | 34 ++++++++++++------------- crates/shim/src/error.rs | 4 +-- crates/shim/src/reap.rs | 2 +- crates/shim/src/synchronous/util.rs | 2 +- 10 files changed, 30 insertions(+), 30 deletions(-) diff --git a/crates/runc-shim/src/cgroup_memory.rs b/crates/runc-shim/src/cgroup_memory.rs index 0ab407f0..2d8a69cf 100644 --- a/crates/runc-shim/src/cgroup_memory.rs +++ b/crates/runc-shim/src/cgroup_memory.rs @@ -93,7 +93,7 @@ pub async fn register_memory_event( let path = cg_dir.join(event_name); let event_file = fs::File::open(path.clone()) .await - .map_err(other_error!(e, "Error get path:"))?; + .map_err(other_error!("Error get path:"))?; let eventfd = EventFd::from_value_and_flags(0, EfdFlags::EFD_CLOEXEC)?; @@ -101,7 +101,7 @@ pub async fn register_memory_event( let data = format!("{} {}", eventfd.as_raw_fd(), event_file.as_raw_fd()); fs::write(&event_control_path, data.clone()) .await - .map_err(other_error!(e, "Error write eventfd:"))?; + .map_err(other_error!("Error write eventfd:"))?; let mut buf = [0u8; 8]; diff --git a/crates/runc-shim/src/common.rs b/crates/runc-shim/src/common.rs index 5a84e4df..c5a271c7 100644 --- a/crates/runc-shim/src/common.rs +++ b/crates/runc-shim/src/common.rs @@ -181,7 +181,7 @@ pub fn create_runc( } gopts .build() - .map_err(other_error!(e, "unable to create runc instance")) + .map_err(other_error!("unable to create runc instance")) } #[derive(Default)] diff --git a/crates/runc-shim/src/runc.rs b/crates/runc-shim/src/runc.rs index 92bb0f23..38e9d68f 100644 --- a/crates/runc-shim/src/runc.rs +++ b/crates/runc-shim/src/runc.rs @@ -340,7 +340,7 @@ impl ProcessLifecycle for RuncInitLifecycle { .runtime .ps(&p.id) .await - .map_err(other_error!(e, "failed to execute runc ps"))?; + .map_err(other_error!("failed to execute runc ps"))?; Ok(pids .iter() .map(|&x| ProcessInfo { diff --git a/crates/runc-shim/src/task.rs b/crates/runc-shim/src/task.rs index 3e677c9c..2fdd4dd2 100644 --- a/crates/runc-shim/src/task.rs +++ b/crates/runc-shim/src/task.rs @@ -143,7 +143,7 @@ async fn monitor_oom(id: &String, pid: u32, tx: EventSender) -> Result<()> { "memory.oom_control", ) .await - .map_err(other_error!(e, "register_memory_event failed:"))?; + .map_err(other_error!("register_memory_event failed:"))?; run_oom_monitor(rx, id.to_string(), tx); } diff --git a/crates/shim/src/asynchronous/monitor.rs b/crates/shim/src/asynchronous/monitor.rs index 7ed8c0a2..efc7b0ff 100644 --- a/crates/shim/src/asynchronous/monitor.rs +++ b/crates/shim/src/asynchronous/monitor.rs @@ -117,7 +117,7 @@ impl Monitor { subject: subject.clone(), exit_code, }) - .map_err(other_error!(e, "failed to send exit code")); + .map_err(other_error!("failed to send exit code")); results.push(res); } } diff --git a/crates/shim/src/asynchronous/util.rs b/crates/shim/src/asynchronous/util.rs index f0f54010..43e2b88d 100644 --- a/crates/shim/src/asynchronous/util.rs +++ b/crates/shim/src/asynchronous/util.rs @@ -38,7 +38,7 @@ where { spawn_blocking(f) .await - .map_err(other_error!(e, "failed to spawn blocking task"))? + .map_err(other_error!("failed to spawn blocking task"))? } pub async fn read_file_to_str(path: impl AsRef) -> Result { @@ -96,14 +96,14 @@ pub async fn read_pid_from_file(pid_path: &Path) -> Result { pub async fn read_spec(bundle: impl AsRef) -> Result { let path = bundle.as_ref().join(CONFIG_FILE_NAME); let content = read_file_to_str(&path).await?; - serde_json::from_str::(content.as_str()).map_err(other_error!(e, "read spec")) + serde_json::from_str::(content.as_str()).map_err(other_error!("read spec")) } pub async fn read_options(bundle: impl AsRef) -> Result { let path = bundle.as_ref().join(OPTIONS_FILE_NAME); let opts_str = read_file_to_str(path).await?; let opts = - serde_json::from_str::(&opts_str).map_err(other_error!(e, "read options"))?; + serde_json::from_str::(&opts_str).map_err(other_error!("read options"))?; Ok(opts.into()) } diff --git a/crates/shim/src/cgroup.rs b/crates/shim/src/cgroup.rs index 1df260f3..4c969bec 100644 --- a/crates/shim/src/cgroup.rs +++ b/crates/shim/src/cgroup.rs @@ -71,7 +71,7 @@ pub fn add_task_to_cgroup(path: &str, pid: u32) -> Result<()> { Cgroup::load(h, path) .add_task_by_tgid(CgroupPid::from(pid as u64)) - .map_err(other_error!(e, "add task to cgroup")) + .map_err(other_error!("add task to cgroup")) } /// Sets the OOM score for the process to the parents OOM score + 1 @@ -92,7 +92,7 @@ fn read_process_oom_score(pid: u32) -> Result { let score = content .trim() .parse::() - .map_err(other_error!(e, "parse oom score"))?; + .map_err(other_error!("parse oom score"))?; Ok(score) } @@ -164,7 +164,7 @@ pub fn collect_metrics(pid: u32) -> Result { pid_stats.set_current( pid_ctr .get_pid_current() - .map_err(other_error!(e, "get current pid"))?, + .map_err(other_error!("get current pid"))?, ); pid_stats.set_limit( pid_ctr @@ -174,7 +174,7 @@ pub fn collect_metrics(pid: u32) -> Result { cgroups_rs::MaxValue::Max => 0, cgroups_rs::MaxValue::Value(val) => val as u64, }) - .map_err(other_error!(e, "get pid limit"))?, + .map_err(other_error!("get pid limit"))?, ); metrics.set_pids(pid_stats) } @@ -193,8 +193,8 @@ fn get_cgroup(pid: u32) -> Result { Cgroup::load(hierarchies, path) } else { // get container main process cgroup - let path = get_cgroups_relative_paths_by_pid(pid) - .map_err(other_error!(e, "get process cgroup"))?; + let path = + get_cgroups_relative_paths_by_pid(pid).map_err(other_error!("get process cgroup"))?; Cgroup::load_with_relative_paths(hierarchies::auto(), Path::new("."), path) }; Ok(cgroup) @@ -243,7 +243,7 @@ pub fn update_resources(pid: u32, resources: &LinuxResources) -> Result<()> { if let Some(pids) = resources.pids() { pid_ctr .set_pid_max(MaxValue::Value(pids.limit())) - .map_err(other_error!(e, "set pid max"))?; + .map_err(other_error!("set pid max"))?; } } Subsystem::Mem(mem_ctr) => { @@ -257,24 +257,24 @@ pub fn update_resources(pid: u32, resources: &LinuxResources) -> Result<()> { if current < swap { mem_ctr .set_memswap_limit(swap) - .map_err(other_error!(e, "set memsw limit"))?; + .map_err(other_error!("set memsw limit"))?; mem_ctr .set_limit(limit) - .map_err(other_error!(e, "set mem limit"))?; + .map_err(other_error!("set mem limit"))?; } } // set memory limit in bytes if let Some(limit) = memory.limit() { mem_ctr .set_limit(limit) - .map_err(other_error!(e, "set mem limit"))?; + .map_err(other_error!("set mem limit"))?; } // set memory swap limit in bytes if let Some(swap) = memory.swap() { mem_ctr .set_memswap_limit(swap) - .map_err(other_error!(e, "set memsw limit"))?; + .map_err(other_error!("set memsw limit"))?; } } } @@ -284,14 +284,14 @@ pub fn update_resources(pid: u32, resources: &LinuxResources) -> Result<()> { if let Some(cpus) = cpu.cpus() { cpuset_ctr .set_cpus(cpus) - .map_err(other_error!(e, "set CPU sets"))?; + .map_err(other_error!("set CPU sets"))?; } // set list of memory nodes in the cpuset if let Some(mems) = cpu.mems() { cpuset_ctr .set_mems(mems) - .map_err(other_error!(e, "set CPU memes"))?; + .map_err(other_error!("set CPU memes"))?; } } } @@ -301,21 +301,21 @@ pub fn update_resources(pid: u32, resources: &LinuxResources) -> Result<()> { if let Some(shares) = cpu.shares() { cpu_ctr .set_shares(shares) - .map_err(other_error!(e, "set CPU share"))?; + .map_err(other_error!("set CPU share"))?; } // set CPU hardcap limit if let Some(quota) = cpu.quota() { cpu_ctr .set_cfs_quota(quota) - .map_err(other_error!(e, "set CPU quota"))?; + .map_err(other_error!("set CPU quota"))?; } // set CPU hardcap period if let Some(period) = cpu.period() { cpu_ctr .set_cfs_period(period) - .map_err(other_error!(e, "set CPU period"))?; + .map_err(other_error!("set CPU period"))?; } } } @@ -325,7 +325,7 @@ pub fn update_resources(pid: u32, resources: &LinuxResources) -> Result<()> { for limit in hp_limits { ht_ctr .set_limit_in_bytes(limit.page_size().as_str(), limit.limit() as u64) - .map_err(other_error!(e, "set huge page limit"))?; + .map_err(other_error!("set huge page limit"))?; } } } diff --git a/crates/shim/src/error.rs b/crates/shim/src/error.rs index 241f98dd..2d741f06 100644 --- a/crates/shim/src/error.rs +++ b/crates/shim/src/error.rs @@ -138,7 +138,7 @@ macro_rules! other { #[macro_export] macro_rules! other_error { - ($e:ident, $s:expr) => { - |$e| Error::Other($s.to_string() + &": ".to_string() + &$e.to_string()) + ($s:expr) => { + |e| Error::Other(format!("{}: {}", $s, e)) }; } diff --git a/crates/shim/src/reap.rs b/crates/shim/src/reap.rs index db75373e..585e3749 100644 --- a/crates/shim/src/reap.rs +++ b/crates/shim/src/reap.rs @@ -27,7 +27,7 @@ use crate::error::Result; /// on the process to discover its termination status. pub fn set_subreaper() -> Result<()> { use crate::error::Error; - prctl::set_child_subreaper(true).map_err(other_error!(code, "linux prctl returned")) + prctl::set_child_subreaper(true).map_err(other_error!("linux prctl returned")) } #[cfg(not(target_os = "linux"))] diff --git a/crates/shim/src/synchronous/util.rs b/crates/shim/src/synchronous/util.rs index c78c17a2..7b79bcfe 100644 --- a/crates/shim/src/synchronous/util.rs +++ b/crates/shim/src/synchronous/util.rs @@ -116,7 +116,7 @@ pub fn write_address(address: &str) -> crate::Result<()> { pub fn read_spec_from_file(bundle: &str) -> crate::Result { let path = Path::new(bundle).join("config.json"); - Spec::load(path).map_err(other_error!(e, "read spec file")) + Spec::load(path).map_err(other_error!("read spec file")) } #[cfg(unix)]