mirror of
https://github.com/kata-containers/cgroups-rs.git
synced 2026-08-05 02:13:23 +00:00
Remove Box wrap of Cgroup.hire
It's unnecessary. Signed-off-by: Tim Zhang <tim@hyper.sh>
This commit is contained in:
@@ -33,7 +33,7 @@ pub struct Cgroup<'b> {
|
||||
subsystems: Vec<Subsystem>,
|
||||
|
||||
/// The hierarchy.
|
||||
hier: Box<&'b dyn Hierarchy>,
|
||||
hier: &'b dyn Hierarchy,
|
||||
path: String,
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ impl<'b> Cgroup<'b> {
|
||||
///
|
||||
/// Note that if the handle goes out of scope and is dropped, the control group is _not_
|
||||
/// destroyed.
|
||||
pub fn new<P: AsRef<Path>>(hier: Box<&'b dyn Hierarchy>, path: P) -> Cgroup<'b> {
|
||||
pub fn new<P: AsRef<Path>>(hier: &dyn Hierarchy, path: P) -> Cgroup {
|
||||
let cg = Cgroup::load(hier, path);
|
||||
cg.create();
|
||||
cg
|
||||
@@ -72,10 +72,10 @@ impl<'b> Cgroup<'b> {
|
||||
/// Note that if the handle goes out of scope and is dropped, the control group is _not_
|
||||
/// destroyed.
|
||||
pub fn new_with_relative_paths<P: AsRef<Path>>(
|
||||
hier: Box<&'b dyn Hierarchy>,
|
||||
hier: &dyn Hierarchy,
|
||||
path: P,
|
||||
relative_paths: HashMap<String, String>,
|
||||
) -> Cgroup<'b> {
|
||||
) -> Cgroup {
|
||||
let cg = Cgroup::load_with_relative_paths(hier, path, relative_paths);
|
||||
cg.create();
|
||||
cg
|
||||
@@ -88,7 +88,7 @@ impl<'b> Cgroup<'b> {
|
||||
///
|
||||
/// Note that if the handle goes out of scope and is dropped, the control group is _not_
|
||||
/// destroyed.
|
||||
pub fn load<P: AsRef<Path>>(hier: Box<&'b dyn Hierarchy>, path: P) -> Cgroup {
|
||||
pub fn load<P: AsRef<Path>>(hier: &dyn Hierarchy, path: P) -> Cgroup {
|
||||
let path = path.as_ref();
|
||||
let mut subsystems = hier.subsystems();
|
||||
if path.as_os_str() != "" {
|
||||
@@ -115,10 +115,10 @@ impl<'b> Cgroup<'b> {
|
||||
/// Note that if the handle goes out of scope and is dropped, the control group is _not_
|
||||
/// destroyed.
|
||||
pub fn load_with_relative_paths<P: AsRef<Path>>(
|
||||
hier: Box<&'b dyn Hierarchy>,
|
||||
hier: &dyn Hierarchy,
|
||||
path: P,
|
||||
relative_paths: HashMap<String, String>,
|
||||
) -> Cgroup<'b> {
|
||||
) -> Cgroup {
|
||||
let path = path.as_ref();
|
||||
let mut subsystems = hier.subsystems();
|
||||
if path.as_os_str() != "" {
|
||||
|
||||
@@ -138,7 +138,7 @@ impl<'a> CgroupBuilder<'a> {
|
||||
|
||||
/// Finalize the control group, consuming the builder and creating the control group.
|
||||
pub fn build(self) -> Cgroup<'a> {
|
||||
let cg = Cgroup::new(self.hierarchy, self.name);
|
||||
let cg = Cgroup::new(*self.hierarchy, self.name);
|
||||
let _ret = cg.apply(&self.resources);
|
||||
cg
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ impl Hierarchy for V1 {
|
||||
|
||||
fn root_control_group(&self) -> Cgroup {
|
||||
let b: &dyn Hierarchy = self as &dyn Hierarchy;
|
||||
Cgroup::load(Box::new(&*b), "".to_string())
|
||||
Cgroup::load(&*b, "".to_string())
|
||||
}
|
||||
|
||||
fn check_support(&self, sub: Controllers) -> bool {
|
||||
@@ -186,7 +186,7 @@ impl Hierarchy for V2 {
|
||||
|
||||
fn root_control_group(&self) -> Cgroup {
|
||||
let b: &dyn Hierarchy = self as &dyn Hierarchy;
|
||||
Cgroup::load(Box::new(&*b), "".to_string())
|
||||
Cgroup::load(&*b, "".to_string())
|
||||
}
|
||||
|
||||
fn check_support(&self, _sub: Controllers) -> bool {
|
||||
|
||||
@@ -13,9 +13,8 @@ use std::collections::HashMap;
|
||||
#[test]
|
||||
fn test_tasks_iterator() {
|
||||
let h = cgroups::hierarchies::auto();
|
||||
let h = Box::new(&*h);
|
||||
let pid = libc::pid_t::from(nix::unistd::getpid()) as u64;
|
||||
let cg = Cgroup::new(h, String::from("test_tasks_iterator"));
|
||||
let cg = Cgroup::new(&*h, String::from("test_tasks_iterator"));
|
||||
{
|
||||
// Add a task to the control group.
|
||||
cg.add_task(CgroupPid::from(pid)).unwrap();
|
||||
@@ -45,13 +44,9 @@ fn test_cgroup_with_relative_paths() {
|
||||
}
|
||||
let h = cgroups::hierarchies::auto();
|
||||
let cgroup_root = h.root();
|
||||
let h = Box::new(&*h);
|
||||
let mut relative_paths = HashMap::new();
|
||||
let mem_relative_path = "/mmm/abc/def";
|
||||
relative_paths.insert("memory".to_string(), mem_relative_path.to_string());
|
||||
let cgroup_name = "test_cgroup_with_relative_paths";
|
||||
|
||||
let cg = Cgroup::new_with_relative_paths(h, String::from(cgroup_name), relative_paths);
|
||||
let cg = Cgroup::load(&*h, String::from(cgroup_name));
|
||||
{
|
||||
let subsystems = cg.subsystems();
|
||||
subsystems.into_iter().for_each(|sub| match sub {
|
||||
@@ -74,12 +69,7 @@ fn test_cgroup_with_relative_paths() {
|
||||
// cgroup_path = cgroup_root + relative_path + cgroup_name
|
||||
assert_eq!(
|
||||
cgroup_path,
|
||||
format!(
|
||||
"{}/memory{}/{}",
|
||||
cgroup_root.to_str().unwrap(),
|
||||
mem_relative_path,
|
||||
cgroup_name
|
||||
)
|
||||
format!("{}/memory/{}", cgroup_root.to_str().unwrap(), cgroup_name)
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
@@ -94,8 +84,7 @@ fn test_cgroup_v2() {
|
||||
return;
|
||||
}
|
||||
let h = cgroups::hierarchies::auto();
|
||||
let h = Box::new(&*h);
|
||||
let cg = Cgroup::new_with_relative_paths(h, String::from("test_v2"), HashMap::new());
|
||||
let cg = Cgroup::load(&*h, String::from("test_v2"));
|
||||
|
||||
let mem_controller: &MemController = cg.controller_of().unwrap();
|
||||
let (mem, swp, rev) = (4 * 1024 * 1000, 2 * 1024 * 1000, 1024 * 1000);
|
||||
|
||||
@@ -13,8 +13,7 @@ use std::fs;
|
||||
#[test]
|
||||
fn test_cfs_quota_and_periods() {
|
||||
let h = cgroups::hierarchies::auto();
|
||||
let h = Box::new(&*h);
|
||||
let cg = Cgroup::new(h, String::from("test_cfs_quota_and_periods"));
|
||||
let cg = Cgroup::new(&*h, String::from("test_cfs_quota_and_periods"));
|
||||
|
||||
let cpu_controller: &CpuController = cg.controller_of().unwrap();
|
||||
|
||||
|
||||
@@ -13,8 +13,7 @@ use std::fs;
|
||||
#[test]
|
||||
fn test_cpuset_memory_pressure_root_cg() {
|
||||
let h = cgroups::hierarchies::auto();
|
||||
let h = Box::new(&*h);
|
||||
let cg = Cgroup::new(h, String::from("test_cpuset_memory_pressure_root_cg"));
|
||||
let cg = Cgroup::new(&*h, String::from("test_cpuset_memory_pressure_root_cg"));
|
||||
{
|
||||
let cpuset: &CpuSetController = cg.controller_of().unwrap();
|
||||
|
||||
@@ -28,8 +27,7 @@ fn test_cpuset_memory_pressure_root_cg() {
|
||||
#[test]
|
||||
fn test_cpuset_set_cpus() {
|
||||
let h = cgroups::hierarchies::auto();
|
||||
let h = Box::new(&*h);
|
||||
let cg = Cgroup::new(h, String::from("test_cpuset_set_cpus"));
|
||||
let cg = Cgroup::new(&*h, String::from("test_cpuset_set_cpus"));
|
||||
{
|
||||
let cpuset: &CpuSetController = cg.controller_of().unwrap();
|
||||
|
||||
@@ -67,8 +65,7 @@ fn test_cpuset_set_cpus() {
|
||||
#[test]
|
||||
fn test_cpuset_set_cpus_add_task() {
|
||||
let h = cgroups::hierarchies::auto();
|
||||
let h = Box::new(&*h);
|
||||
let cg = Cgroup::new(h, String::from("test_cpuset_set_cpus_add_task/sub-dir"));
|
||||
let cg = Cgroup::new(&*h, String::from("test_cpuset_set_cpus_add_task/sub-dir"));
|
||||
|
||||
let cpuset: &CpuSetController = cg.controller_of().unwrap();
|
||||
let set = cpuset.cpuset();
|
||||
|
||||
@@ -17,8 +17,7 @@ fn test_devices_parsing() {
|
||||
}
|
||||
|
||||
let h = cgroups::hierarchies::auto();
|
||||
let h = Box::new(&*h);
|
||||
let cg = Cgroup::new(h, String::from("test_devices_parsing"));
|
||||
let cg = Cgroup::new(&*h, String::from("test_devices_parsing"));
|
||||
{
|
||||
let devices: &DevicesController = cg.controller_of().unwrap();
|
||||
|
||||
|
||||
@@ -20,8 +20,7 @@ fn test_hugetlb_sizes() {
|
||||
}
|
||||
|
||||
let h = cgroups::hierarchies::auto();
|
||||
let h = Box::new(&*h);
|
||||
let cg = Cgroup::new(h, String::from("test_hugetlb_sizes"));
|
||||
let cg = Cgroup::new(&*h, String::from("test_hugetlb_sizes"));
|
||||
{
|
||||
let hugetlb_controller: &HugeTlbController = cg.controller_of().unwrap();
|
||||
let sizes = hugetlb_controller.get_sizes();
|
||||
|
||||
@@ -11,8 +11,7 @@ use cgroups::{Cgroup, MaxValue};
|
||||
#[test]
|
||||
fn test_disable_oom_killer() {
|
||||
let h = cgroups::hierarchies::auto();
|
||||
let h = Box::new(&*h);
|
||||
let cg = Cgroup::new(h, String::from("test_disable_oom_killer"));
|
||||
let cg = Cgroup::new(&*h, String::from("test_disable_oom_killer"));
|
||||
{
|
||||
let mem_controller: &MemController = cg.controller_of().unwrap();
|
||||
|
||||
@@ -41,8 +40,7 @@ fn set_mem_v2() {
|
||||
return;
|
||||
}
|
||||
|
||||
let h = Box::new(&*h);
|
||||
let cg = Cgroup::new(h, String::from("set_mem_v2"));
|
||||
let cg = Cgroup::new(&*h, String::from("set_mem_v2"));
|
||||
{
|
||||
let mem_controller: &MemController = cg.controller_of().unwrap();
|
||||
|
||||
|
||||
@@ -19,8 +19,7 @@ use std::thread;
|
||||
#[test]
|
||||
fn create_and_delete_cgroup() {
|
||||
let h = cgroups::hierarchies::auto();
|
||||
let h = Box::new(&*h);
|
||||
let cg = Cgroup::new(h, String::from("create_and_delete_cgroup"));
|
||||
let cg = Cgroup::new(&*h, String::from("create_and_delete_cgroup"));
|
||||
{
|
||||
let pidcontroller: &PidController = cg.controller_of().unwrap();
|
||||
pidcontroller.set_pid_max(MaxValue::Value(1337));
|
||||
@@ -34,8 +33,7 @@ fn create_and_delete_cgroup() {
|
||||
#[test]
|
||||
fn test_pids_current_is_zero() {
|
||||
let h = cgroups::hierarchies::auto();
|
||||
let h = Box::new(&*h);
|
||||
let cg = Cgroup::new(h, String::from("test_pids_current_is_zero"));
|
||||
let cg = Cgroup::new(&*h, String::from("test_pids_current_is_zero"));
|
||||
{
|
||||
let pidcontroller: &PidController = cg.controller_of().unwrap();
|
||||
let current = pidcontroller.get_pid_current();
|
||||
@@ -47,8 +45,7 @@ fn test_pids_current_is_zero() {
|
||||
#[test]
|
||||
fn test_pids_events_is_zero() {
|
||||
let h = cgroups::hierarchies::auto();
|
||||
let h = Box::new(&*h);
|
||||
let cg = Cgroup::new(h, String::from("test_pids_events_is_zero"));
|
||||
let cg = Cgroup::new(&*h, String::from("test_pids_events_is_zero"));
|
||||
{
|
||||
let pidcontroller: &PidController = cg.controller_of().unwrap();
|
||||
let events = pidcontroller.get_pid_events();
|
||||
@@ -61,8 +58,7 @@ fn test_pids_events_is_zero() {
|
||||
#[test]
|
||||
fn test_pid_events_is_not_zero() {
|
||||
let h = cgroups::hierarchies::auto();
|
||||
let h = Box::new(&*h);
|
||||
let cg = Cgroup::new(h, String::from("test_pid_events_is_not_zero"));
|
||||
let cg = Cgroup::new(&*h, String::from("test_pid_events_is_not_zero"));
|
||||
{
|
||||
let pids: &PidController = cg.controller_of().unwrap();
|
||||
let before = pids.get_pid_events();
|
||||
|
||||
@@ -11,8 +11,7 @@ use cgroups::{Cgroup, Hierarchy, MaxValue, PidResources, Resources};
|
||||
#[test]
|
||||
fn pid_resources() {
|
||||
let h = cgroups::hierarchies::auto();
|
||||
let h = Box::new(&*h);
|
||||
let cg = Cgroup::new(h, String::from("pid_resources"));
|
||||
let cg = Cgroup::new(&*h, String::from("pid_resources"));
|
||||
{
|
||||
let res = Resources {
|
||||
pid: PidResources {
|
||||
|
||||
Reference in New Issue
Block a user