mirror of
https://github.com/containers/youki
synced 2024-11-23 01:11:58 +01:00
Merge pull request #2525 from xiaoyang-sde/libcgroups-docs
docs(libcgroup): add docs for several items in 'libcgroup::v2'
This commit is contained in:
commit
c7567ab42a
@ -75,6 +75,9 @@ pub enum V2ManagerError {
|
||||
IoStats(#[from] V2IoStatsError),
|
||||
}
|
||||
|
||||
/// Represents a management interface for a cgroup located at `{root_path}/{cgroup_path}`
|
||||
///
|
||||
/// This struct does not have ownership of the cgroup
|
||||
pub struct Manager {
|
||||
root_path: PathBuf,
|
||||
cgroup_path: PathBuf,
|
||||
@ -94,10 +97,11 @@ impl Manager {
|
||||
})
|
||||
}
|
||||
|
||||
/// Creates a unified cgroup at `self.full_path` and attaches a process to it
|
||||
fn create_unified_cgroup(&self, pid: Pid) -> Result<(), V2ManagerError> {
|
||||
let controllers: Vec<String> = util::get_available_controllers(&self.root_path)?
|
||||
.iter()
|
||||
.map(|c| format!("{}{}", "+", c))
|
||||
.map(|c| format!("+{c}"))
|
||||
.collect();
|
||||
|
||||
Self::write_controllers(&self.root_path, &controllers)?;
|
||||
@ -129,6 +133,7 @@ impl Manager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Writes a list of controllers to the `{path}/cgroup.subtree_control` file
|
||||
fn write_controllers(path: &Path, controllers: &[String]) -> Result<(), WrappedIoError> {
|
||||
for controller in controllers {
|
||||
common::write_cgroup_file_str(path.join(CGROUP_SUBTREE_CONTROL), controller)?;
|
||||
|
@ -21,6 +21,7 @@ pub enum V2UtilError {
|
||||
DoesNotExist(PathBuf),
|
||||
}
|
||||
|
||||
// Reads the `/proc/self/mountinfo` to get the mount point of this cgroup
|
||||
pub fn get_unified_mount_point() -> Result<PathBuf, V2UtilError> {
|
||||
Process::myself()?
|
||||
.mountinfo()?
|
||||
@ -30,6 +31,8 @@ pub fn get_unified_mount_point() -> Result<PathBuf, V2UtilError> {
|
||||
.ok_or(V2UtilError::CouldNotFind)
|
||||
}
|
||||
|
||||
/// Reads the `{root_path}/cgroup.controllers` file to get the list of the controllers that are
|
||||
/// available in this cgroup
|
||||
pub fn get_available_controllers<P: AsRef<Path>>(
|
||||
root_path: P,
|
||||
) -> Result<Vec<ControllerType>, V2UtilError> {
|
||||
|
Loading…
Reference in New Issue
Block a user