mirror of
https://github.com/kata-containers/cgroups-rs.git
synced 2026-08-05 02:13:23 +00:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
87f05873f0 | ||
|
|
79868d6bfc | ||
|
|
d1d78fe943 | ||
|
|
81d286f31d | ||
|
|
5e538ae286 | ||
|
|
cd5645bb14 | ||
|
|
4a2042068e | ||
|
|
9ac2f5d5ab | ||
|
|
a58cd1d553 | ||
|
|
88a45d4922 | ||
|
|
0c58b5dd84 | ||
|
|
8448548cb3 | ||
|
|
d50245e116 | ||
|
|
bbdfa88596 | ||
|
|
853ed46993 | ||
|
|
15b65c5e5e | ||
|
|
87f8ac7f0d | ||
|
|
225388ff7c | ||
|
|
f0a695cc00 | ||
|
|
50d3c398a0 | ||
|
|
033fa4b857 | ||
|
|
ac4e6eda66 | ||
|
|
35ecd6fd77 | ||
|
|
eb6577e3e0 |
17
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
17
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ''
|
||||||
|
labels: 'bug, needs-review'
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**Expected behavior**
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
||||||
20
.github/ISSUE_TEMPLATE/enhancement-request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/enhancement-request.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
name: Enhancement request
|
||||||
|
about: Suggest an improvement to an existing feature
|
||||||
|
title: ''
|
||||||
|
labels: enhancement, needs-review
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Which feature do you think can be improved?**
|
||||||
|
|
||||||
|
Specify the feature you think could be made better.
|
||||||
|
|
||||||
|
**How can it be improved?**
|
||||||
|
|
||||||
|
Describe how specifically you think it could be improved.
|
||||||
|
|
||||||
|
**Additional Information**
|
||||||
|
|
||||||
|
Anything else to add?
|
||||||
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this project
|
||||||
|
title: ''
|
||||||
|
labels: 'feature, needs-review'
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context or screenshots about the feature request here.
|
||||||
26
.github/workflows/bvt.yaml
vendored
Normal file
26
.github/workflows/bvt.yaml
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
name: BVT
|
||||||
|
on: [pull_request]
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Build
|
||||||
|
run: make debug
|
||||||
|
|
||||||
|
fmt:
|
||||||
|
name: Format Check
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- run: rustup component add rustfmt
|
||||||
|
- run: make fmt
|
||||||
|
test:
|
||||||
|
name: Run Unit Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- run: make test
|
||||||
|
|
||||||
31
.travis.yml
31
.travis.yml
@@ -1,31 +0,0 @@
|
|||||||
# Copyright (c) 2018 Levente Kurusa
|
|
||||||
# Copyright (c) 2020 Ant Group
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
|
||||||
#
|
|
||||||
|
|
||||||
dist: bionic
|
|
||||||
os: linux
|
|
||||||
language: rust
|
|
||||||
cache: cargo
|
|
||||||
|
|
||||||
arch:
|
|
||||||
- amd64
|
|
||||||
- arm64
|
|
||||||
|
|
||||||
install:
|
|
||||||
- rustup component add rustfmt
|
|
||||||
|
|
||||||
script:
|
|
||||||
- RUSTFLAGS="--deny warnings" cargo build
|
|
||||||
- if [ "$TRAVIS_CPU_ARCH" == "amd64" ]; then cargo test -- --color always --nocapture ; fi
|
|
||||||
- cargo fmt -- --check
|
|
||||||
|
|
||||||
rust:
|
|
||||||
- 1.44.1
|
|
||||||
- nightly
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
allow_failures:
|
|
||||||
- rust: nightly
|
|
||||||
fast_finish: true
|
|
||||||
11
Cargo.toml
11
Cargo.toml
@@ -1,20 +1,21 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cgroups"
|
name = "cgroups-rs"
|
||||||
description = "Native Rust crate for managing control groups on Linux"
|
description = "Native Rust crate for managing control groups on Linux"
|
||||||
repository = "https://github.com/levex/cgroups-rs"
|
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.0"
|
version = "0.2.3"
|
||||||
authors = ["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"
|
||||||
|
readme = "README.md"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
regex = "1.1"
|
regex = "1.1"
|
||||||
nix = "0.18.0"
|
nix = "0.18.0"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
procinfo = "0.4.2"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
libc = "0.2.76"
|
libc = "0.2.76"
|
||||||
|
|||||||
37
Makefile
Normal file
37
Makefile
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
all: debug fmt test
|
||||||
|
|
||||||
|
#
|
||||||
|
# Build
|
||||||
|
#
|
||||||
|
|
||||||
|
.PHONY: debug
|
||||||
|
debug:
|
||||||
|
RUSTFLAGS="--deny warnings" cargo build
|
||||||
|
|
||||||
|
.PHONY: release
|
||||||
|
release:
|
||||||
|
cargo build --release
|
||||||
|
|
||||||
|
.PHONY: build
|
||||||
|
build: debug
|
||||||
|
|
||||||
|
#
|
||||||
|
# Tests and linters
|
||||||
|
#
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test:
|
||||||
|
cargo test -- --color always --nocapture
|
||||||
|
|
||||||
|
.PHONY: check
|
||||||
|
check: fmt clippy
|
||||||
|
|
||||||
|
|
||||||
|
.PHONY: fmt
|
||||||
|
fmt:
|
||||||
|
cargo fmt --all -- --check
|
||||||
|
|
||||||
|
.PHONY: clippy
|
||||||
|
clippy:
|
||||||
|
cargo clippy --all-targets --all-features -- -D warnings
|
||||||
|
|
||||||
13
README.md
13
README.md
@@ -1,8 +1,7 @@
|
|||||||
# cgroups-rs 
|
# cgroups-rs 
|
||||||
Native Rust library for managing control groups under Linux
|
Native Rust library for managing control groups under Linux
|
||||||
|
|
||||||
Right now the crate only support the original, V1 hierarchy, however support
|
Both v1 and v2 of cgroups are supported.
|
||||||
is planned for the Unified hierarchy.
|
|
||||||
|
|
||||||
# Examples
|
# Examples
|
||||||
|
|
||||||
@@ -11,11 +10,11 @@ is planned for the Unified hierarchy.
|
|||||||
``` rust
|
``` rust
|
||||||
|
|
||||||
|
|
||||||
use cgroups::*;
|
use cgroups_rs::*;
|
||||||
use cgroups::cgroup_builder::*;
|
use cgroups_rs::cgroup_builder::*;
|
||||||
|
|
||||||
// Acquire a handle for the cgroup hierarchy.
|
// Acquire a handle for the cgroup hierarchy.
|
||||||
let hier = cgroups::hierarchies::auto();
|
let hier = cgroups_rs::hierarchies::auto();
|
||||||
|
|
||||||
// Use the builder pattern (see the documentation to create the control group)
|
// Use the builder pattern (see the documentation to create the control group)
|
||||||
//
|
//
|
||||||
@@ -30,7 +29,7 @@ let hier = cgroups::hierarchies::auto();
|
|||||||
// other control groups.
|
// other control groups.
|
||||||
|
|
||||||
// Get a handle to the CPU controller.
|
// Get a handle to the CPU controller.
|
||||||
let cpus: &cgroups::cpu::CpuController = cg.controller_of().unwrap();
|
let cpus: &cgroups_rs::cpu::CpuController = cg.controller_of().unwrap();
|
||||||
cpus.add_task(&CgroupPid::from(1234u64));
|
cpus.add_task(&CgroupPid::from(1234u64));
|
||||||
|
|
||||||
// [...]
|
// [...]
|
||||||
|
|||||||
23
src/blkio.rs
23
src/blkio.rs
@@ -8,13 +8,13 @@
|
|||||||
//!
|
//!
|
||||||
//! See the Kernel's documentation for more information about this subsystem, found at:
|
//! See the Kernel's documentation for more information about this subsystem, found at:
|
||||||
//! [Documentation/cgroup-v1/blkio-controller.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/blkio-controller.txt)
|
//! [Documentation/cgroup-v1/blkio-controller.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/blkio-controller.txt)
|
||||||
use std::fs::File;
|
use std::io::Write;
|
||||||
use std::io::{Read, Write};
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::error::ErrorKind::*;
|
use crate::error::ErrorKind::*;
|
||||||
use crate::error::*;
|
use crate::error::*;
|
||||||
|
|
||||||
|
use crate::{read_string_from, read_u64_from};
|
||||||
use crate::{
|
use crate::{
|
||||||
BlkIoResources, ControllIdentifier, ControllerInternal, Controllers, Resources, Subsystem,
|
BlkIoResources, ControllIdentifier, ControllerInternal, Controllers, Resources, Subsystem,
|
||||||
};
|
};
|
||||||
@@ -401,25 +401,6 @@ impl<'a> From<&'a Subsystem> for &'a BlkIoController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_string_from(mut file: File) -> Result<String> {
|
|
||||||
let mut string = String::new();
|
|
||||||
match file.read_to_string(&mut string) {
|
|
||||||
Ok(_) => Ok(string.trim().to_string()),
|
|
||||||
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read_u64_from(mut file: File) -> Result<u64> {
|
|
||||||
let mut string = String::new();
|
|
||||||
match file.read_to_string(&mut string) {
|
|
||||||
Ok(_) => string
|
|
||||||
.trim()
|
|
||||||
.parse()
|
|
||||||
.map_err(|e| Error::with_cause(ParseError, e)),
|
|
||||||
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BlkIoController {
|
impl BlkIoController {
|
||||||
/// Constructs a new `BlkIoController` with `root` serving as the root of the control group.
|
/// Constructs a new `BlkIoController` with `root` serving as the root of the control group.
|
||||||
pub fn new(root: PathBuf, v2: bool) -> Self {
|
pub fn new(root: PathBuf, v2: bool) -> Self {
|
||||||
|
|||||||
@@ -16,10 +16,10 @@
|
|||||||
//! by a call to `build()`.
|
//! by a call to `build()`.
|
||||||
//!
|
//!
|
||||||
//! ```rust,no_run
|
//! ```rust,no_run
|
||||||
//! # use cgroups::*;
|
//! # use cgroups_rs::*;
|
||||||
//! # use cgroups::devices::*;
|
//! # use cgroups_rs::devices::*;
|
||||||
//! # use cgroups::cgroup_builder::*;
|
//! # use cgroups_rs::cgroup_builder::*;
|
||||||
//! let h = cgroups::hierarchies::auto();
|
//! let h = cgroups_rs::hierarchies::auto();
|
||||||
//! let cgroup: Cgroup = CgroupBuilder::new("hello")
|
//! let cgroup: Cgroup = CgroupBuilder::new("hello")
|
||||||
//! .memory()
|
//! .memory()
|
||||||
//! .kernel_memory_limit(1024 * 1024)
|
//! .kernel_memory_limit(1024 * 1024)
|
||||||
|
|||||||
13
src/cpu.rs
13
src/cpu.rs
@@ -15,7 +15,7 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
use crate::error::ErrorKind::*;
|
use crate::error::ErrorKind::*;
|
||||||
use crate::error::*;
|
use crate::error::*;
|
||||||
use crate::{parse_max_value, read_i64_from};
|
use crate::{parse_max_value, read_i64_from, read_u64_from};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ControllIdentifier, ControllerInternal, Controllers, CpuResources, CustomizedAttribute,
|
ControllIdentifier, ControllerInternal, Controllers, CpuResources, CustomizedAttribute,
|
||||||
@@ -110,17 +110,6 @@ impl<'a> From<&'a Subsystem> for &'a CpuController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_u64_from(mut file: File) -> Result<u64> {
|
|
||||||
let mut string = String::new();
|
|
||||||
match file.read_to_string(&mut string) {
|
|
||||||
Ok(_) => string
|
|
||||||
.trim()
|
|
||||||
.parse()
|
|
||||||
.map_err(|e| Error::with_cause(ParseError, e)),
|
|
||||||
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CpuController {
|
impl CpuController {
|
||||||
/// Contructs a new `CpuController` with `root` serving as the root of the control group.
|
/// Contructs a new `CpuController` with `root` serving as the root of the control group.
|
||||||
pub fn new(root: PathBuf, v2: bool) -> Self {
|
pub fn new(root: PathBuf, v2: bool) -> Self {
|
||||||
|
|||||||
@@ -7,13 +7,13 @@
|
|||||||
//!
|
//!
|
||||||
//! See the Kernel's documentation for more information about this subsystem, found at:
|
//! See the Kernel's documentation for more information about this subsystem, found at:
|
||||||
//! [Documentation/cgroup-v1/cpuacct.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/cpuacct.txt)
|
//! [Documentation/cgroup-v1/cpuacct.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/cpuacct.txt)
|
||||||
use std::fs::File;
|
use std::io::Write;
|
||||||
use std::io::{Read, Write};
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::error::ErrorKind::*;
|
use crate::error::ErrorKind::*;
|
||||||
use crate::error::*;
|
use crate::error::*;
|
||||||
|
|
||||||
|
use crate::{read_string_from, read_u64_from};
|
||||||
use crate::{ControllIdentifier, ControllerInternal, Controllers, Resources, Subsystem};
|
use crate::{ControllIdentifier, ControllerInternal, Controllers, Resources, Subsystem};
|
||||||
|
|
||||||
/// A controller that allows controlling the `cpuacct` subsystem of a Cgroup.
|
/// A controller that allows controlling the `cpuacct` subsystem of a Cgroup.
|
||||||
@@ -97,26 +97,6 @@ impl<'a> From<&'a Subsystem> for &'a CpuAcctController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_u64_from(mut file: File) -> Result<u64> {
|
|
||||||
let mut string = String::new();
|
|
||||||
let res = file.read_to_string(&mut string);
|
|
||||||
match res {
|
|
||||||
Ok(_) => match string.trim().parse() {
|
|
||||||
Ok(e) => Ok(e),
|
|
||||||
Err(e) => Err(Error::with_cause(ParseError, e)),
|
|
||||||
},
|
|
||||||
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read_string_from(mut file: File) -> Result<String> {
|
|
||||||
let mut string = String::new();
|
|
||||||
match file.read_to_string(&mut string) {
|
|
||||||
Ok(_) => Ok(string.trim().to_string()),
|
|
||||||
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CpuAcctController {
|
impl CpuAcctController {
|
||||||
/// Contructs a new `CpuAcctController` with `root` serving as the root of the control group.
|
/// Contructs a new `CpuAcctController` with `root` serving as the root of the control group.
|
||||||
pub fn new(root: PathBuf) -> Self {
|
pub fn new(root: PathBuf) -> Self {
|
||||||
|
|||||||
@@ -10,13 +10,13 @@
|
|||||||
//! [Documentation/cgroup-v1/cpusets.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/cpusets.txt)
|
//! [Documentation/cgroup-v1/cpusets.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/cpusets.txt)
|
||||||
|
|
||||||
use log::*;
|
use log::*;
|
||||||
use std::fs::File;
|
use std::io::Write;
|
||||||
use std::io::{Read, Write};
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::error::ErrorKind::*;
|
use crate::error::ErrorKind::*;
|
||||||
use crate::error::*;
|
use crate::error::*;
|
||||||
|
|
||||||
|
use crate::{read_string_from, read_u64_from};
|
||||||
use crate::{
|
use crate::{
|
||||||
ControllIdentifier, ControllerInternal, Controllers, CpuResources, Resources, Subsystem,
|
ControllIdentifier, ControllerInternal, Controllers, CpuResources, Resources, Subsystem,
|
||||||
};
|
};
|
||||||
@@ -204,25 +204,6 @@ impl<'a> From<&'a Subsystem> for &'a CpuSetController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_string_from(mut file: File) -> Result<String> {
|
|
||||||
let mut string = String::new();
|
|
||||||
match file.read_to_string(&mut string) {
|
|
||||||
Ok(_) => Ok(string.trim().to_string()),
|
|
||||||
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read_u64_from(mut file: File) -> Result<u64> {
|
|
||||||
let mut string = String::new();
|
|
||||||
match file.read_to_string(&mut string) {
|
|
||||||
Ok(_) => string
|
|
||||||
.trim()
|
|
||||||
.parse()
|
|
||||||
.map_err(|e| Error::with_cause(ParseError, e)),
|
|
||||||
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parse a string like "1,2,4-5,8" into a list of (start, end) tuples.
|
/// Parse a string like "1,2,4-5,8" into a list of (start, end) tuples.
|
||||||
fn parse_range(s: String) -> Result<Vec<(u64, u64)>> {
|
fn parse_range(s: String) -> Result<Vec<(u64, u64)>> {
|
||||||
let mut fin = Vec::new();
|
let mut fin = Vec::new();
|
||||||
|
|||||||
@@ -9,8 +9,9 @@
|
|||||||
//! Currently, we only support the cgroupv1 hierarchy, but in the future we will add support for
|
//! Currently, we only support the cgroupv1 hierarchy, but in the future we will add support for
|
||||||
//! the Unified Hierarchy.
|
//! the Unified Hierarchy.
|
||||||
|
|
||||||
use procinfo::pid::{mountinfo_self, Mountinfo};
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{BufRead, BufReader};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::blkio::BlkIoController;
|
use crate::blkio::BlkIoController;
|
||||||
@@ -31,6 +32,75 @@ use crate::{Controllers, Hierarchy, Subsystem};
|
|||||||
|
|
||||||
use crate::cgroup::Cgroup;
|
use crate::cgroup::Cgroup;
|
||||||
|
|
||||||
|
/// Process mounts information.
|
||||||
|
///
|
||||||
|
/// See `proc(5)` for format details.
|
||||||
|
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||||
|
pub struct Mountinfo {
|
||||||
|
/// Mount pathname relative to the process's root.
|
||||||
|
pub mount_point: PathBuf,
|
||||||
|
/// Filesystem type (main type with optional sub-type).
|
||||||
|
pub fs_type: (String, Option<String>),
|
||||||
|
/// Superblock options.
|
||||||
|
pub super_opts: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn parse_mountinfo_for_line(line: &str) -> Option<Mountinfo> {
|
||||||
|
let s_values: Vec<_> = line.split(" - ").collect();
|
||||||
|
if s_values.len() != 2 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let s0_values: Vec<_> = s_values[0].trim().split(' ').collect();
|
||||||
|
let s1_values: Vec<_> = s_values[1].trim().split(' ').collect();
|
||||||
|
if s0_values.len() < 6 || s1_values.len() < 3 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let mount_point = PathBuf::from(s0_values[4]);
|
||||||
|
let fs_type_values: Vec<_> = s1_values[0].trim().split('.').collect();
|
||||||
|
let fs_type = match fs_type_values.len() {
|
||||||
|
1 => (fs_type_values[0].to_string(), None),
|
||||||
|
2 => (
|
||||||
|
fs_type_values[0].to_string(),
|
||||||
|
Some(fs_type_values[1].to_string()),
|
||||||
|
),
|
||||||
|
_ => return None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let super_opts: Vec<String> = s1_values[2].trim().split(',').map(String::from).collect();
|
||||||
|
Some(Mountinfo {
|
||||||
|
mount_point,
|
||||||
|
fs_type,
|
||||||
|
super_opts,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parses the provided mountinfo file.
|
||||||
|
fn mountinfo_file(file: &mut File) -> Vec<Mountinfo> {
|
||||||
|
let mut r = Vec::new();
|
||||||
|
for line in BufReader::new(file).lines() {
|
||||||
|
match line {
|
||||||
|
Ok(line) => {
|
||||||
|
if let Some(mi) = parse_mountinfo_for_line(&line) {
|
||||||
|
if mi.fs_type.0 == "cgroup" {
|
||||||
|
r.push(mi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_) => continue,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
r
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns mounts information for the current process.
|
||||||
|
pub fn mountinfo_self() -> Vec<Mountinfo> {
|
||||||
|
match File::open("/proc/self/mountinfo") {
|
||||||
|
Ok(mut file) => mountinfo_file(&mut file),
|
||||||
|
Err(_) => vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The standard, original cgroup implementation. Often referred to as "cgroupv1".
|
/// The standard, original cgroup implementation. Often referred to as "cgroupv1".
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct V1 {
|
pub struct V1 {
|
||||||
@@ -184,7 +254,7 @@ impl V1 {
|
|||||||
/// can be created.
|
/// can be created.
|
||||||
pub fn new() -> V1 {
|
pub fn new() -> V1 {
|
||||||
V1 {
|
V1 {
|
||||||
mountinfo: mountinfo_self().unwrap(),
|
mountinfo: mountinfo_self(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,3 +323,36 @@ pub fn auto() -> Box<dyn Hierarchy> {
|
|||||||
Box::new(V1::new())
|
Box::new(V1::new())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_mount() {
|
||||||
|
let mountinfo = vec![
|
||||||
|
("29 26 0:26 / /sys/fs/cgroup/cpuset,cpu,cpuacct rw,nosuid,nodev,noexec,relatime shared:10 - cgroup cgroup rw,cpuset,cpu,cpuacct",
|
||||||
|
Mountinfo{mount_point: PathBuf::from("/sys/fs/cgroup/cpuset,cpu,cpuacct"), fs_type: ("cgroup".to_string(), None), super_opts: vec![
|
||||||
|
"rw".to_string(),
|
||||||
|
"cpuset".to_string(),
|
||||||
|
"cpu".to_string(),
|
||||||
|
"cpuacct".to_string(),
|
||||||
|
]}),
|
||||||
|
("121 1731 0:42 / /shm rw,nosuid,nodev,noexec,relatime shared:68 master:66 - tmpfs shm rw,size=65536k",
|
||||||
|
Mountinfo{mount_point: PathBuf::from("/shm"), fs_type: ("tmpfs".to_string(), None), super_opts: vec![
|
||||||
|
"rw".to_string(),
|
||||||
|
"size=65536k".to_string(),
|
||||||
|
]}),
|
||||||
|
("121 1731 0:42 / /shm rw,nosuid,nodev,noexec,relatime shared:68 master:66 - tmpfs.123 shm rw,size=65536k",
|
||||||
|
Mountinfo{mount_point: PathBuf::from("/shm"), fs_type: ("tmpfs".to_string(), Some("123".to_string())), super_opts: vec![
|
||||||
|
"rw".to_string(),
|
||||||
|
"size=65536k".to_string(),
|
||||||
|
]}),
|
||||||
|
];
|
||||||
|
|
||||||
|
for mi in mountinfo {
|
||||||
|
let info = parse_mountinfo_for_line(mi.0).unwrap();
|
||||||
|
assert_eq!(info, mi.1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,13 +8,12 @@
|
|||||||
//!
|
//!
|
||||||
//! See the Kernel's documentation for more information about this subsystem, found at:
|
//! See the Kernel's documentation for more information about this subsystem, found at:
|
||||||
//! [Documentation/cgroup-v1/hugetlb.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/hugetlb.txt)
|
//! [Documentation/cgroup-v1/hugetlb.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/hugetlb.txt)
|
||||||
use std::fs::File;
|
use std::io::Write;
|
||||||
use std::io::{Read, Write};
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::error::ErrorKind::*;
|
use crate::error::ErrorKind::*;
|
||||||
use crate::error::*;
|
use crate::error::*;
|
||||||
use crate::flat_keyed_to_vec;
|
use crate::{flat_keyed_to_vec, read_u64_from};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ControllIdentifier, ControllerInternal, Controllers, HugePageResources, Resources, Subsystem,
|
ControllIdentifier, ControllerInternal, Controllers, HugePageResources, Resources, Subsystem,
|
||||||
@@ -86,17 +85,6 @@ impl<'a> From<&'a Subsystem> for &'a HugeTlbController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_u64_from(mut file: File) -> Result<u64> {
|
|
||||||
let mut string = String::new();
|
|
||||||
match file.read_to_string(&mut string) {
|
|
||||||
Ok(_) => string
|
|
||||||
.trim()
|
|
||||||
.parse()
|
|
||||||
.map_err(|e| Error::with_cause(ParseError, e)),
|
|
||||||
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HugeTlbController {
|
impl HugeTlbController {
|
||||||
/// Constructs a new `HugeTlbController` with `root` serving as the root of the control group.
|
/// Constructs a new `HugeTlbController` with `root` serving as the root of the control group.
|
||||||
pub fn new(root: PathBuf, v2: bool) -> Self {
|
pub fn new(root: PathBuf, v2: bool) -> Self {
|
||||||
|
|||||||
60
src/lib.rs
60
src/lib.rs
@@ -10,6 +10,7 @@ use std::collections::HashMap;
|
|||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io::{BufRead, BufReader, Read, Write};
|
use std::io::{BufRead, BufReader, Read, Write};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
macro_rules! update_and_test {
|
macro_rules! update_and_test {
|
||||||
($self: ident, $set_func:ident, $value:expr, $get_func:ident) => {
|
($self: ident, $set_func:ident, $value:expr, $get_func:ident) => {
|
||||||
@@ -329,7 +330,7 @@ where
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::remove_dir(self.get_path()).map_err(|e| Error::with_cause(ErrorKind::RemoveFailed, e))
|
remove_dir(self.get_path())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attach a task to this controller.
|
/// Attach a task to this controller.
|
||||||
@@ -378,6 +379,30 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove_dir aims to remove cgroup path. It does so recursively,
|
||||||
|
// by removing any subdirectories (sub-cgroups) first.
|
||||||
|
fn remove_dir(dir: &PathBuf) -> Result<()> {
|
||||||
|
// try the fast path first.
|
||||||
|
if fs::remove_dir(dir).is_ok() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
if dir.exists() {
|
||||||
|
if dir.is_dir() {
|
||||||
|
for entry in fs::read_dir(dir).map_err(|e| Error::with_cause(ReadFailed, e))? {
|
||||||
|
let entry = entry.map_err(|e| Error::with_cause(ReadFailed, e))?;
|
||||||
|
let path = entry.path();
|
||||||
|
if path.is_dir() {
|
||||||
|
remove_dir(&path)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fs::remove_dir(dir).map_err(|e| Error::with_cause(RemoveFailed, e))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub trait ControllIdentifier {
|
pub trait ControllIdentifier {
|
||||||
fn controller_type() -> Controllers;
|
fn controller_type() -> Controllers;
|
||||||
@@ -385,7 +410,7 @@ pub trait ControllIdentifier {
|
|||||||
|
|
||||||
/// Control group hierarchy (right now, only V1 is supported, but in the future Unified will be
|
/// Control group hierarchy (right now, only V1 is supported, but in the future Unified will be
|
||||||
/// implemented as well).
|
/// implemented as well).
|
||||||
pub trait Hierarchy: std::fmt::Debug + Send {
|
pub trait Hierarchy: std::fmt::Debug + Send + Sync {
|
||||||
/// Returns what subsystems are supported by the hierarchy.
|
/// Returns what subsystems are supported by the hierarchy.
|
||||||
fn subsystems(&self) -> Vec<Subsystem>;
|
fn subsystems(&self) -> Vec<Subsystem>;
|
||||||
|
|
||||||
@@ -422,7 +447,7 @@ pub struct MemoryResources {
|
|||||||
///
|
///
|
||||||
/// # Usage:
|
/// # Usage:
|
||||||
/// ```
|
/// ```
|
||||||
/// let resource = &mut cgroups::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", "true".to_string());
|
||||||
/// // apply here
|
/// // apply here
|
||||||
pub attrs: std::collections::HashMap<&'static str, String>,
|
pub attrs: std::collections::HashMap<&'static str, String>,
|
||||||
@@ -464,7 +489,7 @@ pub struct CpuResources {
|
|||||||
/// Customized key-value attributes
|
/// Customized key-value attributes
|
||||||
/// # Usage:
|
/// # Usage:
|
||||||
/// ```
|
/// ```
|
||||||
/// let resource = &mut cgroups::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", "10".to_string());
|
||||||
/// // apply here
|
/// // apply here
|
||||||
/// ```
|
/// ```
|
||||||
@@ -832,14 +857,35 @@ pub fn nested_keyed_to_hashmap(mut file: File) -> Result<HashMap<String, HashMap
|
|||||||
Ok(h)
|
Ok(h)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// read and parse an i64 data
|
fn read_from<T>(mut file: File) -> Result<T>
|
||||||
fn read_i64_from(mut file: File) -> Result<i64> {
|
where
|
||||||
|
T: FromStr,
|
||||||
|
<T as FromStr>::Err: 'static + Send + Sync + std::error::Error,
|
||||||
|
{
|
||||||
let mut string = String::new();
|
let mut string = String::new();
|
||||||
match file.read_to_string(&mut string) {
|
match file.read_to_string(&mut string) {
|
||||||
Ok(_) => string
|
Ok(_) => string
|
||||||
.trim()
|
.trim()
|
||||||
.parse()
|
.parse::<T>()
|
||||||
.map_err(|e| Error::with_cause(ParseError, e)),
|
.map_err(|e| Error::with_cause(ParseError, e)),
|
||||||
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read_string_from(mut file: File) -> Result<String> {
|
||||||
|
let mut string = String::new();
|
||||||
|
match file.read_to_string(&mut string) {
|
||||||
|
Ok(_) => Ok(string.trim().to_string()),
|
||||||
|
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// read and parse an u64 data
|
||||||
|
fn read_u64_from(file: File) -> Result<u64> {
|
||||||
|
read_from::<u64>(file)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// read and parse an i64 data
|
||||||
|
fn read_i64_from(file: File) -> Result<i64> {
|
||||||
|
read_from::<i64>(file)
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,15 +9,14 @@
|
|||||||
//! See the Kernel's documentation for more information about this subsystem, found at:
|
//! See the Kernel's documentation for more information about this subsystem, found at:
|
||||||
//! [Documentation/cgroup-v1/memory.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt)
|
//! [Documentation/cgroup-v1/memory.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt)
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs::File;
|
use std::io::Write;
|
||||||
use std::io::{Read, Write};
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::mpsc::Receiver;
|
use std::sync::mpsc::Receiver;
|
||||||
|
|
||||||
use crate::error::ErrorKind::*;
|
use crate::error::ErrorKind::*;
|
||||||
use crate::error::*;
|
use crate::error::*;
|
||||||
use crate::events;
|
use crate::events;
|
||||||
use crate::read_i64_from;
|
use crate::{read_i64_from, read_string_from, read_u64_from};
|
||||||
|
|
||||||
use crate::flat_keyed_to_hashmap;
|
use crate::flat_keyed_to_hashmap;
|
||||||
|
|
||||||
@@ -461,6 +460,10 @@ impl ControllerInternal for MemController {
|
|||||||
update!(self, set_tcp_limit, memres.kernel_tcp_memory_limit);
|
update!(self, set_tcp_limit, memres.kernel_tcp_memory_limit);
|
||||||
update!(self, set_swappiness, memres.swappiness);
|
update!(self, set_swappiness, memres.swappiness);
|
||||||
|
|
||||||
|
memres.attrs.iter().for_each(|(k, v)| {
|
||||||
|
let _ = self.set(k, v);
|
||||||
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -870,25 +873,6 @@ impl<'a> From<&'a Subsystem> for &'a MemController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_u64_from(mut file: File) -> Result<u64> {
|
|
||||||
let mut string = String::new();
|
|
||||||
match file.read_to_string(&mut string) {
|
|
||||||
Ok(_) => string
|
|
||||||
.trim()
|
|
||||||
.parse()
|
|
||||||
.map_err(|e| Error::with_cause(ParseError, e)),
|
|
||||||
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read_string_from(mut file: File) -> Result<String> {
|
|
||||||
let mut string = String::new();
|
|
||||||
match file.read_to_string(&mut string) {
|
|
||||||
Ok(_) => Ok(string.trim().to_string()),
|
|
||||||
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::memory::{
|
use crate::memory::{
|
||||||
|
|||||||
@@ -7,13 +7,13 @@
|
|||||||
//!
|
//!
|
||||||
//! See the Kernel's documentation for more information about this subsystem, found at:
|
//! See the Kernel's documentation for more information about this subsystem, found at:
|
||||||
//! [Documentation/cgroup-v1/net_cls.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/net_cls.txt)
|
//! [Documentation/cgroup-v1/net_cls.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/net_cls.txt)
|
||||||
use std::fs::File;
|
use std::io::Write;
|
||||||
use std::io::{Read, Write};
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::error::ErrorKind::*;
|
use crate::error::ErrorKind::*;
|
||||||
use crate::error::*;
|
use crate::error::*;
|
||||||
|
|
||||||
|
use crate::read_u64_from;
|
||||||
use crate::{
|
use crate::{
|
||||||
ControllIdentifier, ControllerInternal, Controllers, NetworkResources, Resources, Subsystem,
|
ControllIdentifier, ControllerInternal, Controllers, NetworkResources, Resources, Subsystem,
|
||||||
};
|
};
|
||||||
@@ -74,17 +74,6 @@ impl<'a> From<&'a Subsystem> for &'a NetClsController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_u64_from(mut file: File) -> Result<u64> {
|
|
||||||
let mut string = String::new();
|
|
||||||
match file.read_to_string(&mut string) {
|
|
||||||
Ok(_) => string
|
|
||||||
.trim()
|
|
||||||
.parse()
|
|
||||||
.map_err(|e| Error::with_cause(ParseError, e)),
|
|
||||||
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl NetClsController {
|
impl NetClsController {
|
||||||
/// Constructs a new `NetClsController` with `root` serving as the root of the control group.
|
/// Constructs a new `NetClsController` with `root` serving as the root of the control group.
|
||||||
pub fn new(root: PathBuf) -> Self {
|
pub fn new(root: PathBuf) -> Self {
|
||||||
|
|||||||
@@ -8,13 +8,13 @@
|
|||||||
//! See the Kernel's documentation for more information about this subsystem, found at:
|
//! See the Kernel's documentation for more information about this subsystem, found at:
|
||||||
//! [Documentation/cgroup-v1/net_prio.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/net_prio.txt)
|
//! [Documentation/cgroup-v1/net_prio.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/net_prio.txt)
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs::File;
|
use std::io::{BufRead, BufReader, Write};
|
||||||
use std::io::{BufRead, BufReader, Read, Write};
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::error::ErrorKind::*;
|
use crate::error::ErrorKind::*;
|
||||||
use crate::error::*;
|
use crate::error::*;
|
||||||
|
|
||||||
|
use crate::read_u64_from;
|
||||||
use crate::{
|
use crate::{
|
||||||
ControllIdentifier, ControllerInternal, Controllers, NetworkResources, Resources, Subsystem,
|
ControllIdentifier, ControllerInternal, Controllers, NetworkResources, Resources, Subsystem,
|
||||||
};
|
};
|
||||||
@@ -77,17 +77,6 @@ impl<'a> From<&'a Subsystem> for &'a NetPrioController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_u64_from(mut file: File) -> Result<u64> {
|
|
||||||
let mut string = String::new();
|
|
||||||
match file.read_to_string(&mut string) {
|
|
||||||
Ok(_) => string
|
|
||||||
.trim()
|
|
||||||
.parse()
|
|
||||||
.map_err(|e| Error::with_cause(ParseError, e)),
|
|
||||||
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl NetPrioController {
|
impl NetPrioController {
|
||||||
/// Constructs a new `NetPrioController` with `root` serving as the root of the control group.
|
/// Constructs a new `NetPrioController` with `root` serving as the root of the control group.
|
||||||
pub fn new(root: PathBuf) -> Self {
|
pub fn new(root: PathBuf) -> Self {
|
||||||
|
|||||||
13
src/pid.rs
13
src/pid.rs
@@ -8,13 +8,13 @@
|
|||||||
//!
|
//!
|
||||||
//! See the Kernel's documentation for more information about this subsystem, found at:
|
//! See the Kernel's documentation for more information about this subsystem, found at:
|
||||||
//! [Documentation/cgroups-v1/pids.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/pids.txt)
|
//! [Documentation/cgroups-v1/pids.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/pids.txt)
|
||||||
use std::fs::File;
|
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::error::ErrorKind::*;
|
use crate::error::ErrorKind::*;
|
||||||
use crate::error::*;
|
use crate::error::*;
|
||||||
|
|
||||||
|
use crate::read_u64_from;
|
||||||
use crate::{
|
use crate::{
|
||||||
parse_max_value, ControllIdentifier, ControllerInternal, Controllers, MaxValue, PidResources,
|
parse_max_value, ControllIdentifier, ControllerInternal, Controllers, MaxValue, PidResources,
|
||||||
Resources, Subsystem,
|
Resources, Subsystem,
|
||||||
@@ -89,17 +89,6 @@ impl<'a> From<&'a Subsystem> for &'a PidController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_u64_from(mut file: File) -> Result<u64> {
|
|
||||||
let mut string = String::new();
|
|
||||||
match file.read_to_string(&mut string) {
|
|
||||||
Ok(_) => string
|
|
||||||
.trim()
|
|
||||||
.parse()
|
|
||||||
.map_err(|e| Error::with_cause(ParseError, e)),
|
|
||||||
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PidController {
|
impl PidController {
|
||||||
/// Constructors a new `PidController` instance, with `root` serving as the controller's root
|
/// Constructors a new `PidController` instance, with `root` serving as the controller's root
|
||||||
/// directory.
|
/// directory.
|
||||||
|
|||||||
12
src/rdma.rs
12
src/rdma.rs
@@ -7,13 +7,13 @@
|
|||||||
//!
|
//!
|
||||||
//! See the Kernel's documentation for more information about this subsystem, found at:
|
//! See the Kernel's documentation for more information about this subsystem, found at:
|
||||||
//! [Documentation/cgroup-v1/rdma.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/rdma.txt)
|
//! [Documentation/cgroup-v1/rdma.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/rdma.txt)
|
||||||
use std::fs::File;
|
use std::io::Write;
|
||||||
use std::io::{Read, Write};
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::error::ErrorKind::*;
|
use crate::error::ErrorKind::*;
|
||||||
use crate::error::*;
|
use crate::error::*;
|
||||||
|
|
||||||
|
use crate::read_string_from;
|
||||||
use crate::{ControllIdentifier, ControllerInternal, Controllers, Resources, Subsystem};
|
use crate::{ControllIdentifier, ControllerInternal, Controllers, Resources, Subsystem};
|
||||||
|
|
||||||
/// A controller that allows controlling the `rdma` subsystem of a Cgroup.
|
/// A controller that allows controlling the `rdma` subsystem of a Cgroup.
|
||||||
@@ -66,14 +66,6 @@ impl<'a> From<&'a Subsystem> for &'a RdmaController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_string_from(mut file: File) -> Result<String> {
|
|
||||||
let mut string = String::new();
|
|
||||||
match file.read_to_string(&mut string) {
|
|
||||||
Ok(_) => Ok(string.trim().to_string()),
|
|
||||||
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RdmaController {
|
impl RdmaController {
|
||||||
/// Constructs a new `RdmaController` with `root` serving as the root of the control group.
|
/// Constructs a new `RdmaController` with `root` serving as the root of the control group.
|
||||||
pub fn new(root: PathBuf) -> Self {
|
pub fn new(root: PathBuf) -> Self {
|
||||||
|
|||||||
@@ -5,19 +5,19 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
//! Some simple tests covering the builder pattern for control groups.
|
//! Some simple tests covering the builder pattern for control groups.
|
||||||
use cgroups::blkio::*;
|
use cgroups_rs::blkio::*;
|
||||||
use cgroups::cgroup_builder::*;
|
use cgroups_rs::cgroup_builder::*;
|
||||||
use cgroups::cpu::*;
|
use cgroups_rs::cpu::*;
|
||||||
use cgroups::devices::*;
|
use cgroups_rs::devices::*;
|
||||||
use cgroups::hugetlb::*;
|
use cgroups_rs::hugetlb::*;
|
||||||
use cgroups::memory::*;
|
use cgroups_rs::memory::*;
|
||||||
use cgroups::net_cls::*;
|
use cgroups_rs::net_cls::*;
|
||||||
use cgroups::pid::*;
|
use cgroups_rs::pid::*;
|
||||||
use cgroups::*;
|
use cgroups_rs::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_cpu_res_build() {
|
pub fn test_cpu_res_build() {
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
let cg: Cgroup = CgroupBuilder::new("test_cpu_res_build")
|
let cg: Cgroup = CgroupBuilder::new("test_cpu_res_build")
|
||||||
.cpu()
|
.cpu()
|
||||||
.shares(85)
|
.shares(85)
|
||||||
@@ -35,7 +35,7 @@ pub fn test_cpu_res_build() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_memory_res_build() {
|
pub fn test_memory_res_build() {
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
let cg: Cgroup = CgroupBuilder::new("test_memory_res_build")
|
let cg: Cgroup = CgroupBuilder::new("test_memory_res_build")
|
||||||
.memory()
|
.memory()
|
||||||
.kernel_memory_limit(128 * 1024 * 1024)
|
.kernel_memory_limit(128 * 1024 * 1024)
|
||||||
@@ -58,7 +58,7 @@ pub fn test_memory_res_build() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_pid_res_build() {
|
pub fn test_pid_res_build() {
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
let cg: Cgroup = CgroupBuilder::new("test_pid_res_build")
|
let cg: Cgroup = CgroupBuilder::new("test_pid_res_build")
|
||||||
.pid()
|
.pid()
|
||||||
.maximum_number_of_processes(MaxValue::Value(123))
|
.maximum_number_of_processes(MaxValue::Value(123))
|
||||||
@@ -77,7 +77,7 @@ pub fn test_pid_res_build() {
|
|||||||
#[test]
|
#[test]
|
||||||
#[ignore] // ignore this test for now, not sure why my kernel doesn't like it
|
#[ignore] // ignore this test for now, not sure why my kernel doesn't like it
|
||||||
pub fn test_devices_res_build() {
|
pub fn test_devices_res_build() {
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
let cg: Cgroup = CgroupBuilder::new("test_devices_res_build")
|
let cg: Cgroup = CgroupBuilder::new("test_devices_res_build")
|
||||||
.devices()
|
.devices()
|
||||||
.device(1, 6, DeviceType::Char, true, vec![DevicePermissions::Read])
|
.device(1, 6, DeviceType::Char, true, vec![DevicePermissions::Read])
|
||||||
@@ -103,7 +103,7 @@ pub fn test_devices_res_build() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_network_res_build() {
|
pub fn test_network_res_build() {
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
if h.v2() {
|
if h.v2() {
|
||||||
// FIXME add cases for v2
|
// FIXME add cases for v2
|
||||||
return;
|
return;
|
||||||
@@ -124,7 +124,7 @@ pub fn test_network_res_build() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_hugepages_res_build() {
|
pub fn test_hugepages_res_build() {
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
if h.v2() {
|
if h.v2() {
|
||||||
// FIXME add cases for v2
|
// FIXME add cases for v2
|
||||||
return;
|
return;
|
||||||
@@ -149,7 +149,7 @@ pub fn test_hugepages_res_build() {
|
|||||||
#[test]
|
#[test]
|
||||||
#[ignore] // high version kernel not support `blkio.weight`
|
#[ignore] // high version kernel not support `blkio.weight`
|
||||||
pub fn test_blkio_res_build() {
|
pub fn test_blkio_res_build() {
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
let cg: Cgroup = CgroupBuilder::new("test_blkio_res_build")
|
let cg: Cgroup = CgroupBuilder::new("test_blkio_res_build")
|
||||||
.blkio()
|
.blkio()
|
||||||
.weight(100)
|
.weight(100)
|
||||||
|
|||||||
@@ -5,13 +5,13 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
//! Simple unit tests about the control groups system.
|
//! Simple unit tests about the control groups system.
|
||||||
use cgroups::memory::MemController;
|
use cgroups_rs::memory::MemController;
|
||||||
use cgroups::Controller;
|
use cgroups_rs::Controller;
|
||||||
use cgroups::{Cgroup, CgroupPid, Subsystem};
|
use cgroups_rs::{Cgroup, CgroupPid, Subsystem};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_tasks_iterator() {
|
fn test_tasks_iterator() {
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
let pid = libc::pid_t::from(nix::unistd::getpid()) as u64;
|
let pid = libc::pid_t::from(nix::unistd::getpid()) as u64;
|
||||||
let cg = Cgroup::new(h, String::from("test_tasks_iterator"));
|
let cg = Cgroup::new(h, String::from("test_tasks_iterator"));
|
||||||
{
|
{
|
||||||
@@ -38,10 +38,10 @@ fn test_tasks_iterator() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cgroup_with_relative_paths() {
|
fn test_cgroup_with_relative_paths() {
|
||||||
if cgroups::hierarchies::is_cgroup2_unified_mode() {
|
if cgroups_rs::hierarchies::is_cgroup2_unified_mode() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
let cgroup_root = h.root();
|
let cgroup_root = h.root();
|
||||||
let cgroup_name = "test_cgroup_with_relative_paths";
|
let cgroup_name = "test_cgroup_with_relative_paths";
|
||||||
|
|
||||||
@@ -79,10 +79,10 @@ fn test_cgroup_with_relative_paths() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cgroup_v2() {
|
fn test_cgroup_v2() {
|
||||||
if !cgroups::hierarchies::is_cgroup2_unified_mode() {
|
if !cgroups_rs::hierarchies::is_cgroup2_unified_mode() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
let cg = Cgroup::new(h, String::from("test_v2"));
|
let cg = Cgroup::new(h, String::from("test_v2"));
|
||||||
|
|
||||||
let mem_controller: &MemController = cg.controller_of().unwrap();
|
let mem_controller: &MemController = cg.controller_of().unwrap();
|
||||||
|
|||||||
@@ -4,12 +4,12 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
//! Simple unit tests about the CPU control groups system.
|
//! Simple unit tests about the CPU control groups system.
|
||||||
use cgroups::cpu::CpuController;
|
use cgroups_rs::cpu::CpuController;
|
||||||
use cgroups::Cgroup;
|
use cgroups_rs::Cgroup;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cfs_quota_and_periods() {
|
fn test_cfs_quota_and_periods() {
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
let cg = Cgroup::new(h, String::from("test_cfs_quota_and_periods"));
|
let cg = Cgroup::new(h, String::from("test_cfs_quota_and_periods"));
|
||||||
|
|
||||||
let cpu_controller: &CpuController = cg.controller_of().unwrap();
|
let cpu_controller: &CpuController = cg.controller_of().unwrap();
|
||||||
|
|||||||
@@ -4,15 +4,15 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0 or MIT
|
// SPDX-License-Identifier: Apache-2.0 or MIT
|
||||||
//
|
//
|
||||||
|
|
||||||
use cgroups::cpuset::CpuSetController;
|
use cgroups_rs::cpuset::CpuSetController;
|
||||||
use cgroups::error::ErrorKind;
|
use cgroups_rs::error::ErrorKind;
|
||||||
use cgroups::{Cgroup, CgroupPid};
|
use cgroups_rs::{Cgroup, CgroupPid};
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cpuset_memory_pressure_root_cg() {
|
fn test_cpuset_memory_pressure_root_cg() {
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
let cg = Cgroup::new(h, String::from("test_cpuset_memory_pressure_root_cg"));
|
let cg = Cgroup::new(h, String::from("test_cpuset_memory_pressure_root_cg"));
|
||||||
{
|
{
|
||||||
let cpuset: &CpuSetController = cg.controller_of().unwrap();
|
let cpuset: &CpuSetController = cg.controller_of().unwrap();
|
||||||
@@ -26,7 +26,7 @@ fn test_cpuset_memory_pressure_root_cg() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cpuset_set_cpus() {
|
fn test_cpuset_set_cpus() {
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
let cg = Cgroup::new(h, String::from("test_cpuset_set_cpus"));
|
let cg = Cgroup::new(h, String::from("test_cpuset_set_cpus"));
|
||||||
{
|
{
|
||||||
let cpuset: &CpuSetController = cg.controller_of().unwrap();
|
let cpuset: &CpuSetController = cg.controller_of().unwrap();
|
||||||
@@ -64,7 +64,7 @@ fn test_cpuset_set_cpus() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cpuset_set_cpus_add_task() {
|
fn test_cpuset_set_cpus_add_task() {
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
let cg = Cgroup::new(h, String::from("test_cpuset_set_cpus_add_task/sub-dir"));
|
let cg = Cgroup::new(h, String::from("test_cpuset_set_cpus_add_task/sub-dir"));
|
||||||
|
|
||||||
let cpuset: &CpuSetController = cg.controller_of().unwrap();
|
let cpuset: &CpuSetController = cg.controller_of().unwrap();
|
||||||
|
|||||||
@@ -6,17 +6,17 @@
|
|||||||
|
|
||||||
//! Integration tests about the devices subsystem
|
//! Integration tests about the devices subsystem
|
||||||
|
|
||||||
use cgroups::devices::{DevicePermissions, DeviceType, DevicesController};
|
use cgroups_rs::devices::{DevicePermissions, DeviceType, DevicesController};
|
||||||
use cgroups::{Cgroup, DeviceResource};
|
use cgroups_rs::{Cgroup, DeviceResource};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_devices_parsing() {
|
fn test_devices_parsing() {
|
||||||
// now only v2
|
// now only v2
|
||||||
if cgroups::hierarchies::is_cgroup2_unified_mode() {
|
if cgroups_rs::hierarchies::is_cgroup2_unified_mode() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
let cg = Cgroup::new(h, String::from("test_devices_parsing"));
|
let cg = Cgroup::new(h, String::from("test_devices_parsing"));
|
||||||
{
|
{
|
||||||
let devices: &DevicesController = cg.controller_of().unwrap();
|
let devices: &DevicesController = cg.controller_of().unwrap();
|
||||||
|
|||||||
@@ -4,19 +4,19 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
//! Integration tests about the hugetlb subsystem
|
//! Integration tests about the hugetlb subsystem
|
||||||
use cgroups::error::*;
|
use cgroups_rs::error::*;
|
||||||
use cgroups::hugetlb::{self, HugeTlbController};
|
use cgroups_rs::hugetlb::{self, HugeTlbController};
|
||||||
use cgroups::Cgroup;
|
use cgroups_rs::Cgroup;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_hugetlb_sizes() {
|
fn test_hugetlb_sizes() {
|
||||||
// now only v2
|
// now only v2
|
||||||
if cgroups::hierarchies::is_cgroup2_unified_mode() {
|
if cgroups_rs::hierarchies::is_cgroup2_unified_mode() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
let cg = Cgroup::new(h, String::from("test_hugetlb_sizes"));
|
let cg = Cgroup::new(h, String::from("test_hugetlb_sizes"));
|
||||||
{
|
{
|
||||||
let hugetlb_controller: &HugeTlbController = cg.controller_of().unwrap();
|
let hugetlb_controller: &HugeTlbController = cg.controller_of().unwrap();
|
||||||
|
|||||||
@@ -4,13 +4,13 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
//! Integration tests about the hugetlb subsystem
|
//! Integration tests about the hugetlb subsystem
|
||||||
use cgroups::memory::{MemController, SetMemory};
|
use cgroups_rs::memory::{MemController, SetMemory};
|
||||||
use cgroups::Controller;
|
use cgroups_rs::Controller;
|
||||||
use cgroups::{Cgroup, MaxValue};
|
use cgroups_rs::{Cgroup, MaxValue};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_disable_oom_killer() {
|
fn test_disable_oom_killer() {
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
let cg = Cgroup::new(h, String::from("test_disable_oom_killer"));
|
let cg = Cgroup::new(h, String::from("test_disable_oom_killer"));
|
||||||
{
|
{
|
||||||
let mem_controller: &MemController = cg.controller_of().unwrap();
|
let mem_controller: &MemController = cg.controller_of().unwrap();
|
||||||
@@ -35,7 +35,7 @@ fn test_disable_oom_killer() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn set_mem_v2() {
|
fn set_mem_v2() {
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
if !h.v2() {
|
if !h.v2() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
//! Integration tests about the pids subsystem
|
//! Integration tests about the pids subsystem
|
||||||
use cgroups::pid::PidController;
|
use cgroups_rs::pid::PidController;
|
||||||
use cgroups::Controller;
|
use cgroups_rs::Controller;
|
||||||
use cgroups::{Cgroup, MaxValue};
|
use cgroups_rs::{Cgroup, MaxValue};
|
||||||
|
|
||||||
use nix::sys::wait::{waitpid, WaitStatus};
|
use nix::sys::wait::{waitpid, WaitStatus};
|
||||||
use nix::unistd::{fork, ForkResult};
|
use nix::unistd::{fork, ForkResult};
|
||||||
@@ -16,7 +16,7 @@ use libc::pid_t;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn create_and_delete_cgroup() {
|
fn create_and_delete_cgroup() {
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
let cg = Cgroup::new(h, String::from("create_and_delete_cgroup"));
|
let cg = Cgroup::new(h, String::from("create_and_delete_cgroup"));
|
||||||
{
|
{
|
||||||
let pidcontroller: &PidController = cg.controller_of().unwrap();
|
let pidcontroller: &PidController = cg.controller_of().unwrap();
|
||||||
@@ -30,7 +30,7 @@ fn create_and_delete_cgroup() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pids_current_is_zero() {
|
fn test_pids_current_is_zero() {
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
let cg = Cgroup::new(h, String::from("test_pids_current_is_zero"));
|
let cg = Cgroup::new(h, String::from("test_pids_current_is_zero"));
|
||||||
{
|
{
|
||||||
let pidcontroller: &PidController = cg.controller_of().unwrap();
|
let pidcontroller: &PidController = cg.controller_of().unwrap();
|
||||||
@@ -42,7 +42,7 @@ fn test_pids_current_is_zero() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pids_events_is_zero() {
|
fn test_pids_events_is_zero() {
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
let cg = Cgroup::new(h, String::from("test_pids_events_is_zero"));
|
let cg = Cgroup::new(h, String::from("test_pids_events_is_zero"));
|
||||||
{
|
{
|
||||||
let pidcontroller: &PidController = cg.controller_of().unwrap();
|
let pidcontroller: &PidController = cg.controller_of().unwrap();
|
||||||
@@ -55,7 +55,7 @@ fn test_pids_events_is_zero() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pid_events_is_not_zero() {
|
fn test_pid_events_is_not_zero() {
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
let cg = Cgroup::new(h, String::from("test_pid_events_is_not_zero"));
|
let cg = Cgroup::new(h, String::from("test_pid_events_is_not_zero"));
|
||||||
{
|
{
|
||||||
let pids: &PidController = cg.controller_of().unwrap();
|
let pids: &PidController = cg.controller_of().unwrap();
|
||||||
|
|||||||
@@ -5,12 +5,12 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
//! Integration test about setting resources using `apply()`
|
//! Integration test about setting resources using `apply()`
|
||||||
use cgroups::pid::PidController;
|
use cgroups_rs::pid::PidController;
|
||||||
use cgroups::{Cgroup, MaxValue, PidResources, Resources};
|
use cgroups_rs::{Cgroup, MaxValue, PidResources, Resources};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pid_resources() {
|
fn pid_resources() {
|
||||||
let h = cgroups::hierarchies::auto();
|
let h = cgroups_rs::hierarchies::auto();
|
||||||
let cg = Cgroup::new(h, String::from("pid_resources"));
|
let cg = Cgroup::new(h, String::from("pid_resources"));
|
||||||
{
|
{
|
||||||
let res = Resources {
|
let res = Resources {
|
||||||
|
|||||||
Reference in New Issue
Block a user