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>
In older kernel versions (tested with 5.10.208), the cgroup.controllers
files ends with a newline. This newline is not trimmed and as such the
application later can incorrectly consider that the last controller is not
supported
When compiling for a musl target, use the same CGROUP2_SUPER_MAGIC
constant that we use for other linux targets
Signed-off-by: Andrés Medina <andresnrx@gmail.com>
When setting memory.max/memory.swap.max in cgroup v2, Linux uses "max"
instead of "-1" to indicate no restriction on memory usage. The
set_limit and set_memswap_limit functions of the memory controller
accept i64 as a parameter. In cgroupv2, if the parameter is -1, "max"
should be written into the cgroup file.
Fixes#128
Signed-off-by: mengze <mengze@linux.alibaba.com>
Kernel 5.19 introduces `memory.peak` and kernel 6.5 introduces
`memory.swap.peak` to expose the memory and swap usage watermark.
This change use these values to fill `max_usage_in_bytes`.
Signed-off-by: HeRaNO <heran55@126.com>
The included patches are
- 89edba0f85: gha: Bump Rust version to 1.69.0
- 66a93b1c3d: devices: Throw an error if device resources are invalid
- 55505e0b3e: Minor changes for cgroup and devices subsystem
- 0b6b229a38: add .path() method
Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
The changes include:
- Expose `create()` and add `exists()` for `Cgroup`: The changes
are allowed to load cgroup and test if the cgroup exists. If not exists,
performing the `create()` directly to avoid performing `new()`.
- Make path of devices cgroup error more details: The origin path is
either `devices.allow` or `devices.deny`. It not shows which cgroup it
belongs to.
Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
The cgroup-rs should throw errors while setting devices cgroup if the rule
is invalid. For example, if a cgroup has permissions of some devices. Then
we set a `a *:* rwm` to its parent's `devices.deny`. An error should be
thrown to make users realize that it is a invalid rule.
Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>