From f08e9287200772c9a201d9f988dd78ffe2fc7ea4 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Wed, 23 Nov 2016 12:27:32 -0500 Subject: [PATCH] core: keep supporting cgroup hybrid layout from v232 for live upgrades v232's cgroup hybrid mode mounted v2 on /sys/fs/cgroup/systemd, which unfortunately broke other tools which expect v1 there. From v233 on, hybrid mode instead mounts and uses v2 on /sys/fs/cgroup/unified and keeps /sys/fs/cgroup/systemd on v1 for compatibility with external tools. However, to keep systemd live upgrades working, v233+ should be able to recognize v232 layout and keep using it. This patch adds v232 hybrid mode support. If v232 layout is detected, cg_unified(SYSTEMD_CGRouP_CONTROLLER) keeps returning %true but cg_hybrid_unified() returns %false. This keeps process management on cgroup v2 but turns off the parallel layout. --- src/basic/cgroup-util.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 6601f16e01..9208873d9c 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -2283,6 +2283,20 @@ int cg_kernel_controllers(Set *controllers) { static thread_local CGroupUnified unified_cache = CGROUP_UNIFIED_UNKNOWN; +/* The hybrid mode was initially implemented in v232 and simply mounted + * cgroup v2 on /sys/fs/cgroup/systemd. This unfortunately broke other + * tools (such as docker) which expected the v1 "name=systemd" hierarchy + * on /sys/fs/cgroup/systemd. From v233 and on, the hybrid mode mountnbs + * v2 on /sys/fs/cgroup/unified and maintains "name=systemd" hierarchy + * on /sys/fs/cgroup/systemd for compatibility with other tools. + * + * To keep live upgrade working, we detect and support v232 layout. When + * v232 layout is detected, to keep cgroup v2 process management but + * disable the compat dual layout, we return %true on + * cg_unified(SYSTEMD_CGROUP_CONTROLLER) and %false on cg_hybrid_unified(). + */ +static thread_local bool unified_systemd_v232; + static int cg_update_unified(void) { struct statfs fs; @@ -2302,9 +2316,14 @@ static int cg_update_unified(void) { unified_cache = CGROUP_UNIFIED_ALL; else if (F_TYPE_EQUAL(fs.f_type, TMPFS_MAGIC)) { if (statfs("/sys/fs/cgroup/unified/", &fs) == 0 && - F_TYPE_EQUAL(fs.f_type, CGROUP2_SUPER_MAGIC)) + F_TYPE_EQUAL(fs.f_type, CGROUP2_SUPER_MAGIC)) { unified_cache = CGROUP_UNIFIED_SYSTEMD; - else { + unified_systemd_v232 = false; + } else if (statfs("/sys/fs/cgroup/systemd/", &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/systemd/", &fs) < 0) return -errno; if (!F_TYPE_EQUAL(fs.f_type, CGROUP_SUPER_MAGIC)) @@ -2336,7 +2355,7 @@ bool cg_hybrid_unified(void) { assert(cg_update_unified() >= 0); - return unified_cache == CGROUP_UNIFIED_SYSTEMD; + return unified_cache == CGROUP_UNIFIED_SYSTEMD && !unified_systemd_v232; } int cg_unified_flush(void) {