fix: remove meaningless input from other_error macro

Signed-off-by: Lei Liu <liulei.pt@bytedance.com>
This commit is contained in:
Lei Liu 2024-10-28 13:14:52 +08:00 committed by Maksym Pavlenko
parent a6b4286542
commit c22dba6201
10 changed files with 30 additions and 30 deletions

View File

@ -93,7 +93,7 @@ pub async fn register_memory_event(
let path = cg_dir.join(event_name); let path = cg_dir.join(event_name);
let event_file = fs::File::open(path.clone()) let event_file = fs::File::open(path.clone())
.await .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)?; 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()); let data = format!("{} {}", eventfd.as_raw_fd(), event_file.as_raw_fd());
fs::write(&event_control_path, data.clone()) fs::write(&event_control_path, data.clone())
.await .await
.map_err(other_error!(e, "Error write eventfd:"))?; .map_err(other_error!("Error write eventfd:"))?;
let mut buf = [0u8; 8]; let mut buf = [0u8; 8];

View File

@ -181,7 +181,7 @@ pub fn create_runc(
} }
gopts gopts
.build() .build()
.map_err(other_error!(e, "unable to create runc instance")) .map_err(other_error!("unable to create runc instance"))
} }
#[derive(Default)] #[derive(Default)]

View File

@ -340,7 +340,7 @@ impl ProcessLifecycle<InitProcess> for RuncInitLifecycle {
.runtime .runtime
.ps(&p.id) .ps(&p.id)
.await .await
.map_err(other_error!(e, "failed to execute runc ps"))?; .map_err(other_error!("failed to execute runc ps"))?;
Ok(pids Ok(pids
.iter() .iter()
.map(|&x| ProcessInfo { .map(|&x| ProcessInfo {

View File

@ -143,7 +143,7 @@ async fn monitor_oom(id: &String, pid: u32, tx: EventSender) -> Result<()> {
"memory.oom_control", "memory.oom_control",
) )
.await .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); run_oom_monitor(rx, id.to_string(), tx);
} }

View File

@ -117,7 +117,7 @@ impl Monitor {
subject: subject.clone(), subject: subject.clone(),
exit_code, exit_code,
}) })
.map_err(other_error!(e, "failed to send exit code")); .map_err(other_error!("failed to send exit code"));
results.push(res); results.push(res);
} }
} }

View File

