mirror of
https://github.com/mii443/izoli.git
synced 2025-08-22 16:05:40 +00:00
add get_controllers
This commit is contained in:
@ -5,5 +5,6 @@ fn main() {
|
|||||||
let cgroup = CGroup::new("test").unwrap();
|
let cgroup = CGroup::new("test").unwrap();
|
||||||
println!("{:?}", cgroup.get_root_path());
|
println!("{:?}", cgroup.get_root_path());
|
||||||
println!("{}", cgroup.check_status());
|
println!("{}", cgroup.check_status());
|
||||||
println!("{:?}", cgroup.read("cgroup.controllers"));
|
println!("{:?}", cgroup.read("cgroup.type"));
|
||||||
|
println!("{:?}", cgroup.get_controllers());
|
||||||
}
|
}
|
||||||
|
@ -2,18 +2,10 @@ use std::{
|
|||||||
fs::{self, File},
|
fs::{self, File},
|
||||||
io::Read,
|
io::Read,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
str::FromStr,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub enum Controller {
|
use super::controller::Controller;
|
||||||
Cpu,
|
|
||||||
Cpuset,
|
|
||||||
Memory,
|
|
||||||
Io,
|
|
||||||
Hugetlb,
|
|
||||||
Misc,
|
|
||||||
Pids,
|
|
||||||
Rdma,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct CGroup {
|
pub struct CGroup {
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
@ -63,4 +55,15 @@ impl CGroup {
|
|||||||
|
|
||||||
cgroup_root.join(&self.path)
|
cgroup_root.join(&self.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_controllers(&self) -> Result<Vec<Controller>, std::io::Error> {
|
||||||
|
let controllers = self
|
||||||
|
.read("cgroup.controllers")?
|
||||||
|
.trim()
|
||||||
|
.split(" ")
|
||||||
|
.map(|controller| Controller::from_str(controller).unwrap_or(Controller::Unknown))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
Ok(controllers)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +1,2 @@
|
|||||||
pub mod cgroup;
|
pub mod cgroup;
|
||||||
|
pub mod controller;
|
||||||
|
Reference in New Issue
Block a user