]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: keep supporting cgroup hybrid layout from v232 for live upgrades
authorTejun Heo <htejun@fb.com>
Wed, 23 Nov 2016 17:27:32 +0000 (12:27 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 20 Feb 2017 17:28:44 +0000 (12:28 -0500)
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

index 6601f16e013900a4f3bfc3a86b40a4e1cb598fc2..9208873d9caa14b7594619f77c3bcaf5892e8c9f 100644 (file)
@@ -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) {