From: Sven Eden Date: Wed, 20 Jun 2018 17:13:05 +0000 (+0200) Subject: Fix cgroup directory mounting: X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=f0a7917bc8ea0ba859e10093517e33f2bad78f10;p=elogind.git Fix cgroup directory mounting: A little misunderstanding has been fixed, and elogind now mounts the following directories, if (and only if) it has to act as its own cgroups controller. * -Ddefault-hierarchy=legacy : /sys/fs/cgroup as tmpfs /sys/fs/cgroup/elogind as cgroup * -Ddefault-hierarchy=hybrid : The same as with 'legacy', plus /sys/fs/cgroup/unified as cgroup2 * -Ddefault-hierarchy=unified : /sys/fs/cgroup2 as cgroup2 --- diff --git a/meson_options.txt b/meson_options.txt index 0fa3f1896..84100b629 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -189,9 +189,10 @@ option('default-hierarchy', type : 'combo', # description : 'time epoch for time clients') #else description : '''Wanted cgroup hierarchy if elogind has to be a cgroup controller: - "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. + "legacy" assumes tmpfs mounted on /sys/fs/cgroup and cgroup on its + subfolders. + "hybrid" assumes cgroups version 2 mounted on /sys/fs/cgroup/unified. + /sys/fs/cgroup is legacy, then. "unified" assumes cgroups version 2 on /sys/fs/cgroup''') option('cgroup-controller', type : 'string', description : 'Name of the cgroup controller to use') diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index fa9275043..4fc542cc8 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -2740,8 +2740,10 @@ int cg_enable_everywhere(CGroupMask supported, CGroupMask mask, const char *p) { bool cg_is_unified_wanted(void) { static thread_local int wanted = -1; +#if 0 /// UNNEEDED by elogind int r; bool b; +#endif // 0 const bool is_default = DEFAULT_HIERARCHY == CGROUP_UNIFIED_ALL; /* If we have a cached value, return that. */ @@ -2757,9 +2759,11 @@ bool cg_is_unified_wanted(void) { /* 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); +#else + return is_default; +#endif // 0 } bool cg_is_legacy_wanted(void) { @@ -2781,8 +2785,10 @@ bool cg_is_legacy_wanted(void) { bool cg_is_hybrid_wanted(void) { static thread_local int wanted = -1; +#if 0 /// UNNEEDED by elogind int r; bool b; +#endif // 0 const bool is_default = DEFAULT_HIERARCHY >= CGROUP_UNIFIED_SYSTEMD; /* We default to true if the default is "hybrid", obviously, * but also when the default is "unified", because if we get @@ -2802,11 +2808,13 @@ bool cg_is_hybrid_wanted(void) { /* 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 + return is_default; +#endif // 0 } #if 0 /// UNNEEDED by elogind diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c index 0b41e26e6..f08abb640 100644 --- a/src/core/mount-setup.c +++ b/src/core/mount-setup.c @@ -103,11 +103,11 @@ static const MountPoint mount_table[] = { #endif { "tmpfs", "/run", "tmpfs", "mode=755", MS_NOSUID|MS_NODEV|MS_STRICTATIME, NULL, MNT_FATAL|MNT_IN_CONTAINER }, +#endif // 0 { "cgroup2", "/sys/fs/cgroup", "cgroup2", "nsdelegate", MS_NOSUID|MS_NOEXEC|MS_NODEV, cg_is_unified_wanted, MNT_IN_CONTAINER|MNT_CHECK_WRITABLE }, { "cgroup2", "/sys/fs/cgroup", "cgroup2", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV, cg_is_unified_wanted, MNT_IN_CONTAINER|MNT_CHECK_WRITABLE }, -#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 }, { "cgroup2", "/sys/fs/cgroup/unified", "cgroup2", "nsdelegate", MS_NOSUID|MS_NOEXEC|MS_NODEV, @@ -130,7 +130,7 @@ static const MountPoint mount_table[] = { #else { "cgroup", "/sys/fs/cgroup/elogind", "cgroup", "none,name=elogind,release_agent="SYSTEMD_CGROUP_AGENT_PATH",xattr", MS_NOSUID|MS_NOEXEC|MS_NODEV, cg_is_legacy_wanted, MNT_IN_CONTAINER }, - { "cgroup", "/sys/fs/cgroup/elogind", "cgroup", "none,name=elogind,release_agent="SYSTEMD_CGROUP_AGENT_PATH, MS_NOSUID|MS_NOEXEC|MS_NODEV, + { "cgroup", "/sys/fs/cgroup/eloignd", "cgroup", "none,name=elogind,release_agent="SYSTEMD_CGROUP_AGENT_PATH, MS_NOSUID|MS_NOEXEC|MS_NODEV, cg_is_legacy_wanted, MNT_FATAL|MNT_IN_CONTAINER }, #endif // 0 };