More documentation!

Signed-off-by: Levente Kurusa <lkurusa@acm.org>
This commit is contained in:
Levente Kurusa
2018-08-29 18:39:57 +02:00
parent 6ef19363be
commit caa9241285
11 changed files with 327 additions and 18 deletions
+21 -1
View File
@@ -1,18 +1,33 @@
/* Freezer controller */
//! This module contains the implementation of the `freezer` cgroup subsystem.
//!
//! See the Kernel's documentation for more information about this subsystem, found at:
//! [Documentation/cgroup-v1/freezer-subsystem.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/freezer-subsystem.txt)
use std::path::PathBuf;
use std::io::{Read, Write};
use {Controllers, Controller, Resources, ControllIdentifier, Subsystem};
/// A controller that allows controlling the `freezer` subsystem of a Cgroup.
///
/// In essence, this subsystem allows the user to freeze and thaw (== "un-freeze") the processes in
/// the control group. This is done _transparently_ so that neither the parent, nor the children of
/// the processes can observe the freeze.
///
/// Note that if the control group is currently in the `Frozen` or `Freezing` state, then no
/// processes can be added to it.
#[derive(Debug, Clone)]
pub struct FreezerController{
base: PathBuf,
path: PathBuf,
}
/// The current state of the control group
pub enum FreezerState {
/// The processes in the control group are _not_ frozen.
Thawed,
/// The processes in the control group are in the processes of being frozen.
Freezing,
/// The processes in the control group are frozen.
Frozen,
}
@@ -47,6 +62,7 @@ impl<'a> From<&'a Subsystem> for &'a FreezerController {
}
impl FreezerController {
/// Contructs a new `FreezerController` with `oroot` serving as the root of the control group.
pub fn new(oroot: PathBuf) -> Self {
let mut root = oroot;
root.push(Self::controller_type().to_string());
@@ -55,18 +71,22 @@ impl FreezerController {
path: root,
}
}
/// Freezes the processes in the control group.
pub fn freeze(self: &Self) {
self.open_path("freezer.state", true).and_then(|mut file| {
file.write_all("FROZEN".to_string().as_ref()).ok()
});
}
/// Thaws, that is, unfreezes the processes in the control group.
pub fn thaw(self: &Self) {
self.open_path("freezer.state", true).and_then(|mut file| {
file.write_all("THAWED".to_string().as_ref()).ok()
});
}
/// Retrieve the state of processes in the control group.
pub fn state(self: &Self) -> FreezerState {
self.open_path("freezer.state", false).and_then(|mut file| {
let mut s = String::new();