Run the complete test suite in pinned Ubuntu guests so cgroupfs and
systemd coverage does not depend on the GitHub runner's hierarchy.
Cross-compile static test binaries on the host to keep TCG execution
practical.
Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
Resolve cgroup filesystem paths according to the active hierarchy and
assert systemd's expected cgroup v1 limitations. This lets the existing
manager and D-Bus tests run in both guest modes without changing library
behavior.
Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
There used to be a race condition while creating the cgroup hierarchy:
if a parent directory was created after .exists() but before
.create_dir, the function failed unnecessarily.
This commit changes the function to use create_dir_all, which is the
atomic variant of the above pattern, and fixes some surrounding
docstrings on the way.
Signed-off-by: Markus Rudy <mr@edgeless.systems>
New zbus and zvariant releases require a newer Rust compiler.
Use Rust 1.90.0 in CI so dependency resolution can complete.
Signed-off-by: Tim Zhang <tim@hyper.sh>
cgroups-rs exposes oci-spec types in its public API (e.g.
Manager::set() takes &LinuxResources), so the version pinned here
dictates which oci-spec version every consumer must use: 0.x lines
are semver-incompatible, and a consumer on a newer oci-spec gets
"expected LinuxResources, found LinuxResources" type mismatches.
Kata Containers is moving its workspace to oci-spec 0.10.0 and
cannot call into cgroups-rs until this crate follows. The 0.8 to
0.10 changes are additive for everything cgroups-rs touches (no
code changes needed): the crate builds warning-free with the oci
feature and the unit tests pass (the only failures are the
pre-existing fs manager tests that need root to write cgroupfs).
Signed-off-by: Zvonko Kaiser <zkaiser@nvidia.com>
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
Fixed an error hidden during the creation of cgroup,
which resulted in subsequent error propagation
Signed-off-by: jokemanfire <hu.dingyang@zte.com.cn>
The systemd version is purely informational and should not be parsed, as
documented in the [1]. In practice, systemd version has different formats
on OpenShift and Ubuntu.
This commit skips the version check and allows all operations. The errors
will be thrown from dbus when performing unsupported operations on obsolete
versions of systemd.
1: https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.systemd1.html
Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
The tests cover the methods of `conv` mod, `FsManager`, and
`SystemdManager`. Since we have to manipulate the cgroups during testing,
the tests related to this part are set to be run in sequence.
Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
The tests cover `SystemdClient` and methods from `utils` mods.
Please note that the `SystemdClient` tests do not run well in parallel, but
work well in sequence. Please run them with `--test-threads=1`.
Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
Systemd manager takes cgroups path in the format of
"parent:scope_prefix:name" to create and manipulate cgroups through
systemd. It does value conversions for resources defined in the Linux
resources from the OCI spec, such as CPU quota, period, etc.
Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
`SystemdCgroup` takes a `parent`, which is the name of a slice, and a
`unit`, which is the name of a slice or a scope unit, and provides methods
to start, kill the unit, as well as set properties for the unit.
The mods, `cpu`, `memory`, `cpuset`, and `pids`, are designed to generate
properties quickly. It hides the difference between cgroups v1 and v2, and
does simple checks for the systemd version and arguments.
Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
`Manager` is a trait to unify the interface of cgroups. It is designed for
OCI containers. Its `set()` takes Linux resources of the OCI spec to set
cgroups.
The `FsManager`, the concrete implementation of `Manager`, manipulates
cgroups through cgroupfs, and supports both cgroups v1 and v2.
Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
Prepare to implement FsManager, which should be done in the following-up
commits. Apart from that, no code is not modified.
Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
The cargo complaints that ".cargo/config" is deprecated in favor of
".cargo/config.toml". Therefore, the file is renamed to it to make cargo
happy.
Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
Most of the issues are small, but `fold()`. The usage of `fold()` in these
cases confuses me a lot, so that I don't follow the sugguestions from
clippy to replace `fold()` with `try_fold()`. Instead, I replace them with
`map() + collect()`.
Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
Rust 1.69.0, released in 2023, lags significantly behind the version used
by Kata Containers. Therefore, we bump it to 1.85.1.
Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
This removes the only place the regex crate is used, which could lead to significant binary size savings in projects that don't use the regex craate.
Signed-off-by: Oguz Bilgener <oguz@bilgener.me>
The documentation in the hierarchies module is outdated, this project
does support cgroups2 and the unified hierarchy :)
Signed-off-by: Michel Heily <michelheily@gmail.com>
There are several fixes since the last release, and itś been a few years
waiting for a new one.
Signed-off-by: Fabiano Fidêncio <fidencio@northflank.com>
I'm not fmiliar with this crate, so let's just ignore the warning for
now instead of removing the code.
Signed-off-by: Fabiano Fidêncio <fidencio@northflank.com>
Path of cgroup is wrong when running a container in a container. Use
the root path of mountinfo fetched from /proc/$(shim_pid)/mountinfo
to trim the path obtained from /proc/self/mountinfo.
Fixes: #131
Signed-off-by: 乔琛 10307740 <qiao.chen@zte.com.cn>