From: Zbigniew Jędrzejewski-Szmek Date: Sun, 19 Feb 2017 20:59:21 +0000 (-0500) Subject: core/mount-setup: if unified hierarchy is not supported, fall back to legacy X-Git-Tag: v233.3~49 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=d2fee9031f20cefd32465836193982f5382baebc core/mount-setup: if unified hierarchy is not supported, fall back to legacy We need this to gracefully support older or strangely configured kernels. v2: - do not install a callback handler, just embed the right conditions into cg_is_*_wanted() v3: - fix bug in cg_is_legacy_wanted() --- diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index ad4122353..0079ff9a4 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -2495,7 +2495,14 @@ bool cg_is_unified_wanted(void) { } bool cg_is_legacy_wanted(void) { - return !cg_is_unified_wanted(); + /* Check if we have cgroups2 already mounted. */ + if (cg_unified_flush() >= 0 && + unified_cache == CGROUP_UNIFIED_ALL) + return false; + + /* Otherwise, assume that at least partial legacy is wanted, + * since cgroups2 should already be mounted at this point. */ + return true; } bool cg_is_hybrid_wanted(void) { @@ -2504,11 +2511,6 @@ bool cg_is_hybrid_wanted(void) { bool b; const bool is_default = DEFAULT_HIERARCHY == CGROUP_UNIFIED_SYSTEMD; - /* If the unified hierarchy is requested in full, no need to - * bother with this. */ - if (cg_is_unified_wanted()) - return 0; - /* If the hierarchy is already mounted, then follow whatever * was chosen for it. */ if (cg_unified_flush() >= 0) diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c index 694a03cc8..d8140bea9 100644 --- a/src/core/mount-setup.c +++ b/src/core/mount-setup.c @@ -100,7 +100,7 @@ static const MountPoint mount_table[] = { { "tmpfs", "/run", "tmpfs", "mode=755", MS_NOSUID|MS_NODEV|MS_STRICTATIME, NULL, MNT_FATAL|MNT_IN_CONTAINER }, { "cgroup", "/sys/fs/cgroup", "cgroup2", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV, - cg_is_unified_wanted, MNT_FATAL|MNT_IN_CONTAINER }, + cg_is_unified_wanted, MNT_IN_CONTAINER }, #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 }, @@ -114,10 +114,9 @@ static const MountPoint mount_table[] = { { "cgroup", "/sys/fs/cgroup/elogind", "cgroup", "none,name=elogind,xattr", MS_NOSUID|MS_NOEXEC|MS_NODEV, cg_is_legacy_wanted, MNT_IN_CONTAINER }, { "cgroup", "/sys/fs/cgroup/elogind", "cgroup", "none,name=elogind", MS_NOSUID|MS_NOEXEC|MS_NODEV, - cg_is_legacy_wanted, MNT_IN_CONTAINER }, #endif // 0 + cg_is_legacy_wanted, MNT_IN_CONTAINER }, #if 0 /// UNNEEDED by elogind - cg_is_legacy_wanted, MNT_FATAL|MNT_IN_CONTAINER }, { "pstore", "/sys/fs/pstore", "pstore", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV, NULL, MNT_NONE }, #ifdef ENABLE_EFI