chiark / gitweb /
Prep 235: Make cgroups2 available, hybrid mode already works.
authorSven Eden <yamakuzure@gmx.net>
Wed, 10 Jan 2018 17:06:23 +0000 (18:06 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 10 Jan 2018 17:06:23 +0000 (18:06 +0100)
meson_options.txt
src/basic/cgroup-util.c
src/basic/meson.build
src/core/cgroup.c
src/core/mount-setup.c
src/libelogind/sd-login/test-login.c
src/test/test-cgroup.c

index d4f6d25b8760a8f56066cc072839f3410e068f4d..6c7eb739fdd837077aae4aa8f0d66b9112d733a6 100644 (file)
@@ -155,7 +155,11 @@ option('fallback-hostname', type : 'string', value : 'localhost',
 #endif // 0
 option('default-hierarchy', type : 'combo',
        choices : ['legacy', 'hybrid', 'unified'], value : 'hybrid',
-       description : 'default cgroup hierarchy')
+       description : 'default cgroup hierarchy
+                "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.
+                "unified" assumes cgroups version 2 on /sys/fs/cgroup')
 #if 0 /// UNNEEDED by elogind
 # option('time-epoch', type : 'string',
 #        description : 'time epoch for time clients')
index 41a33899f991980179f771fcbc278098c76646bd..884589f996502932292a28b03f823afefd648c3d 100644 (file)
@@ -1037,7 +1037,7 @@ int cg_get_xattr(const char *controller, const char *path, const char *name, voi
 int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
         _cleanup_fclose_ FILE *f = NULL;
         char line[LINE_MAX];
-#if 0 // At elogind we do not want that (false alarm) "maybe uninitialized" warning
+#if 0 /// At elogind we do not want that (false alarm) "maybe uninitialized" warning
         const char *fs, *controller_str;
 #else
         const char *fs, *controller_str = NULL;
@@ -1943,7 +1943,7 @@ int cg_path_get_user_slice(const char *p, char **slice) {
         assert(p);
         assert(slice);
 
-#if 0 // nothing to skip in elogind
+#if 0 /// nothing to skip in elogind
         t = skip_user_prefix(p);
         if (!t)
                 return -ENXIO;
@@ -2548,7 +2548,6 @@ static int cg_unified_update(void) {
         if (statfs("/sys/fs/cgroup/", &fs) < 0)
                 return -errno;
 
-#if 0 /// UNNEEDED by elogind
         if (F_TYPE_EQUAL(fs.f_type, CGROUP2_SUPER_MAGIC))
                 unified_cache = CGROUP_UNIFIED_ALL;
         else if (F_TYPE_EQUAL(fs.f_type, TMPFS_MAGIC)) {
@@ -2556,6 +2555,7 @@ static int cg_unified_update(void) {
                     F_TYPE_EQUAL(fs.f_type, CGROUP2_SUPER_MAGIC)) {
                         unified_cache = CGROUP_UNIFIED_SYSTEMD;
                         unified_systemd_v232 = false;
+#if 0 /// elogind uses its own name
                 } else if (statfs("/sys/fs/cgroup/systemd/", &fs) == 0 &&
                            F_TYPE_EQUAL(fs.f_type, CGROUP2_SUPER_MAGIC)) {
                         unified_cache = CGROUP_UNIFIED_SYSTEMD;
@@ -2563,20 +2563,21 @@ static int cg_unified_update(void) {
                 } else {
                         if (statfs("/sys/fs/cgroup/systemd/", &fs) < 0)
                                 return -errno;
+#else
+                } else if (statfs("/sys/fs/cgroup/elogind/", &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/elogind/", &fs) < 0)
+                                return -errno;
+#endif // 0
                         if (!F_TYPE_EQUAL(fs.f_type, CGROUP_SUPER_MAGIC))
                                 return -ENOMEDIUM;
                         unified_cache = CGROUP_UNIFIED_NONE;
                 }
         } else
                 return -ENOMEDIUM;
-#else
-        /* elogind can not support the unified hierarchy as a controller,
-         * so always assume a classical hierarchy.
-         * If, and only *if*, someone really wants to substitute systemd-login
-         * in an environment managed by systemd with elogind, we might have to
-         * add such a support. */
-        unified_cache = CGROUP_UNIFIED_NONE;
-#endif // 0
 
         return 0;
 }
@@ -2594,7 +2595,11 @@ int cg_unified_controller(const char *controller) {
         if (unified_cache >= CGROUP_UNIFIED_ALL)
                 return true;
 
+#if 0 /// only if elogind is the controller we can use cgroups2 in hybrid mode
         return streq_ptr(controller, SYSTEMD_CGROUP_CONTROLLER);
+#else
+        return streq_ptr(controller, SYSTEMD_CGROUP_CONTROLLER_HYBRID);
+#endif // 0
 }
 
 int cg_all_unified(void) {
@@ -2666,6 +2671,7 @@ int cg_enable_everywhere(CGroupMask supported, CGroupMask mask, const char *p) {
 
         return 0;
 }
+#endif // 0
 
 bool cg_is_unified_wanted(void) {
         static thread_local int wanted = -1;
@@ -2682,9 +2688,11 @@ bool cg_is_unified_wanted(void) {
         if (cg_unified_flush() >= 0)
                 return (wanted = unified_cache >= CGROUP_UNIFIED_ALL);
 
+#if 0 /// elogind is not init and has no business with kernel command line
         /* 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);
 }
@@ -2725,25 +2733,16 @@ bool cg_is_hybrid_wanted(void) {
             unified_cache == CGROUP_UNIFIED_ALL)
                 return (wanted = false);
 
+#if 0 /// elogind is not init and has no business with kernel command line
         /* 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
-bool cg_is_unified_wanted(void) {
-        return false;
-}
-bool cg_is_legacy_wanted(void) {
-        return true;
-}
-bool cg_is_hybrid_wanted(void) {
-        return false;
-}
-#endif // 0
 
 #if 0 /// UNNEEDED by elogind
 int cg_weight_parse(const char *s, uint64_t *ret) {
index ca4db60f7ceac0649aa1c16dbcecdd16d1bb3990..5cdc316d21cc15eba1e125c3085d5d616d90a39b 100644 (file)
@@ -364,7 +364,7 @@ generate_cap_list = find_program('generate-cap-list.sh')
 cap_list_txt = custom_target(
         'cap-list.txt',
         output : 'cap-list.txt',
-#if 0 // elogind needs musl_missing.h, so generate_cap_list must know the source root
+#if 0 /// elogind needs musl_missing.h, so generate_cap_list must know the source root
 #         command : [generate_cap_list, cpp, config_h, missing_h],
 #else
         command : [generate_cap_list, cpp, meson.source_root(), config_h, missing_h],
index 664defceb8980a60d28c648b1671886eafa69352..dd6faf493ea90217d58e3abb04a268057d1c2194 100644 (file)
@@ -2100,7 +2100,7 @@ void manager_shutdown_cgroup(Manager *m, bool delete) {
         if (delete && m->cgroup_root)
                 (void) cg_trim(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_root, false);
 
-#if 0 /// elogind does not support the unified hierarchy, yet.
+#if 0 /// elogind is not init
         m->cgroup_empty_event_source = sd_event_source_unref(m->cgroup_empty_event_source);
 
         m->cgroup_inotify_wd_unit = hashmap_free(m->cgroup_inotify_wd_unit);
index f9e476a012c086c09d5447ab34ec1bfd6af0423c..bd979bcee6adbf184f2e75a2da66efe74709ab03 100644 (file)
@@ -106,11 +106,11 @@ static const MountPoint mount_table[] = {
 #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 },
-#if 0 /// UNNEEDED by elogind
         { "cgroup",      "/sys/fs/cgroup/unified",    "cgroup2",    "nsdelegate",              MS_NOSUID|MS_NOEXEC|MS_NODEV,
           cg_is_hybrid_wanted, MNT_IN_CONTAINER },
         { "cgroup",      "/sys/fs/cgroup/unified",    "cgroup2",    NULL,                      MS_NOSUID|MS_NOEXEC|MS_NODEV,
           cg_is_hybrid_wanted, MNT_IN_CONTAINER },
+#if 0 /// UNNEEDED by elogind
         { "cgroup",      "/sys/fs/cgroup/systemd",    "cgroup",     "none,name=systemd,xattr", MS_NOSUID|MS_NOEXEC|MS_NODEV,
           cg_is_legacy_wanted, MNT_IN_CONTAINER     },
         { "cgroup",      "/sys/fs/cgroup/systemd",    "cgroup",     "none,name=systemd",       MS_NOSUID|MS_NOEXEC|MS_NODEV,
index d874677094019964144f43024f129fb15b3aabc7..3b5e50c343e47f35216abc5cd01c7b8bfe8173fa 100644 (file)
@@ -61,7 +61,7 @@ static void test_login(void) {
         uid_t u, u2;
         char *t, **seats, **sessions;
 
-#if 0 /// elogind does not support systemd slices
+#if 0 /// elogind does not support systemd units
         r = sd_pid_get_unit(0, &unit);
         assert_se(r >= 0 || r == -ENODATA);
         log_info("sd_pid_get_unit(0, …) → \"%s\"", strna(unit));
@@ -69,11 +69,11 @@ static void test_login(void) {
         r = sd_pid_get_user_unit(0, &user_unit);
         assert_se(r >= 0 || r == -ENODATA);
         log_info("sd_pid_get_user_unit(0, …) → \"%s\"", strna(user_unit));
+#endif // 0
 
         r = sd_pid_get_slice(0, &slice);
         assert_se(r >= 0 || r == -ENODATA);
         log_info("sd_pid_get_slice(0, …) → \"%s\"", strna(slice));
-#endif // 0
 
         r = sd_pid_get_session(0, &session);
         if (r < 0) {
index 509946250840106abb0da00d39262653ee9b7a7b..e56473a630fc9b66554d2b842ea390032d2de0d0 100644 (file)
@@ -54,7 +54,11 @@ int main(int argc, char*argv[]) {
         free(path);
 
         assert_se(cg_get_path(SYSTEMD_CGROUP_CONTROLLER, "/test-b/test-d", NULL, &path) == 0);
+#if 0 /// elogind uses its own name
         assert_se(path_equal(path, "/sys/fs/cgroup/systemd/test-b/test-d"));
+#else
+        assert_se(path_equal(path, "/sys/fs/cgroup/elogind/test-b/test-d"));
+#endif // 0
         free(path);
 
         assert_se(cg_is_empty(SYSTEMD_CGROUP_CONTROLLER, "/test-a") > 0);