chiark / gitweb /
util-lib: rename CHASE_NON_EXISTING → CHASE_NONEXISTENT
[elogind.git] / src / basic / cgroup-util.c
index 323720caef49797a6cd33c5f103f4f8a488846c5..1c26c7f8ffd12469125f6a8ef073d6893add66f7 100644 (file)
@@ -2339,6 +2339,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;
@@ -2359,9 +2373,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))
@@ -2402,7 +2421,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) {
@@ -2509,6 +2528,11 @@ bool cg_is_legacy_wanted(void) {
         /* The meaning of the kernel option is reversed wrt. to the return value
          * of this function, hence the negation. */
         return (wanted = r > 0 ? !b : false);
+        return (wanted = r > 0 ? b : false);
+}
+
+bool cg_is_legacy_systemd_controller_wanted(void) {
+        return cg_is_legacy_wanted() && !cg_is_unified_systemd_controller_wanted();
 }
 #endif // 0