Skip to content

Commit fefbdc8

Browse files
authored
Merge pull request #148 from kata-containers/manager
Introduce FsManager and SystemdManager
2 parents 6e273cd + c774e9e commit fefbdc8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+5893
-1168
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ nix = { version = "0.25.0", default-features = false, features = ["event", "fs",
1717
libc = "0.2"
1818
serde = { version = "1.0", features = ["derive"], optional = true }
1919
thiserror = "1"
20+
oci-spec = { version = "0.8.1", optional = true }
21+
zbus = "5.8"
22+
bit-vec = "0.6"
2023

2124
[dev-dependencies]
2225
libc = "0.2.76"
26+
rand = "0.8"
27+
nix = "0.25"
2328

2429
[features]
2530
default = []
31+
oci = ["oci-spec"]

Makefile

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,37 @@ build: debug
1919
# Tests and linters
2020
#
2121

22-
.PHONY: test
23-
test:
24-
cargo test -- --color always --nocapture
22+
# Tests that manipulate cgroups should run in sequence, so that
23+
# `--test-threads=1` is used.
24+
test: test-systemd test-fs-manager test-systemd-manager
25+
cargo test --all-features -- --color always \
26+
--nocapture \
27+
--skip systemd::dbus::client::tests \
28+
--skip manager::fs::tests \
29+
--skip manager::systemd::tests
30+
31+
.PHONY: test-systemd
32+
# Tests that manipulate cgroups should run in sequence, so that
33+
# `--test-threads=1` is used.
34+
test-systemd:
35+
cargo test --package cgroups-rs --lib \
36+
-- systemd::dbus::client::tests \
37+
--color always --nocapture \
38+
--test-threads=1
39+
40+
.PHONY: test-fs-manager
41+
# See test-systemd
42+
test-fs-manager:
43+
cargo test --all-features --package cgroups-rs \
44+
--lib -- manager::fs::tests \
45+
--color always --nocapture --test-threads=1
46+
47+
.PHONY: test-systemd-manager
48+
# See test-systemd
49+
test-systemd-manager:
50+
cargo test --all-features --package cgroups-rs \
51+
--lib -- manager::systemd::tests \
52+
--color always --nocapture --test-threads=1
2553

2654
.PHONY: check
2755
check: fmt clippy

src/blkio.rs renamed to src/fs/blkio.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
use std::io::Write;
1212
use std::path::PathBuf;
1313

14-
use crate::error::ErrorKind::*;
15-
use crate::error::*;
14+
use crate::fs::error::ErrorKind::*;
15+
use crate::fs::error::*;
1616

17-
use crate::{read_string_from, read_u64_from};
18-
use crate::{
17+
use crate::fs::{read_string_from, read_u64_from};
18+
use crate::fs::{
1919
BlkIoResources, ControllIdentifier, ControllerInternal, Controllers, CustomizedAttribute,
2020
Resources, Subsystem,
2121
};
@@ -829,9 +829,9 @@ impl BlkIoController {
829829
impl CustomizedAttribute for BlkIoController {}
830830
#[cfg(test)]
831831
mod test {
832-
use crate::blkio::{parse_blkio_data, BlkIoData};
833-
use crate::blkio::{parse_io_service, parse_io_service_total, IoService};
834-
use crate::error::*;
832+
use crate::fs::blkio::{parse_blkio_data, BlkIoData};
833+
use crate::fs::blkio::{parse_io_service, parse_io_service_total, IoService};
834+
use crate::fs::error::*;
835835

836836
static TEST_VALUE: &str = "\
837837
8:32 Read 4280320

src/cgroup.rs renamed to src/fs/cgroup.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
//! This module handles cgroup operations. Start here!
88
9-
use crate::error::ErrorKind::*;
10-
use crate::error::*;
9+
use crate::fs::error::ErrorKind::*;
10+
use crate::fs::error::*;
1111

12-
use crate::hierarchies::V1;
13-
use crate::{CgroupPid, ControllIdentifier, Controller, Hierarchy, Resources, Subsystem};
12+
use crate::fs::hierarchies::V1;
13+
use crate::fs::{CgroupPid, ControllIdentifier, Controller, Hierarchy, Resources, Subsystem};
1414

1515
use std::collections::HashMap;
1616
use std::convert::From;
@@ -51,7 +51,7 @@ impl Clone for Cgroup {
5151
fn clone(&self) -> Self {
5252
Cgroup {
5353
subsystems: self.subsystems.clone(),
54-
hier: crate::hierarchies::auto(),
54+
hier: crate::fs::hierarchies::auto(),
5555
path: self.path.clone(),
5656
specified_controllers: None,
5757
}
@@ -62,7 +62,7 @@ impl Default for Cgroup {
6262
fn default() -> Self {
6363
Cgroup {
6464
subsystems: Vec::new(),
65-
hier: crate::hierarchies::auto(),
65+
hier: crate::fs::hierarchies::auto(),
6666
path: "".to_string(),
6767
specified_controllers: None,
6868
}

src/cgroup_builder.rs renamed to src/fs/cgroup_builder.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
//! by a call to `build()`.
1717
//!
1818
//! ```rust,no_run
19-
//! # use cgroups_rs::*;
20-
//! # use cgroups_rs::devices::*;
21-
//! # use cgroups_rs::cgroup_builder::*;
22-
//! let h = cgroups_rs::hierarchies::auto();
19+
//! # use cgroups_rs::fs::*;
20+
//! # use cgroups_rs::fs::devices::*;
21+
//! # use cgroups_rs::fs::cgroup_builder::*;
22+
//! let h = cgroups_rs::fs::hierarchies::auto();
2323
//! let cgroup: Cgroup = CgroupBuilder::new("hello")
2424
//! .memory()
2525
//! .kernel_memory_limit(1024 * 1024)
@@ -60,7 +60,7 @@
6060
//! .build(h).unwrap();
6161
//! ```
6262
63-
use crate::{
63+
use crate::fs::{
6464
BlkIoDeviceResource, BlkIoDeviceThrottleResource, Cgroup, DeviceResource, Error, Hierarchy,
6565
HugePageResource, MaxValue, NetworkPriority, Resources,
6666
};
@@ -250,9 +250,9 @@ impl DeviceResourceBuilder {
250250
mut self,
251251
major: i64,
252252
minor: i64,
253-
devtype: crate::devices::DeviceType,
253+
devtype: crate::fs::devices::DeviceType,
254254
allow: bool,
255-
access: Vec<crate::devices::DevicePermissions>,
255+
access: Vec<crate::fs::devices::DevicePermissions>,
256256
) -> DeviceResourceBuilder {
257257
self.cgroup.resources.devices.devices.push(DeviceResource {
258258
allow,

src/cpu.rs renamed to src/fs/cpu.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ use std::fs::File;
1313
use std::io::{Read, Write};
1414
use std::path::PathBuf;
1515

16-
use crate::error::ErrorKind::*;
17-
use crate::error::*;
18-
use crate::{parse_max_value, read_i64_from, read_u64_from};
16+
use crate::fs::error::ErrorKind::*;
17+
use crate::fs::error::*;
18+
use crate::fs::{parse_max_value, read_i64_from, read_u64_from};
1919

20-
use crate::{
20+
use crate::fs::{
2121
ControllIdentifier, ControllerInternal, Controllers, CpuResources, CustomizedAttribute,
2222
MaxValue, Resources, Subsystem,
2323
};

src/cpuacct.rs renamed to src/fs/cpuacct.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
use std::io::Write;
1111
use std::path::PathBuf;
1212

13-
use crate::error::ErrorKind::*;
14-
use crate::error::*;
13+
use crate::fs::error::ErrorKind::*;
14+
use crate::fs::error::*;
1515

16-
use crate::{read_string_from, read_u64_from};
17-
use crate::{ControllIdentifier, ControllerInternal, Controllers, Resources, Subsystem};
16+
use crate::fs::{read_string_from, read_u64_from};
17+
use crate::fs::{ControllIdentifier, ControllerInternal, Controllers, Resources, Subsystem};
1818

1919
/// A controller that allows controlling the `cpuacct` subsystem of a Cgroup.
2020
///

src/cpuset.rs renamed to src/fs/cpuset.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ use log::*;
1313
use std::io::Write;
1414
use std::path::PathBuf;
1515

16-
use crate::error::ErrorKind::*;
17-
use crate::error::*;
16+
use crate::fs::error::ErrorKind::*;
17+
use crate::fs::error::*;
1818

19-
use crate::{read_string_from, read_u64_from};
20-
use crate::{
19+
use crate::fs::{read_string_from, read_u64_from};
20+
use crate::fs::{
2121
ControllIdentifier, ControllerInternal, Controllers, CpuResources, Resources, Subsystem,
2222
};
2323

@@ -591,7 +591,7 @@ impl CpuSetController {
591591

592592
#[cfg(test)]
593593
mod tests {
594-
use crate::cpuset;
594+
use crate::fs::cpuset;
595595
#[test]
596596
fn test_parse_range() {
597597
let test_cases = vec![

src/devices.rs renamed to src/fs/devices.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use std::path::PathBuf;
1212

1313
use log::*;
1414

15-
use crate::error::ErrorKind::*;
16-
use crate::error::*;
15+
use crate::fs::error::ErrorKind::*;
16+
use crate::fs::error::*;
1717

18-
use crate::{
18+
use crate::fs::{
1919
ControllIdentifier, ControllerInternal, Controllers, DeviceResource, DeviceResources,
2020
Resources, Subsystem,
2121
};
File renamed without changes.

0 commit comments

Comments
 (0)