Fix: update cgroups-rs for fix a bug

bug ref:
7d4d4579a3

Signed-off-by: jokemanfire <hu.dingyang@zte.com.cn>
This commit is contained in:
jokemanfire 2025-08-01 09:50:14 +08:00 committed by Maksym Pavlenko
parent ae58ea3aed
commit 6b81286549
4 changed files with 19 additions and 11 deletions

View File

@ -26,7 +26,7 @@ edition = "2021"
# Common dependencies for all crates
[workspace.dependencies]
async-trait = "0.1.52"
cgroups-rs = "0.3.4"
cgroups-rs = "0.4.0"
crossbeam = "0.8.1"
futures = "0.3.19"
libc = "0.2.112"

View File

@ -125,9 +125,12 @@ mod tests {
use std::path::Path;
use cgroups_rs::{
hierarchies::{self, is_cgroup2_unified_mode},
memory::MemController,
Cgroup, CgroupPid,
fs::{
hierarchies::{self, is_cgroup2_unified_mode},
memory::MemController,
Cgroup,
},
CgroupPid,
};
use tokio::{fs::remove_file, io::AsyncWriteExt, process::Command};
@ -139,7 +142,6 @@ mod tests {
// Create a memory cgroup with limits on both memory and swap.
let path = "cgroupv1_oom_monitor";
let cg = Cgroup::new(hierarchies::auto(), path).unwrap();
let mem_controller: &MemController = cg.controller_of().unwrap();
mem_controller.set_limit(10 * 1024 * 1024).unwrap(); // 10M
mem_controller.set_swappiness(0).unwrap();

View File

@ -50,7 +50,7 @@ type EventSender = Sender<(String, Box<dyn MessageDyn>)>;
use std::path::Path;
#[cfg(target_os = "linux")]
use cgroups_rs::hierarchies::is_cgroup2_unified_mode;
use cgroups_rs::fs::hierarchies::is_cgroup2_unified_mode;
use containerd_shim::{
api::{PauseRequest, ResumeRequest},
protos::events::task::{TaskPaused, TaskResumed},

View File

@ -24,8 +24,11 @@ use std::{
};
use cgroups_rs::{
cgroup::get_cgroups_relative_paths_by_pid, error::Result as CgResult, hierarchies, Cgroup,
CgroupPid, MaxValue, Subsystem,
fs::{
cgroup::get_cgroups_relative_paths_by_pid, error::Result as CgResult, hierarchies, Cgroup,
MaxValue, Subsystem,
},
CgroupPid,
};
use containerd_shim_protos::{
cgroups::metrics::{CPUStat, CPUUsage, MemoryEntry, MemoryStat, Metrics, PidsStat, Throttle},
@ -186,8 +189,8 @@ pub fn collect_metrics(pid: u32) -> Result<Metrics> {
pid_stats.set_limit(
ignore_err(pid_ctr.get_pid_max().map(|val| match val {
// See https://github.com/opencontainers/runc/blob/dbe8434359ca35af1c1e10df42b1f4391c1e1010/libcontainer/cgroups/fs/pids.go#L55
cgroups_rs::MaxValue::Max => 0,
cgroups_rs::MaxValue::Value(val) => val as u64,
MaxValue::Max => 0,
MaxValue::Value(val) => val as u64,
}))
.map_err(other_error!("get pid limit"))?,
);
@ -354,7 +357,10 @@ pub fn update_resources(pid: u32, resources: &LinuxResources) -> Result<()> {
mod tests {
use std::path::PathBuf;
use cgroups_rs::{hierarchies, Cgroup, CgroupPid};
use cgroups_rs::{
fs::{hierarchies, Cgroup},
CgroupPid,
};
use super::parse_cgroups_v2_path;
use crate::cgroup::{