mirror of
https://github.com/kata-containers/cgroups-rs.git
synced 2026-08-05 02:13:23 +00:00
Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b4df6016b3 | ||
|
|
0686400268 | ||
|
|
6986c49e70 | ||
|
|
e0bf36ae23 | ||
|
|
2c68f36488 | ||
|
|
0bc1b9821b | ||
|
|
da75ba25d6 | ||
|
|
01475ad515 | ||
|
|
417badd05f | ||
|
|
1720443d58 | ||
|
|
fb55383273 | ||
|
|
0233c1e046 | ||
|
|
bf5af7b195 | ||
|
|
2e3719dbd5 | ||
|
|
4231f35a44 | ||
|
|
88b7aafd05 | ||
|
|
63750887c2 | ||
|
|
09499e7614 | ||
|
|
bcb7c6cd54 | ||
|
|
2554aa65d0 | ||
|
|
34f935be89 | ||
|
|
5485d8dd46 | ||
|
|
ec4cda1dd9 | ||
|
|
4b5a190ecc | ||
|
|
45b626e0c0 | ||
|
|
0e2430fde1 | ||
|
|
5aa7e6c90e | ||
|
|
5bb27a2692 | ||
|
|
0b2a0405e2 | ||
|
|
c4850ef2ef | ||
|
|
aa207edca8 |
1
.clippy.toml
Normal file
1
.clippy.toml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
upper-case-acronyms-aggressive = true
|
||||||
12
.github/workflows/bvt.yaml
vendored
12
.github/workflows/bvt.yaml
vendored
@@ -1,20 +1,22 @@
|
|||||||
name: BVT
|
name: BVT
|
||||||
on: [pull_request]
|
on: [pull_request]
|
||||||
|
env:
|
||||||
|
RUST_VERSION: 1.52
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
name: Build
|
name: Build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- uses: actions/checkout@v2
|
||||||
uses: actions/checkout@v2
|
- run: rustup install ${{ env.RUST_VERSION }} && rustup default ${{ env.RUST_VERSION }}
|
||||||
- name: Build
|
- run: make debug
|
||||||
run: make debug
|
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
name: Format Check
|
name: Format Check
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
- run: rustup install ${{ env.RUST_VERSION }} && rustup default ${{ env.RUST_VERSION }}
|
||||||
- run: rustup component add rustfmt
|
- run: rustup component add rustfmt
|
||||||
- run: make fmt
|
- run: make fmt
|
||||||
clippy:
|
clippy:
|
||||||
@@ -22,6 +24,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
- run: rustup install ${{ env.RUST_VERSION }} && rustup default ${{ env.RUST_VERSION }}
|
||||||
- run: rustup component add clippy
|
- run: rustup component add clippy
|
||||||
- run: make clippy
|
- run: make clippy
|
||||||
test:
|
test:
|
||||||
@@ -29,6 +32,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
- run: rustup install ${{ env.RUST_VERSION }} && rustup default ${{ env.RUST_VERSION }}
|
||||||
- run: make test
|
- run: make test
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2
.github/workflows/commit-message-check.yaml
vendored
2
.github/workflows/commit-message-check.yaml
vendored
@@ -48,6 +48,6 @@ jobs:
|
|||||||
uses: tim-actions/commit-message-checker-with-regex@v0.3.1
|
uses: tim-actions/commit-message-checker-with-regex@v0.3.1
|
||||||
with:
|
with:
|
||||||
commits: ${{ steps.get-pr-commits.outputs.commits }}
|
commits: ${{ steps.get-pr-commits.outputs.commits }}
|
||||||
pattern: '^.+(\n.{0,72})*$|^.+\n\s*[^a-zA-Z\s\n]|^.+\n\S+$'
|
pattern: '^.+(\n([a-zA-Z].{0,149}|[^a-zA-Z\n].*|Signed-off-by:.*|))+$'
|
||||||
error: 'Body line too long (max 72)'
|
error: 'Body line too long (max 72)'
|
||||||
post_error: ${{ env.error_msg }}
|
post_error: ${{ env.error_msg }}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ repository = "https://github.com/kata-containers/cgroups-rs"
|
|||||||
keywords = ["linux", "cgroup", "containers", "isolation"]
|
keywords = ["linux", "cgroup", "containers", "isolation"]
|
||||||
categories = ["os", "api-bindings", "os::unix-apis"]
|
categories = ["os", "api-bindings", "os::unix-apis"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
version = "0.2.4"
|
version = "0.2.8"
|
||||||
authors = ["The Kata Containers community <kata-dev@lists.katacontainers.io>", "Levente Kurusa <lkurusa@acm.org>", "Sam Wilson <tecywiz121@hotmail.com>"]
|
authors = ["The Kata Containers community <kata-dev@lists.katacontainers.io>", "Levente Kurusa <lkurusa@acm.org>", "Sam Wilson <tecywiz121@hotmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
homepage = "https://github.com/kata-containers/cgroups-rs"
|
homepage = "https://github.com/kata-containers/cgroups-rs"
|
||||||
@@ -14,8 +14,12 @@ readme = "README.md"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
regex = "1.1"
|
regex = "1.1"
|
||||||
nix = "0.20.0"
|
nix = "0.23.0"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
|
serde = { version = "1.0", features = ["derive"], optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
libc = "0.2.76"
|
libc = "0.2.76"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ pub struct BlkIoController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Debug)]
|
#[derive(Eq, PartialEq, Debug)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
/// Per-device information
|
/// Per-device information
|
||||||
pub struct BlkIoData {
|
pub struct BlkIoData {
|
||||||
/// The major number of the device.
|
/// The major number of the device.
|
||||||
@@ -42,6 +43,7 @@ pub struct BlkIoData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Debug)]
|
#[derive(Eq, PartialEq, Debug)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
/// Per-device activity from the control group.
|
/// Per-device activity from the control group.
|
||||||
pub struct IoService {
|
pub struct IoService {
|
||||||
/// The major number of the device.
|
/// The major number of the device.
|
||||||
@@ -61,6 +63,7 @@ pub struct IoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Debug)]
|
#[derive(Eq, PartialEq, Debug)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
/// Per-device activity from the control group.
|
/// Per-device activity from the control group.
|
||||||
/// Only for cgroup v2
|
/// Only for cgroup v2
|
||||||
pub struct IoStat {
|
pub struct IoStat {
|
||||||
@@ -203,6 +206,7 @@ fn parse_blkio_data(s: String) -> Result<Vec<BlkIoData>> {
|
|||||||
/// Current state and statistics about how throttled are the block devices when accessed from the
|
/// Current state and statistics about how throttled are the block devices when accessed from the
|
||||||
/// controller's control group.
|
/// controller's control group.
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct BlkIoThrottle {
|
pub struct BlkIoThrottle {
|
||||||
/// Statistics about the bytes transferred between the block devices by the tasks in this
|
/// Statistics about the bytes transferred between the block devices by the tasks in this
|
||||||
/// control group.
|
/// control group.
|
||||||
@@ -238,6 +242,7 @@ pub struct BlkIoThrottle {
|
|||||||
|
|
||||||
/// Statistics and state of the block devices.
|
/// Statistics and state of the block devices.
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct BlkIo {
|
pub struct BlkIo {
|
||||||
/// The number of BIOS requests merged into I/O requests by the control group's tasks.
|
/// The number of BIOS requests merged into I/O requests by the control group's tasks.
|
||||||
pub io_merged: Vec<IoService>,
|
pub io_merged: Vec<IoService>,
|
||||||
|
|||||||
@@ -311,9 +311,8 @@ impl Cgroup {
|
|||||||
|
|
||||||
pub const UNIFIED_MOUNTPOINT: &str = "/sys/fs/cgroup";
|
pub const UNIFIED_MOUNTPOINT: &str = "/sys/fs/cgroup";
|
||||||
|
|
||||||
fn enable_controllers(controllers: &[String], path: &PathBuf) {
|
fn enable_controllers(controllers: &[String], path: &Path) {
|
||||||
let mut f = path.clone();
|
let f = path.join("cgroup.subtree_control");
|
||||||
f.push("cgroup.subtree_control");
|
|
||||||
for c in controllers {
|
for c in controllers {
|
||||||
let body = format!("+{}", c);
|
let body = format!("+{}", c);
|
||||||
let _rest = fs::write(f.as_path(), body.as_bytes());
|
let _rest = fs::write(f.as_path(), body.as_bytes());
|
||||||
|
|||||||
@@ -240,10 +240,10 @@ impl DeviceResourceBuilder {
|
|||||||
access: Vec<crate::devices::DevicePermissions>,
|
access: Vec<crate::devices::DevicePermissions>,
|
||||||
) -> DeviceResourceBuilder {
|
) -> DeviceResourceBuilder {
|
||||||
self.cgroup.resources.devices.devices.push(DeviceResource {
|
self.cgroup.resources.devices.devices.push(DeviceResource {
|
||||||
|
allow,
|
||||||
|
devtype,
|
||||||
major,
|
major,
|
||||||
minor,
|
minor,
|
||||||
devtype,
|
|
||||||
allow,
|
|
||||||
access,
|
access,
|
||||||
});
|
});
|
||||||
self
|
self
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ pub struct CpuController {
|
|||||||
|
|
||||||
/// The current state of the control group and its processes.
|
/// The current state of the control group and its processes.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct Cpu {
|
pub struct Cpu {
|
||||||
/// Reports CPU time statistics.
|
/// Reports CPU time statistics.
|
||||||
///
|
///
|
||||||
@@ -45,7 +46,7 @@ pub struct Cpu {
|
|||||||
|
|
||||||
/// The current state of the control group and its processes.
|
/// The current state of the control group and its processes.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct CFSQuotaAndPeriod {
|
struct CfsQuotaAndPeriod {
|
||||||
quota: MaxValue,
|
quota: MaxValue,
|
||||||
period: u64,
|
period: u64,
|
||||||
}
|
}
|
||||||
@@ -284,7 +285,7 @@ impl CpuController {
|
|||||||
|
|
||||||
impl CustomizedAttribute for CpuController {}
|
impl CustomizedAttribute for CpuController {}
|
||||||
|
|
||||||
fn parse_cfs_quota_and_period(mut file: File) -> Result<CFSQuotaAndPeriod> {
|
fn parse_cfs_quota_and_period(mut file: File) -> Result<CfsQuotaAndPeriod> {
|
||||||
let mut content = String::new();
|
let mut content = String::new();
|
||||||
file.read_to_string(&mut content)
|
file.read_to_string(&mut content)
|
||||||
.map_err(|e| Error::with_cause(ReadFailed, e))?;
|
.map_err(|e| Error::with_cause(ReadFailed, e))?;
|
||||||
@@ -299,5 +300,5 @@ fn parse_cfs_quota_and_period(mut file: File) -> Result<CFSQuotaAndPeriod> {
|
|||||||
.parse::<u64>()
|
.parse::<u64>()
|
||||||
.map_err(|e| Error::with_cause(ParseError, e))?;
|
.map_err(|e| Error::with_cause(ParseError, e))?;
|
||||||
|
|
||||||
Ok(CFSQuotaAndPeriod { quota, period })
|
Ok(CfsQuotaAndPeriod { quota, period })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ pub struct CpuAcctController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Represents the statistics retrieved from the control group.
|
/// Represents the statistics retrieved from the control group.
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct CpuAcct {
|
pub struct CpuAcct {
|
||||||
/// Divides the time used by the tasks into `user` time and `system` time.
|
/// Divides the time used by the tasks into `user` time and `system` time.
|
||||||
pub stat: String,
|
pub stat: String,
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ pub struct CpuSetController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The current state of the `cpuset` controller for this control group.
|
/// The current state of the `cpuset` controller for this control group.
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct CpuSet {
|
pub struct CpuSet {
|
||||||
/// If true, no other control groups can share the CPUs listed in the `cpus` field.
|
/// If true, no other control groups can share the CPUs listed in the `cpus` field.
|
||||||
pub cpu_exclusive: bool,
|
pub cpu_exclusive: bool,
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ pub struct DevicesController {
|
|||||||
|
|
||||||
/// An enum holding the different types of devices that can be manipulated using this controller.
|
/// An enum holding the different types of devices that can be manipulated using this controller.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "serde",
|
||||||
|
derive(serde::Serialize, serde::Deserialize),
|
||||||
|
serde(rename_all = "snake_case")
|
||||||
|
)]
|
||||||
pub enum DeviceType {
|
pub enum DeviceType {
|
||||||
/// The rule applies to all devices.
|
/// The rule applies to all devices.
|
||||||
All,
|
All,
|
||||||
@@ -49,6 +54,7 @@ impl Default for DeviceType {
|
|||||||
|
|
||||||
impl DeviceType {
|
impl DeviceType {
|
||||||
/// Convert a DeviceType into the character that the kernel recognizes.
|
/// Convert a DeviceType into the character that the kernel recognizes.
|
||||||
|
#[allow(clippy::should_implement_trait, clippy::wrong_self_convention)]
|
||||||
pub fn to_char(&self) -> char {
|
pub fn to_char(&self) -> char {
|
||||||
match self {
|
match self {
|
||||||
DeviceType::All => 'a',
|
DeviceType::All => 'a',
|
||||||
@@ -70,6 +76,11 @@ impl DeviceType {
|
|||||||
|
|
||||||
/// An enum with the permissions that can be allowed/denied to the control group.
|
/// An enum with the permissions that can be allowed/denied to the control group.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "serde",
|
||||||
|
derive(serde::Serialize, serde::Deserialize),
|
||||||
|
serde(rename_all = "snake_case")
|
||||||
|
)]
|
||||||
pub enum DevicePermissions {
|
pub enum DevicePermissions {
|
||||||
/// Permission to read from the device.
|
/// Permission to read from the device.
|
||||||
Read,
|
Read,
|
||||||
@@ -82,6 +93,7 @@ pub enum DevicePermissions {
|
|||||||
|
|
||||||
impl DevicePermissions {
|
impl DevicePermissions {
|
||||||
/// Convert a DevicePermissions into the character that the kernel recognizes.
|
/// Convert a DevicePermissions into the character that the kernel recognizes.
|
||||||
|
#[allow(clippy::should_implement_trait, clippy::wrong_self_convention)]
|
||||||
pub fn to_char(&self) -> char {
|
pub fn to_char(&self) -> char {
|
||||||
match self {
|
match self {
|
||||||
DevicePermissions::Read => 'r',
|
DevicePermissions::Read => 'r',
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ impl fmt::Display for Error {
|
|||||||
|
|
||||||
impl StdError for Error {
|
impl StdError for Error {
|
||||||
fn cause(&self) -> Option<&dyn StdError> {
|
fn cause(&self) -> Option<&dyn StdError> {
|
||||||
|
#[allow(clippy::manual_map)]
|
||||||
match self.cause {
|
match self.cause {
|
||||||
Some(ref x) => Some(&**x),
|
Some(ref x) => Some(&**x),
|
||||||
None => None,
|
None => None,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use nix::sys::eventfd;
|
|||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::os::unix::io::{AsRawFd, FromRawFd};
|
use std::os::unix::io::{AsRawFd, FromRawFd};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::Path;
|
||||||
use std::sync::mpsc::{self, Receiver};
|
use std::sync::mpsc::{self, Receiver};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
@@ -17,18 +17,18 @@ use crate::error::*;
|
|||||||
|
|
||||||
// notify_on_oom returns channel on which you can expect event about OOM,
|
// notify_on_oom returns channel on which you can expect event about OOM,
|
||||||
// if process died without OOM this channel will be closed.
|
// if process died without OOM this channel will be closed.
|
||||||
pub fn notify_on_oom_v2(key: &str, dir: &PathBuf) -> Result<Receiver<String>> {
|
pub fn notify_on_oom_v2(key: &str, dir: &Path) -> Result<Receiver<String>> {
|
||||||
register_memory_event(key, dir, "memory.oom_control", "")
|
register_memory_event(key, dir, "memory.oom_control", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// notify_on_oom returns channel on which you can expect event about OOM,
|
// notify_on_oom returns channel on which you can expect event about OOM,
|
||||||
// if process died without OOM this channel will be closed.
|
// if process died without OOM this channel will be closed.
|
||||||
pub fn notify_on_oom_v1(key: &str, dir: &PathBuf) -> Result<Receiver<String>> {
|
pub fn notify_on_oom_v1(key: &str, dir: &Path) -> Result<Receiver<String>> {
|
||||||
register_memory_event(key, dir, "memory.oom_control", "")
|
register_memory_event(key, dir, "memory.oom_control", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// level is one of "low", "medium", or "critical"
|
// level is one of "low", "medium", or "critical"
|
||||||
pub fn notify_memory_pressure(key: &str, dir: &PathBuf, level: &str) -> Result<Receiver<String>> {
|
pub fn notify_memory_pressure(key: &str, dir: &Path, level: &str) -> Result<Receiver<String>> {
|
||||||
if level != "low" && level != "medium" && level != "critical" {
|
if level != "low" && level != "medium" && level != "critical" {
|
||||||
return Err(Error::from_string(format!(
|
return Err(Error::from_string(format!(
|
||||||
"invalid pressure level {}",
|
"invalid pressure level {}",
|
||||||
@@ -41,7 +41,7 @@ pub fn notify_memory_pressure(key: &str, dir: &PathBuf, level: &str) -> Result<R
|
|||||||
|
|
||||||
fn register_memory_event(
|
fn register_memory_event(
|
||||||
key: &str,
|
key: &str,
|
||||||
cg_dir: &PathBuf,
|
cg_dir: &Path,
|
||||||
event_name: &str,
|
event_name: &str,
|
||||||
arg: &str,
|
arg: &str,
|
||||||
) -> Result<Receiver<String>> {
|
) -> Result<Receiver<String>> {
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ pub struct FreezerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The current state of the control group
|
/// The current state of the control group
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub enum FreezerState {
|
pub enum FreezerState {
|
||||||
/// The processes in the control group are _not_ frozen.
|
/// The processes in the control group are _not_ frozen.
|
||||||
Thawed,
|
Thawed,
|
||||||
@@ -130,7 +131,7 @@ impl FreezerController {
|
|||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
let res = file.read_to_string(&mut s);
|
let res = file.read_to_string(&mut s);
|
||||||
match res {
|
match res {
|
||||||
Ok(_) => match s.as_ref() {
|
Ok(_) => match s.trim() {
|
||||||
"FROZEN" => Ok(FreezerState::Frozen),
|
"FROZEN" => Ok(FreezerState::Frozen),
|
||||||
"THAWED" => Ok(FreezerState::Thawed),
|
"THAWED" => Ok(FreezerState::Thawed),
|
||||||
"1" => Ok(FreezerState::Frozen),
|
"1" => Ok(FreezerState::Frozen),
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ use crate::cgroup::Cgroup;
|
|||||||
/// Process mounts information.
|
/// Process mounts information.
|
||||||
///
|
///
|
||||||
/// See `proc(5)` for format details.
|
/// See `proc(5)` for format details.
|
||||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
||||||
pub struct Mountinfo {
|
pub struct Mountinfo {
|
||||||
/// Mount pathname relative to the process's root.
|
/// Mount pathname relative to the process's root.
|
||||||
pub mount_point: PathBuf,
|
pub mount_point: PathBuf,
|
||||||
@@ -87,7 +87,7 @@ fn mountinfo_file(file: &mut File) -> Vec<Mountinfo> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => continue,
|
Err(_) => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
r
|
r
|
||||||
@@ -102,12 +102,12 @@ pub fn mountinfo_self() -> Vec<Mountinfo> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The standard, original cgroup implementation. Often referred to as "cgroupv1".
|
/// The standard, original cgroup implementation. Often referred to as "cgroupv1".
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct V1 {
|
pub struct V1 {
|
||||||
mountinfo: Vec<Mountinfo>,
|
mountinfo: Vec<Mountinfo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct V2 {
|
pub struct V2 {
|
||||||
root: String,
|
root: String,
|
||||||
}
|
}
|
||||||
@@ -202,7 +202,12 @@ impl Hierarchy for V2 {
|
|||||||
let mut subs = vec![];
|
let mut subs = vec![];
|
||||||
|
|
||||||
let controllers = ret.unwrap().trim().to_string();
|
let controllers = ret.unwrap().trim().to_string();
|
||||||
let controller_list: Vec<&str> = controllers.split(' ').collect();
|
let mut controller_list: Vec<&str> = controllers.split(' ').collect();
|
||||||
|
|
||||||
|
// The freezer functionality is present in V2, but not as a controller,
|
||||||
|
// but apparently as a core functionality. FreezerController supports
|
||||||
|
// that, but we must explicitly fake the controller here.
|
||||||
|
controller_list.push("freezer");
|
||||||
|
|
||||||
for s in controller_list {
|
for s in controller_list {
|
||||||
match s {
|
match s {
|
||||||
|
|||||||
35
src/lib.rs
35
src/lib.rs
@@ -366,9 +366,12 @@ where
|
|||||||
let bf = BufReader::new(file);
|
let bf = BufReader::new(file);
|
||||||
let mut v = Vec::new();
|
let mut v = Vec::new();
|
||||||
for line in bf.lines() {
|
for line in bf.lines() {
|
||||||
if let Ok(line) = line {
|
match line {
|
||||||
let n = line.trim().parse().unwrap_or(0u64);
|
Ok(line) => {
|
||||||
v.push(n);
|
let n = line.trim().parse().unwrap_or(0u64);
|
||||||
|
v.push(n);
|
||||||
|
}
|
||||||
|
Err(_) => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v.into_iter().map(CgroupPid::from).collect()
|
v.into_iter().map(CgroupPid::from).collect()
|
||||||
@@ -383,7 +386,7 @@ where
|
|||||||
|
|
||||||
// remove_dir aims to remove cgroup path. It does so recursively,
|
// remove_dir aims to remove cgroup path. It does so recursively,
|
||||||
// by removing any subdirectories (sub-cgroups) first.
|
// by removing any subdirectories (sub-cgroups) first.
|
||||||
fn remove_dir(dir: &PathBuf) -> Result<()> {
|
fn remove_dir(dir: &Path) -> Result<()> {
|
||||||
// try the fast path first.
|
// try the fast path first.
|
||||||
if fs::remove_dir(dir).is_ok() {
|
if fs::remove_dir(dir).is_ok() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -425,6 +428,7 @@ pub trait Hierarchy: std::fmt::Debug + Send + Sync {
|
|||||||
|
|
||||||
/// Resource limits for the memory subsystem.
|
/// Resource limits for the memory subsystem.
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct MemoryResources {
|
pub struct MemoryResources {
|
||||||
/// How much memory (in bytes) can the kernel consume.
|
/// How much memory (in bytes) can the kernel consume.
|
||||||
pub kernel_memory_limit: Option<i64>,
|
pub kernel_memory_limit: Option<i64>,
|
||||||
@@ -448,13 +452,15 @@ pub struct MemoryResources {
|
|||||||
/// # Usage:
|
/// # Usage:
|
||||||
/// ```
|
/// ```
|
||||||
/// let resource = &mut cgroups_rs::Resources::default();
|
/// let resource = &mut cgroups_rs::Resources::default();
|
||||||
/// resource.memory.attrs.insert("memory.numa_balancing", "true".to_string());
|
/// resource.memory.attrs.insert("memory.numa_balancing".to_string(), "true".to_string());
|
||||||
/// // apply here
|
/// // apply here
|
||||||
pub attrs: std::collections::HashMap<&'static str, String>,
|
/// ```
|
||||||
|
pub attrs: HashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resources limits on the number of processes.
|
/// Resources limits on the number of processes.
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct PidResources {
|
pub struct PidResources {
|
||||||
/// The maximum number of processes that can exist in the control group.
|
/// The maximum number of processes that can exist in the control group.
|
||||||
///
|
///
|
||||||
@@ -466,6 +472,7 @@ pub struct PidResources {
|
|||||||
|
|
||||||
/// Resources limits about how the tasks can use the CPU.
|
/// Resources limits about how the tasks can use the CPU.
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct CpuResources {
|
pub struct CpuResources {
|
||||||
// cpuset
|
// cpuset
|
||||||
/// A comma-separated list of CPU IDs where the task in the control group can run. Dashes
|
/// A comma-separated list of CPU IDs where the task in the control group can run. Dashes
|
||||||
@@ -490,14 +497,15 @@ pub struct CpuResources {
|
|||||||
/// # Usage:
|
/// # Usage:
|
||||||
/// ```
|
/// ```
|
||||||
/// let resource = &mut cgroups_rs::Resources::default();
|
/// let resource = &mut cgroups_rs::Resources::default();
|
||||||
/// resource.cpu.attrs.insert("cpu.cfs_init_buffer_us", "10".to_string());
|
/// resource.cpu.attrs.insert("cpu.cfs_init_buffer_us".to_string(), "10".to_string());
|
||||||
/// // apply here
|
/// // apply here
|
||||||
/// ```
|
/// ```
|
||||||
pub attrs: std::collections::HashMap<&'static str, String>,
|
pub attrs: HashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A device resource that can be allowed or denied access to.
|
/// A device resource that can be allowed or denied access to.
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct DeviceResource {
|
pub struct DeviceResource {
|
||||||
/// If true, access to the device is allowed, otherwise it's denied.
|
/// If true, access to the device is allowed, otherwise it's denied.
|
||||||
pub allow: bool,
|
pub allow: bool,
|
||||||
@@ -513,6 +521,7 @@ pub struct DeviceResource {
|
|||||||
|
|
||||||
/// Limit the usage of devices for the control group's tasks.
|
/// Limit the usage of devices for the control group's tasks.
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct DeviceResources {
|
pub struct DeviceResources {
|
||||||
/// For each device in the list, the limits in the structure are applied.
|
/// For each device in the list, the limits in the structure are applied.
|
||||||
pub devices: Vec<DeviceResource>,
|
pub devices: Vec<DeviceResource>,
|
||||||
@@ -520,6 +529,7 @@ pub struct DeviceResources {
|
|||||||
|
|
||||||
/// Assigned priority for a network device.
|
/// Assigned priority for a network device.
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct NetworkPriority {
|
pub struct NetworkPriority {
|
||||||
/// The name (as visible in `ifconfig`) of the interface.
|
/// The name (as visible in `ifconfig`) of the interface.
|
||||||
pub name: String,
|
pub name: String,
|
||||||
@@ -530,6 +540,7 @@ pub struct NetworkPriority {
|
|||||||
/// Collections of limits and tags that can be imposed on packets emitted by the tasks in the
|
/// Collections of limits and tags that can be imposed on packets emitted by the tasks in the
|
||||||
/// control group.
|
/// control group.
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct NetworkResources {
|
pub struct NetworkResources {
|
||||||
/// The networking class identifier to attach to the packets.
|
/// The networking class identifier to attach to the packets.
|
||||||
///
|
///
|
||||||
@@ -541,6 +552,7 @@ pub struct NetworkResources {
|
|||||||
|
|
||||||
/// A hugepage type and its consumption limit for the control group.
|
/// A hugepage type and its consumption limit for the control group.
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct HugePageResource {
|
pub struct HugePageResource {
|
||||||
/// The size of the hugepage, i.e. `2MB`, `1GB`, etc.
|
/// The size of the hugepage, i.e. `2MB`, `1GB`, etc.
|
||||||
pub size: String,
|
pub size: String,
|
||||||
@@ -551,6 +563,7 @@ pub struct HugePageResource {
|
|||||||
|
|
||||||
/// Provides the ability to set consumption limit on each type of hugepages.
|
/// Provides the ability to set consumption limit on each type of hugepages.
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct HugePageResources {
|
pub struct HugePageResources {
|
||||||
/// Set a limit of consumption for each hugepages type.
|
/// Set a limit of consumption for each hugepages type.
|
||||||
pub limits: Vec<HugePageResource>,
|
pub limits: Vec<HugePageResource>,
|
||||||
@@ -558,6 +571,7 @@ pub struct HugePageResources {
|
|||||||
|
|
||||||
/// Weight for a particular block device.
|
/// Weight for a particular block device.
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct BlkIoDeviceResource {
|
pub struct BlkIoDeviceResource {
|
||||||
/// The major number of the device.
|
/// The major number of the device.
|
||||||
pub major: u64,
|
pub major: u64,
|
||||||
@@ -571,6 +585,7 @@ pub struct BlkIoDeviceResource {
|
|||||||
|
|
||||||
/// Provides the ability to throttle a device (both byte/sec, and IO op/s)
|
/// Provides the ability to throttle a device (both byte/sec, and IO op/s)
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct BlkIoDeviceThrottleResource {
|
pub struct BlkIoDeviceThrottleResource {
|
||||||
/// The major number of the device.
|
/// The major number of the device.
|
||||||
pub major: u64,
|
pub major: u64,
|
||||||
@@ -582,6 +597,7 @@ pub struct BlkIoDeviceThrottleResource {
|
|||||||
|
|
||||||
/// General block I/O resource limits.
|
/// General block I/O resource limits.
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct BlkIoResources {
|
pub struct BlkIoResources {
|
||||||
/// The weight of the control group against descendant nodes.
|
/// The weight of the control group against descendant nodes.
|
||||||
pub weight: Option<u16>,
|
pub weight: Option<u16>,
|
||||||
@@ -601,6 +617,7 @@ pub struct BlkIoResources {
|
|||||||
|
|
||||||
/// The resource limits and constraints that will be set on the control group.
|
/// The resource limits and constraints that will be set on the control group.
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct Resources {
|
pub struct Resources {
|
||||||
/// Memory usage related limits.
|
/// Memory usage related limits.
|
||||||
pub memory: MemoryResources,
|
pub memory: MemoryResources,
|
||||||
@@ -726,6 +743,7 @@ impl Subsystem {
|
|||||||
|
|
||||||
/// The values for `memory.hight` or `pids.max`
|
/// The values for `memory.hight` or `pids.max`
|
||||||
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
|
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub enum MaxValue {
|
pub enum MaxValue {
|
||||||
/// This value is returned when the text is `"max"`.
|
/// This value is returned when the text is `"max"`.
|
||||||
Max,
|
Max,
|
||||||
@@ -740,6 +758,7 @@ impl Default for MaxValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MaxValue {
|
impl MaxValue {
|
||||||
|
#[allow(clippy::should_implement_trait, clippy::wrong_self_convention)]
|
||||||
fn to_i64(&self) -> i64 {
|
fn to_i64(&self) -> i64 {
|
||||||
match self {
|
match self {
|
||||||
MaxValue::Max => -1,
|
MaxValue::Max => -1,
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ pub struct MemController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, PartialEq, Eq)]
|
#[derive(Default, Debug, PartialEq, Eq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct SetMemory {
|
pub struct SetMemory {
|
||||||
pub low: Option<MaxValue>,
|
pub low: Option<MaxValue>,
|
||||||
pub high: Option<MaxValue>,
|
pub high: Option<MaxValue>,
|
||||||
@@ -47,6 +48,7 @@ pub struct SetMemory {
|
|||||||
|
|
||||||
/// Controls statistics and controls about the OOM killer operating in this control group.
|
/// Controls statistics and controls about the OOM killer operating in this control group.
|
||||||
#[derive(Default, Debug, PartialEq, Eq)]
|
#[derive(Default, Debug, PartialEq, Eq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct OomControl {
|
pub struct OomControl {
|
||||||
/// If true, the OOM killer has been disabled for the tasks in this control group.
|
/// If true, the OOM killer has been disabled for the tasks in this control group.
|
||||||
pub oom_kill_disable: bool,
|
pub oom_kill_disable: bool,
|
||||||
@@ -87,6 +89,7 @@ fn parse_oom_control(s: String) -> Result<OomControl> {
|
|||||||
|
|
||||||
/// Contains statistics about the NUMA locality of the control group's tasks.
|
/// Contains statistics about the NUMA locality of the control group's tasks.
|
||||||
#[derive(Default, Debug, PartialEq, Eq)]
|
#[derive(Default, Debug, PartialEq, Eq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct NumaStat {
|
pub struct NumaStat {
|
||||||
/// Total amount of pages used by the control group.
|
/// Total amount of pages used by the control group.
|
||||||
pub total_pages: u64,
|
pub total_pages: u64,
|
||||||
@@ -302,6 +305,7 @@ fn parse_numa_stat(s: String) -> Result<NumaStat> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, PartialEq, Eq)]
|
#[derive(Default, Debug, PartialEq, Eq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct MemoryStat {
|
pub struct MemoryStat {
|
||||||
pub cache: u64,
|
pub cache: u64,
|
||||||
pub rss: u64,
|
pub rss: u64,
|
||||||
@@ -403,6 +407,7 @@ fn parse_memory_stat(s: String) -> Result<MemoryStat> {
|
|||||||
/// Contains statistics about the current usage of memory and swap (together, not seperately) by
|
/// Contains statistics about the current usage of memory and swap (together, not seperately) by
|
||||||
/// the control group's tasks.
|
/// the control group's tasks.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct MemSwap {
|
pub struct MemSwap {
|
||||||
/// How many times the limit has been hit.
|
/// How many times the limit has been hit.
|
||||||
pub fail_cnt: u64,
|
pub fail_cnt: u64,
|
||||||
@@ -417,6 +422,7 @@ pub struct MemSwap {
|
|||||||
/// State of and statistics gathered by the kernel about the memory usage of the control group's
|
/// State of and statistics gathered by the kernel about the memory usage of the control group's
|
||||||
/// tasks.
|
/// tasks.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct Memory {
|
pub struct Memory {
|
||||||
/// How many times the limit has been hit.
|
/// How many times the limit has been hit.
|
||||||
pub fail_cnt: u64,
|
pub fail_cnt: u64,
|
||||||
@@ -461,6 +467,7 @@ pub struct Memory {
|
|||||||
/// The current state of and gathered statistics about the kernel's memory usage for TCP-related
|
/// The current state of and gathered statistics about the kernel's memory usage for TCP-related
|
||||||
/// data structures.
|
/// data structures.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct Tcp {
|
pub struct Tcp {
|
||||||
/// How many times the limit has been hit.
|
/// How many times the limit has been hit.
|
||||||
pub fail_cnt: u64,
|
pub fail_cnt: u64,
|
||||||
@@ -479,6 +486,7 @@ pub struct Tcp {
|
|||||||
/// these tasks if it would think that the limits here would be violated. It's important to note
|
/// these tasks if it would think that the limits here would be violated. It's important to note
|
||||||
/// that interrupts in particular might not be able to enforce these limits.
|
/// that interrupts in particular might not be able to enforce these limits.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct Kmem {
|
pub struct Kmem {
|
||||||
/// How many times the limit has been hit.
|
/// How many times the limit has been hit.
|
||||||
pub fail_cnt: u64,
|
pub fail_cnt: u64,
|
||||||
|
|||||||
@@ -36,12 +36,12 @@ fn test_cpuset_set_cpus() {
|
|||||||
assert_eq!(0, set.cpus.len());
|
assert_eq!(0, set.cpus.len());
|
||||||
} else {
|
} else {
|
||||||
// for cgroup v1, cpuset is copied from parent.
|
// for cgroup v1, cpuset is copied from parent.
|
||||||
assert_eq!(true, !set.cpus.is_empty());
|
assert!(!set.cpus.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0
|
// 0
|
||||||
let r = cpuset.set_cpus("0");
|
let r = cpuset.set_cpus("0");
|
||||||
assert_eq!(true, r.is_ok());
|
assert!(r.is_ok());
|
||||||
|
|
||||||
let set = cpuset.cpuset();
|
let set = cpuset.cpuset();
|
||||||
assert_eq!(1, set.cpus.len());
|
assert_eq!(1, set.cpus.len());
|
||||||
@@ -51,8 +51,8 @@ fn test_cpuset_set_cpus() {
|
|||||||
let cpus = fs::read_to_string("/sys/fs/cgroup/cpuset.cpus.effective").unwrap_or_default();
|
let cpus = fs::read_to_string("/sys/fs/cgroup/cpuset.cpus.effective").unwrap_or_default();
|
||||||
let cpus = cpus.trim();
|
let cpus = cpus.trim();
|
||||||
if !cpus.is_empty() {
|
if !cpus.is_empty() {
|
||||||
let r = cpuset.set_cpus(&cpus);
|
let r = cpuset.set_cpus(cpus);
|
||||||
assert_eq!(true, r.is_ok());
|
assert!(r.is_ok());
|
||||||
let set = cpuset.cpuset();
|
let set = cpuset.cpuset();
|
||||||
assert_eq!(1, set.cpus.len());
|
assert_eq!(1, set.cpus.len());
|
||||||
assert_eq!(format!("{}-{}", set.cpus[0].0, set.cpus[0].1), cpus);
|
assert_eq!(format!("{}-{}", set.cpus[0].0, set.cpus[0].1), cpus);
|
||||||
@@ -72,14 +72,14 @@ fn test_cpuset_set_cpus_add_task() {
|
|||||||
assert_eq!(0, set.cpus.len());
|
assert_eq!(0, set.cpus.len());
|
||||||
} else {
|
} else {
|
||||||
// for cgroup v1, cpuset is copied from parent.
|
// for cgroup v1, cpuset is copied from parent.
|
||||||
assert_eq!(true, !set.cpus.is_empty());
|
assert!(!set.cpus.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a task to the control group.
|
// Add a task to the control group.
|
||||||
let pid_i = libc::pid_t::from(nix::unistd::getpid()) as u64;
|
let pid_i = libc::pid_t::from(nix::unistd::getpid()) as u64;
|
||||||
let _ = cg.add_task(CgroupPid::from(pid_i));
|
let _ = cg.add_task(CgroupPid::from(pid_i));
|
||||||
let tasks = cg.tasks();
|
let tasks = cg.tasks();
|
||||||
assert_eq!(true, !tasks.is_empty());
|
assert!(!tasks.is_empty());
|
||||||
println!("tasks after added: {:?}", tasks);
|
println!("tasks after added: {:?}", tasks);
|
||||||
|
|
||||||
// remove task
|
// remove task
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ fn test_hugetlb_sizes() {
|
|||||||
|
|
||||||
for size in sizes {
|
for size in sizes {
|
||||||
let supported = hugetlb_controller.size_supported(&size);
|
let supported = hugetlb_controller.size_supported(&size);
|
||||||
assert_eq!(supported, true);
|
assert!(supported);
|
||||||
assert_no_error(hugetlb_controller.failcnt(&size));
|
assert_no_error(hugetlb_controller.failcnt(&size));
|
||||||
assert_no_error(hugetlb_controller.limit_in_bytes(&size));
|
assert_no_error(hugetlb_controller.limit_in_bytes(&size));
|
||||||
assert_no_error(hugetlb_controller.usage_in_bytes(&size));
|
assert_no_error(hugetlb_controller.usage_in_bytes(&size));
|
||||||
@@ -40,5 +40,5 @@ fn test_hugetlb_sizes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn assert_no_error(r: Result<u64>) {
|
fn assert_no_error(r: Result<u64>) {
|
||||||
assert_eq!(!r.is_err(), true)
|
assert!(!r.is_err())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,17 +17,17 @@ fn test_disable_oom_killer() {
|
|||||||
|
|
||||||
// before disable
|
// before disable
|
||||||
let m = mem_controller.memory_stat();
|
let m = mem_controller.memory_stat();
|
||||||
assert_eq!(m.oom_control.oom_kill_disable, false);
|
assert!(!m.oom_control.oom_kill_disable);
|
||||||
|
|
||||||
// now only v1
|
// now only v1
|
||||||
if !mem_controller.v2() {
|
if !mem_controller.v2() {
|
||||||
// disable oom killer
|
// disable oom killer
|
||||||
let r = mem_controller.disable_oom_killer();
|
let r = mem_controller.disable_oom_killer();
|
||||||
assert_eq!(r.is_err(), false);
|
assert!(!r.is_err());
|
||||||
|
|
||||||
// after disable
|
// after disable
|
||||||
let m = mem_controller.memory_stat();
|
let m = mem_controller.memory_stat();
|
||||||
assert_eq!(m.oom_control.oom_kill_disable, true);
|
assert!(m.oom_control.oom_kill_disable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cg.delete().unwrap();
|
cg.delete().unwrap();
|
||||||
@@ -60,7 +60,7 @@ fn set_mem_v2() {
|
|||||||
max: None,
|
max: None,
|
||||||
};
|
};
|
||||||
let r = mem_controller.set_mem(m);
|
let r = mem_controller.set_mem(m);
|
||||||
assert_eq!(true, r.is_ok());
|
assert!(r.is_ok());
|
||||||
|
|
||||||
let m = mem_controller.get_mem().unwrap();
|
let m = mem_controller.get_mem().unwrap();
|
||||||
// get
|
// get
|
||||||
@@ -77,7 +77,7 @@ fn set_mem_v2() {
|
|||||||
low: None,
|
low: None,
|
||||||
};
|
};
|
||||||
let r = mem_controller.set_mem(m);
|
let r = mem_controller.set_mem(m);
|
||||||
assert_eq!(true, r.is_ok());
|
assert!(r.is_ok());
|
||||||
|
|
||||||
let m = mem_controller.get_mem().unwrap();
|
let m = mem_controller.get_mem().unwrap();
|
||||||
// get
|
// get
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ fn pid_resources() {
|
|||||||
// verify
|
// verify
|
||||||
let pidcontroller: &PidController = cg.controller_of().unwrap();
|
let pidcontroller: &PidController = cg.controller_of().unwrap();
|
||||||
let pid_max = pidcontroller.get_pid_max();
|
let pid_max = pidcontroller.get_pid_max();
|
||||||
assert_eq!(pid_max.is_ok(), true);
|
assert!(pid_max.is_ok());
|
||||||
assert_eq!(pid_max.unwrap(), MaxValue::Value(512));
|
assert_eq!(pid_max.unwrap(), MaxValue::Value(512));
|
||||||
}
|
}
|
||||||
cg.delete().unwrap();
|
cg.delete().unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user