mirror of
https://github.com/kata-containers/cgroups-rs.git
synced 2026-08-05 02:13:23 +00:00
manager: Introduce FsManager
`Manager` is a trait to unify the interface of cgroups. It is designed for OCI containers. Its `set()` takes Linux resources of the OCI spec to set cgroups. The `FsManager`, the concrete implementation of `Manager`, manipulates cgroups through cgroupfs, and supports both cgroups v1 and v2. Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
This commit is contained in:
@@ -13,8 +13,8 @@ use std::path::PathBuf;
|
||||
|
||||
use crate::fs::error::ErrorKind::*;
|
||||
use crate::fs::error::*;
|
||||
|
||||
use crate::fs::{ControllIdentifier, ControllerInternal, Controllers, Resources, Subsystem};
|
||||
use crate::FreezerState;
|
||||
|
||||
/// A controller that allows controlling the `freezer` subsystem of a Cgroup.
|
||||
///
|
||||
@@ -31,17 +31,6 @@ pub struct FreezerController {
|
||||
v2: bool,
|
||||
}
|
||||
|
||||
/// The current state of the control group
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
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,
|
||||
}
|
||||
|
||||
impl ControllerInternal for FreezerController {
|
||||
fn control_type(&self) -> Controllers {
|
||||
Controllers::Freezer
|
||||
|
||||
@@ -245,6 +245,7 @@ mod sealed {
|
||||
}
|
||||
|
||||
pub(crate) use crate::fs::sealed::{ControllerInternal, CustomizedAttribute};
|
||||
use crate::CgroupPid;
|
||||
|
||||
/// A Controller is a subsystem attached to the control group.
|
||||
///
|
||||
@@ -771,26 +772,6 @@ pub struct Resources {
|
||||
pub blkio: BlkIoResources,
|
||||
}
|
||||
|
||||
/// A structure representing a `pid`. Currently implementations exist for `u64` and
|
||||
/// `std::process::Child`.
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct CgroupPid {
|
||||
/// The process identifier
|
||||
pub pid: u64,
|
||||
}
|
||||
|
||||
impl From<u64> for CgroupPid {
|
||||
fn from(u: u64) -> CgroupPid {
|
||||
CgroupPid { pid: u }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&std::process::Child> for CgroupPid {
|
||||
fn from(u: &std::process::Child) -> CgroupPid {
|
||||
CgroupPid { pid: u.id() as u64 }
|
||||
}
|
||||
}
|
||||
|
||||
impl Subsystem {
|
||||
fn enter(self, path: &Path) -> Self {
|
||||
match self {
|
||||
|
||||
Reference in New Issue
Block a user