Skip to content

Commit 6b81286

Browse files
jokemanfiremxpv
authored andcommitted
Fix: update cgroups-rs for fix a bug
bug ref: kata-containers/cgroups-rs@7d4d457 Signed-off-by: jokemanfire <[email protected]>
1 parent ae58ea3 commit 6b81286

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ edition = "2021"
2626
# Common dependencies for all crates
2727
[workspace.dependencies]
2828
async-trait = "0.1.52"
29-
cgroups-rs = "0.3.4"
29+
cgroups-rs = "0.4.0"
3030
crossbeam = "0.8.1"
3131
futures = "0.3.19"
3232
libc = "0.2.112"

crates/runc-shim/src/cgroup_memory.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,12 @@ mod tests {
125125
use std::path::Path;
126126

127127
use cgroups_rs::{
128-
hierarchies::{self, is_cgroup2_unified_mode},
129-
memory::MemController,
130-
Cgroup, CgroupPid,
128+
fs::{
129+
hierarchies::{self, is_cgroup2_unified_mode},
130+
memory::MemController,
131+
Cgroup,
132+
},
133+
CgroupPid,
131134
};
132135
use tokio::{fs::remove_file, io::AsyncWriteExt, process::Command};
133136

@@ -139,7 +142,6 @@ mod tests {
139142
// Create a memory cgroup with limits on both memory and swap.
140143
let path = "cgroupv1_oom_monitor";
141144
let cg = Cgroup::new(hierarchies::auto(), path).unwrap();
142-
143145
let mem_controller: &MemController = cg.controller_of().unwrap();
144146
mem_controller.set_limit(10 * 1024 * 1024).unwrap(); // 10M
145147
mem_controller.set_swappiness(0).unwrap();

crates/runc-shim/src/task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type EventSender = Sender<(String, Box<dyn MessageDyn>)>;
5050
use std::path::Path;
5151

5252
#[cfg(target_os = "linux")]
53-
use cgroups_rs::hierarchies::is_cgroup2_unified_mode;
53+
use cgroups_rs::fs::hierarchies::is_cgroup2_unified_mode;
5454
use containerd_shim::{
5555
api::{PauseRequest, ResumeRequest},
5656
protos::events::task::{TaskPaused, TaskResumed},

crates/shim/src/cgroup.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ use std::{
2424
};
2525

2626
use cgroups_rs::{
27-
cgroup::get_cgroups_relative_paths_by_pid, error::Result as CgResult, hierarchies, Cgroup,
28-
CgroupPid, MaxValue, Subsystem,
27+
fs::{
28+
cgroup::get_cgroups_relative_paths_by_pid, error::Result as CgResult, hierarchies, Cgroup,
29+
MaxValue, Subsystem,
30+
},
31+
CgroupPid,
2932
};
3033
use containerd_shim_protos::{
3134
cgroups::metrics::{CPUStat, CPUUsage, MemoryEntry, MemoryStat, Metrics, PidsStat, Throttle},
@@ -186,8 +189,8 @@ pub fn collect_metrics(pid: u32) -> Result<Metrics> {
186189
pid_stats.set_limit(
187190
ignore_err(pid_ctr.get_pid_max().map(|val| match val {
188191
// See https://github.com/opencontainers/runc/blob/dbe8434359ca35af1c1e10df42b1f4391c1e1010/libcontainer/cgroups/fs/pids.go#L55
189-
cgroups_rs::MaxValue::Max => 0,
190-
cgroups_rs::MaxValue::Value(val) => val as u64,
192+
MaxValue::Max => 0,
193+
MaxValue::Value(val) => val as u64,
191194
}))
192195
.map_err(other_error!("get pid limit"))?,
193196
);
@@ -354,7 +357,10 @@ pub fn update_resources(pid: u32, resources: &LinuxResources) -> Result<()> {
354357
mod tests {
355358
use std::path::PathBuf;
356359

357-
use cgroups_rs::{hierarchies, Cgroup, CgroupPid};
360+
use cgroups_rs::{
361+
fs::{hierarchies, Cgroup},
362+
CgroupPid,
363+
};
358364

359365
use super::parse_cgroups_v2_path;
360366
use crate::cgroup::{

0 commit comments

Comments
 (0)