diff options
author | Michal Sekletár <msekleta@redhat.com> | 2020-04-29 17:53:43 +0200 |
---|---|---|
committer | Michal Sekletár <msekleta@redhat.com> | 2020-04-30 19:02:51 +0200 |
commit | d9e45bc3abb8adf5a1cb20816ba8f2d2aa65b17e (patch) | |
tree | 7c7dcdd6e921fc80e1026915c8df2eee3b5f7d71 /src/basic/cgroup-util.c | |
parent | 25a1f04c682260bb9b96e25bdf33665d6172db98 (diff) | |
download | systemd-d9e45bc3abb8adf5a1cb20816ba8f2d2aa65b17e.tar.gz |
core: introduce support for cgroup freezer
With cgroup v2 the cgroup freezer is implemented as a cgroup
attribute called cgroup.freeze. cgroup can be frozen by writing "1"
to the file and kernel will send us a notification through
"cgroup.events" after the operation is finished and processes in the
cgroup entered quiescent state, i.e. they are not scheduled to
run. Writing "0" to the attribute file does the inverse and process
execution is resumed.
This commit exposes above low-level functionality through systemd's DBus
API. Each unit type must provide specialized implementation for these
methods, otherwise, we return an error. So far only service, scope, and
slice unit types provide the support. It is possible to check if a
given unit has the support using CanFreeze() DBus property.
Note that DBus API has a synchronous behavior and we dispatch the reply
to freeze/thaw requests only after the kernel has notified us that
requested operation was completed.
Diffstat (limited to 'src/basic/cgroup-util.c')
-rw-r--r-- | src/basic/cgroup-util.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index da4bd33d18..e94fcfad02 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -149,6 +149,17 @@ bool cg_ns_supported(void) { return enabled; } +bool cg_freezer_supported(void) { + static thread_local int supported = -1; + + if (supported >= 0) + return supported; + + supported = cg_all_unified() > 0 && access("/sys/fs/cgroup/init.scope/cgroup.freeze", F_OK) == 0; + + return supported; +} + int cg_enumerate_subgroups(const char *controller, const char *path, DIR **_d) { _cleanup_free_ char *fs = NULL; int r; @@ -1702,7 +1713,8 @@ int cg_get_keyed_attribute_full( * all keys to retrieve. The 'ret_values' parameter should be passed as string size with the same number of * entries as 'keys'. On success each entry will be set to the value of the matching key. * - * If the attribute file doesn't exist at all returns ENOENT, if any key is not found returns ENXIO. */ + * If the attribute file doesn't exist at all returns ENOENT, if any key is not found returns ENXIO. If mode + * is set to GG_KEY_MODE_GRACEFUL we ignore missing keys and return those that were parsed successfully. */ r = cg_get_path(controller, path, attribute, &filename); if (r < 0) @@ -1752,8 +1764,8 @@ int cg_get_keyed_attribute_full( if (mode & CG_KEY_MODE_GRACEFUL) goto done; - else - r = -ENXIO; + + r = -ENXIO; fail: for (i = 0; i < n; i++) |