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 `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>
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>
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>
Support to set threaded mode in cgroup v2. The premise of switching to threaded mode is that only the cgroup of cpuset, cpu and pids is supported.
Fixes: #90
Signed-off-by: yaoyinnan <yaoyinnan@foxmail.com>
For some cgroup file operations, when failed, add the path
and the value (for write operation) to the error message.
Fixes: #93
Signed-off-by: bin liu <liubin0329@gmail.com>
Add feature "serde" that derives all resource and statistics types from
Serialize and Deserialize. The feature is turned off by default.
Fixes#54Fixes#55Fixes#56
Signed-off-by: Felix Obenhuber <felix@obenhuber.de>
It should remove the child cgroups recursively
and then remove the parent cgroup, otherwise,
it would remove failed.
Signed-off-by: fupan.lfp <fupan.lfp@antfin.com>
There's so many Duplicated read_string_from method in different
subsystem's implementation, so as read_u64_from/read_i64_from methods.
(1) Move the read_string_from method into `lib.rs`,
called by each subsystem implementation as needed.
(2) Refactor read_u[i]64_from method with the help Rust Generic f
unction `read_from` and wrapped by read_u64_from or read_i64_from.
fix: #20
Signed-off-by: LiYa'nan <oliverliyn@gmail.com>
Delete check_support and stop detecting subsystems by finding in the
root folders because the detecting method is not accurate.
Signed-off-by: Tim Zhang <tim@hyper.sh>
Use idiomatic Option::None to represent optional fields.
This enables updates where not all fields need to be specified.
Signed-off-by: Tim Zhang <tim@hyper.sh>
Customized attributes are useful for customized kernels.
Usage:
let resource = &mut cgroups::Resources::default();
resource.cpu.attrs.insert("cpu.cfs_init_buffer_us", "10".to_string());
// apply here
Signed-off-by: Tim Zhang <tim@hyper.sh>
c_char is equal to i8 on x86, but it is equal to u8 on arm arch,
so we need to use type c_char instead of i8 to avoid compiling error.
Fixes: #9
Signed-off-by: zhanghj <zhanghj.lc@inspur.com>