Browse Source

Prep 235: Make cgroups2 available, hybrid mode already works.

Sven Eden 4 years ago
parent
commit
e68c14bfa4
  1. 6
      meson_options.txt
  2. 43
      src/basic/cgroup-util.c
  3. 2
      src/basic/meson.build
  4. 2
      src/core/cgroup.c
  5. 2
      src/core/mount-setup.c
  6. 4
      src/libelogind/sd-login/test-login.c
  7. 4
      src/test/test-cgroup.c

6
meson_options.txt

@ -155,7 +155,11 @@ option('fallback-hostname', type : 'string', value : 'localhost',
#endif // 0
option('default-hierarchy', type : 'combo',
choices : ['legacy', 'hybrid', 'unified'], value : 'hybrid',
description : 'default cgroup hierarchy')
description : 'default cgroup hierarchy
"legacy" assumes cgroups version 1 mounted on /sys/fs/cgroup
"hybrid" assumes cgroups version 2 mounted on /sys/fs/cgroup/unified and
cgroups version 1 mounted on /sys/fs/cgroup.
"unified" assumes cgroups version 2 on /sys/fs/cgroup')
#if 0 /// UNNEEDED by elogind
# option('time-epoch', type : 'string',
# description : 'time epoch for time clients')

43
src/basic/cgroup-util.c

@ -1037,7 +1037,7 @@ int cg_get_xattr(const char *controller, const char *path, const char *name, voi
int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
_cleanup_fclose_ FILE *f = NULL;
char line[LINE_MAX];
#if 0 // At elogind we do not want that (false alarm) "maybe uninitialized" warning
#if 0 /// At elogind we do not want that (false alarm) "maybe uninitialized" warning
const char *fs, *controller_str;
#else
const char *fs, *controller_str = NULL;
@ -1943,7 +1943,7 @@ int cg_path_get_user_slice(const char *p, char **slice) {
assert(p);
assert(slice);
#if 0 // nothing to skip in elogind
#if 0 /// nothing to skip in elogind
t = skip_user_prefix(p);
if (!t)
return -ENXIO;
@ -2548,7 +2548,6 @@ static int cg_unified_update(void) {
if (statfs("/sys/fs/cgroup/", &fs) < 0)
return -errno;
#if 0 /// UNNEEDED by elogind
if (F_TYPE_EQUAL(fs.f_type, CGROUP2_SUPER_MAGIC))
unified_cache = CGROUP_UNIFIED_ALL;
else if (F_TYPE_EQUAL(fs.f_type, TMPFS_MAGIC)) {
@ -2556,6 +2555,7 @@ static int cg_unified_update(void) {
F_TYPE_EQUAL(fs.f_type, CGROUP2_SUPER_MAGIC)) {
unified_cache = CGROUP_UNIFIED_SYSTEMD;
unified_systemd_v232 = false;
#if 0 /// elogind uses its own name
} else if (statfs("/sys/fs/cgroup/systemd/", &fs) == 0 &&
F_TYPE_EQUAL(fs.f_type, CGROUP2_SUPER_MAGIC)) {
unified_cache = CGROUP_UNIFIED_SYSTEMD;
@ -2563,20 +2563,21 @@ static int cg_unified_update(void) {
} else {
if (statfs("/sys/fs/cgroup/systemd/", &fs) < 0)
return -errno;
#else
} else if (statfs("/sys/fs/cgroup/elogind/", &fs) == 0 &&
F_TYPE_EQUAL(fs.f_type, CGROUP2_SUPER_MAGIC)) {
unified_cache = CGROUP_UNIFIED_SYSTEMD;
unified_systemd_v232 = true;
} else {
if (statfs("/sys/fs/cgroup/elogind/", &fs) < 0)
return -errno;
#endif // 0
if (!F_TYPE_EQUAL(fs.f_type, CGROUP_SUPER_MAGIC))
return -ENOMEDIUM;
unified_cache = CGROUP_UNIFIED_NONE;
}
} else
return -ENOMEDIUM;
#else
/* elogind can not support the unified hierarchy as a controller,
* so always assume a classical hierarchy.
* If, and only *if*, someone really wants to substitute systemd-login
* in an environment managed by systemd with elogind, we might have to
* add such a support. */
unified_cache = CGROUP_UNIFIED_NONE;
#endif // 0
return 0;
}
@ -2594,7 +2595,11 @@ int cg_unified_controller(const char *controller) {
if (unified_cache >= CGROUP_UNIFIED_ALL)
return true;
#if 0 /// only if elogind is the controller we can use cgroups2 in hybrid mode
return streq_ptr(controller, SYSTEMD_CGROUP_CONTROLLER);
#else
return streq_ptr(controller, SYSTEMD_CGROUP_CONTROLLER_HYBRID);
#endif // 0
}
int cg_all_unified(void) {
@ -2666,6 +2671,7 @@ int cg_enable_everywhere(CGroupMask supported, CGroupMask mask, const char *p) {
return 0;
}
#endif // 0
bool cg_is_unified_wanted(void) {
static thread_local int wanted = -1;
@ -2682,9 +2688,11 @@ bool cg_is_unified_wanted(void) {
if (cg_unified_flush() >= 0)
return (wanted = unified_cache >= CGROUP_UNIFIED_ALL);
#if 0 /// elogind is not init and has no business with kernel command line
/* Otherwise, let's see what the kernel command line has to say.
* Since checking is expensive, cache a non-error result. */
r = proc_cmdline_get_bool("systemd.unified_cgroup_hierarchy", &b);
#endif // 0
return (wanted = r > 0 ? b : is_default);
}
@ -2725,25 +2733,16 @@ bool cg_is_hybrid_wanted(void) {
unified_cache == CGROUP_UNIFIED_ALL)
return (wanted = false);
#if 0 /// elogind is not init and has no business with kernel command line
/* Otherwise, let's see what the kernel command line has to say.
* Since checking is expensive, cache a non-error result. */
r = proc_cmdline_get_bool("systemd.legacy_systemd_cgroup_controller", &b);
#endif // 0
/* The meaning of the kernel option is reversed wrt. to the return value
* of this function, hence the negation. */
return (wanted = r > 0 ? !b : is_default);
}
#else
bool cg_is_unified_wanted(void) {
return false;
}
bool cg_is_legacy_wanted(void) {
return true;
}
bool cg_is_hybrid_wanted(void) {
return false;
}
#endif // 0
#if 0 /// UNNEEDED by elogind
int cg_weight_parse(const char *s, uint64_t *ret) {

2
src/basic/meson.build

@ -364,7 +364,7 @@ generate_cap_list = find_program('generate-cap-list.sh')
cap_list_txt = custom_target(
'cap-list.txt',
output : 'cap-list.txt',
#if 0 // elogind needs musl_missing.h, so generate_cap_list must know the source root
#if 0 /// elogind needs musl_missing.h, so generate_cap_list must know the source root
# command : [generate_cap_list, cpp, config_h, missing_h],
#else
command : [generate_cap_list, cpp, meson.source_root(), config_h, missing_h],

2
src/core/cgroup.c

@ -2100,7 +2100,7 @@ void manager_shutdown_cgroup(Manager *m, bool delete) {
if (delete && m->cgroup_root)
(void) cg_trim(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_root, false);
#if 0 /// elogind does not support the unified hierarchy, yet.
#if 0 /// elogind is not init
m->cgroup_empty_event_source = sd_event_source_unref(m->cgroup_empty_event_source);
m->cgroup_inotify_wd_unit = hashmap_free(m->cgroup_inotify_wd_unit);

2
src/core/mount-setup.c

@ -106,11 +106,11 @@ static const MountPoint mount_table[] = {
#endif // 0
{ "tmpfs", "/sys/fs/cgroup", "tmpfs", "mode=755", MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_STRICTATIME,
cg_is_legacy_wanted, MNT_FATAL|MNT_IN_CONTAINER },
#if 0 /// UNNEEDED by elogind
{ "cgroup", "/sys/fs/cgroup/unified", "cgroup2", "nsdelegate", MS_NOSUID|MS_NOEXEC|MS_NODEV,
cg_is_hybrid_wanted, MNT_IN_CONTAINER },
{ "cgroup", "/sys/fs/cgroup/unified", "cgroup2", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV,
cg_is_hybrid_wanted, MNT_IN_CONTAINER },
#if 0 /// UNNEEDED by elogind
{ "cgroup", "/sys/fs/cgroup/systemd", "cgroup", "none,name=systemd,xattr", MS_NOSUID|MS_NOEXEC|MS_NODEV,
cg_is_legacy_wanted, MNT_IN_CONTAINER },
{ "cgroup", "/sys/fs/cgroup/systemd", "cgroup", "none,name=systemd", MS_NOSUID|MS_NOEXEC|MS_NODEV,

4
src/libelogind/sd-login/test-login.c

@ -61,7 +61,7 @@ static void test_login(void) {
uid_t u, u2;
char *t, **seats, **sessions;
#if 0 /// elogind does not support systemd slices
#if 0 /// elogind does not support systemd units
r = sd_pid_get_unit(0, &unit);
assert_se(r >= 0 || r == -ENODATA);
log_info("sd_pid_get_unit(0, …) → \"%s\"", strna(unit));
@ -69,11 +69,11 @@ static void test_login(void) {
r = sd_pid_get_user_unit(0, &user_unit);
assert_se(r >= 0 || r == -ENODATA);
log_info("sd_pid_get_user_unit(0, …) → \"%s\"", strna(user_unit));
#endif // 0
r = sd_pid_get_slice(0, &slice);
assert_se(r >= 0 || r == -ENODATA);
log_info("sd_pid_get_slice(0, …) → \"%s\"", strna(slice));
#endif // 0
r = sd_pid_get_session(0, &session);
if (r < 0) {

4
src/test/test-cgroup.c

@ -54,7 +54,11 @@ int main(int argc, char*argv[]) {
free(path);
assert_se(cg_get_path(SYSTEMD_CGROUP_CONTROLLER, "/test-b/test-d", NULL, &path) == 0);
#if 0 /// elogind uses its own name
assert_se(path_equal(path, "/sys/fs/cgroup/systemd/test-b/test-d"));
#else
assert_se(path_equal(path, "/sys/fs/cgroup/elogind/test-b/test-d"));
#endif // 0
free(path);
assert_se(cg_is_empty(SYSTEMD_CGROUP_CONTROLLER, "/test-a") > 0);

Loading…
Cancel
Save