From 1ce94d237a8ae5b61e18882edba846316e36fdb0 Mon Sep 17 00:00:00 2001 From: Xiaoyang Liu Date: Sat, 11 Nov 2023 23:02:11 -0800 Subject: [PATCH] docs(libcgroup): add docs for several items in 'libcgroup::v2' Signed-off-by: Xiaoyang Liu --- crates/libcgroups/src/v2/manager.rs | 7 ++++++- crates/libcgroups/src/v2/util.rs | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/libcgroups/src/v2/manager.rs b/crates/libcgroups/src/v2/manager.rs index 9aa5b8d5..d6e354a9 100644 --- a/crates/libcgroups/src/v2/manager.rs +++ b/crates/libcgroups/src/v2/manager.rs @@ -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 = 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)?; diff --git a/crates/libcgroups/src/v2/util.rs b/crates/libcgroups/src/v2/util.rs index 57746bc3..8971fe98 100644 --- a/crates/libcgroups/src/v2/util.rs +++ b/crates/libcgroups/src/v2/util.rs @@ -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 { Process::myself()? .mountinfo()? @@ -30,6 +31,8 @@ pub fn get_unified_mount_point() -> Result { .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>( root_path: P, ) -> Result, V2UtilError> {