@ -38,7 +38,7 @@ where
{ {
spawn_blocking(f) spawn_blocking(f)
.await .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<Path>) -> Result<String> { pub async fn read_file_to_str(path: impl AsRef<Path>) -> Result<String> {
@ -96,14 +96,14 @@ pub async fn read_pid_from_file(pid_path: &Path) -> Result<i32> {
pub async fn read_spec(bundle: impl AsRef<Path>) -> Result<Spec> { pub async fn read_spec(bundle: impl AsRef<Path>) -> Result<Spec> {
let path = bundle.as_ref().join(CONFIG_FILE_NAME); let path = bundle.as_ref().join(CONFIG_FILE_NAME);
let content = read_file_to_str(&path).await?; let content = read_file_to_str(&path).await?;
serde_json::from_str::<Spec>(content.as_str()).map_err(other_error!(e, "read spec")) serde_json::from_str::<Spec>(content.as_str()).map_err(other_error!("read spec"))
} }
pub async fn read_options(bundle: impl AsRef<Path>) -> Result<Options> { pub async fn read_options(bundle: impl AsRef<Path>) -> Result<Options> {
let path = bundle.as_ref().join(OPTIONS_FILE_NAME); let path = bundle.as_ref().join(OPTIONS_FILE_NAME);
let opts_str = read_file_to_str(path).await?; let opts_str = read_file_to_str(path).await?;
let opts = let opts =
serde_json::from_str::<JsonOptions>(&opts_str).map_err(other_error!(e, "read options"))?; serde_json::from_str::<JsonOptions>(&opts_str).map_err(other_error!("read options"))?;
Ok(opts.into()) Ok(opts.into())
} }

View File

@ -71,7 +71,7 @@ pub fn add_task_to_cgroup(path: &str, pid: u32) -> Result<()> {
Cgroup::load(h, path) Cgroup::load(h, path)
.add_task_by_tgid(CgroupPid::from(pid as u64)) .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 /// 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<i64> {
let score = content let score = content
.trim() .trim()
.parse::<i64>() .parse::<i64>()
.map_err(other_error!(e, "parse oom score"))?; .map_err(other_error!("parse oom score"))?;
Ok(score) Ok(score)
} }
@ -164,7 +164,7 @@ pub fn collect_metrics(pid: u32) -> Result<Metrics> {
pid_stats.set_current( pid_stats.set_current(
pid_ctr pid_ctr
.get_pid_current() .get_pid_current()
.map_err(other_error!(e, "get current pid"))?, .map_err(other_error!("get current pid"))?,
); );
pid_stats.set_limit( pid_stats.set_limit(
pid_ctr pid_ctr
@ -174,7 +174,7 @@ pub fn collect_metrics(pid: u32) -> Result<Metrics> {
cgroups_rs::MaxValue::Max => 0, cgroups_rs::MaxValue::Max => 0,
cgroups_rs::MaxValue::Value(val) => val as u64, 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) metrics.set_pids(pid_stats)
} }
@ -193,8 +193,8 @@ fn get_cgroup(pid: u32) -> Result<Cgroup> {
Cgroup::load(hierarchies, path) Cgroup::load(hierarchies, path)
} else { } else {
// get container main process cgroup // get container main process cgroup
let path = get_cgroups_relative_paths_by_pid(pid) let path =
.map_err(other_error!(e, "get process cgroup"))?; get_cgroups_relative_paths_by_pid(pid).map_err(other_error!("get process cgroup"))?;
Cgroup::load_with_relative_paths(hierarchies::auto(), Path::new("."), path) Cgroup::load_with_relative_paths(hierarchies::auto(), Path::new("."), path)
}; };
Ok(cgroup) Ok(cgroup)
@ -243,7 +243,7 @@ pub fn update_resources(pid: u32, resources: &LinuxResources) -> Result<()> {
if let Some(pids) = resources.pids() { if let Some(pids) = resources.pids() {
pid_ctr pid_ctr
.set_pid_max(MaxValue::Value(pids.limit())) .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) => { Subsystem::Mem(mem_ctr) => {
@ -257,24 +257,24 @@ pub fn update_resources(pid: u32, resources: &LinuxResources) -> Result<()> {
if current < swap { if current < swap {
mem_ctr mem_ctr
.set_memswap_limit(swap) .set_memswap_limit(swap)
.map_err(other_error!(e, "set memsw limit"))?; .map_err(other_error!("set memsw limit"))?;
mem_ctr mem_ctr
.set_limit(limit) .set_limit(limit)
.map_err(other_error!(e, "set mem limit"))?; .map_err(other_error!("set mem limit"))?;
} }
} }
// set memory limit in bytes // set memory limit in bytes
if let Some(limit) = memory.limit() { if let Some(limit) = memory.limit() {
mem_ctr mem_ctr
.set_limit(limit) .set_limit(limit)
.map_err(other_error!(e, "set mem limit"))?; .map_err(other_error!("set mem limit"))?;
} }
// set memory swap limit in bytes // set memory swap limit in bytes
if let Some(swap) = memory.swap() { if let Some(swap) = memory.swap() {
mem_ctr mem_ctr
.set_memswap_limit(swap) .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() { if let Some(cpus) = cpu.cpus() {
cpuset_ctr cpuset_ctr
.set_cpus(cpus) .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 // set list of memory nodes in the cpuset
if let Some(mems) = cpu.mems() { if let Some(mems) = cpu.mems() {
cpuset_ctr cpuset_ctr
.set_mems(mems) .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() { if let Some(shares) = cpu.shares() {
cpu_ctr cpu_ctr
.set_shares(shares) .set_shares(shares)
.map_err(other_error!(e, "set CPU share"))?; .map_err(other_error!("set CPU share"))?;
} }
// set CPU hardcap limit // set CPU hardcap limit
if let Some(quota) = cpu.quota() { if let Some(quota) = cpu.quota() {
cpu_ctr cpu_ctr
.set_cfs_quota(quota) .set_cfs_quota(quota)
.map_err(other_error!(e, "set CPU quota"))?; .map_err(other_error!("set CPU quota"))?;
} }
// set CPU hardcap period // set CPU hardcap period
if let Some(period) = cpu.period() { if let Some(period) = cpu.period() {
cpu_ctr cpu_ctr
.set_cfs_period(period) .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 { for limit in hp_limits {
ht_ctr ht_ctr
.set_limit_in_bytes(limit.page_size().as_str(), limit.limit() as u64) .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"))?;
} }
} }
} }

View File

@ -138,7 +138,7 @@ macro_rules! other {
#[macro_export] #[macro_export]
macro_rules! other_error { macro_rules! other_error {
($e:ident, $s:expr) => { ($s:expr) => {
|$e| Error::Other($s.to_string() + &": ".to_string() + &$e.to_string()) |e| Error::Other(format!("{}: {}", $s, e))
}; };
} }

View File

@ -27,7 +27,7 @@ use crate::error::Result;
/// on the process to discover its termination status. /// on the process to discover its termination status.
pub fn set_subreaper() -> Result<()> { pub fn set_subreaper() -> Result<()> {
use crate::error::Error; 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"))] #[cfg(not(target_os = "linux"))]

View File

@ -116,7 +116,7 @@ pub fn write_address(address: &str) -> crate::Result<()> {
pub fn read_spec_from_file(bundle: &str) -> crate::Result<Spec> { pub fn read_spec_from_file(bundle: &str) -> crate::Result<Spec> {
let path = Path::new(bundle).join("config.json"); 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)] #[cfg(unix)]