diff options
author | Luke Shumaker <lukeshu@parabola.nu> | 2017-07-07 01:20:02 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-09-13 14:17:43 -0400 |
commit | 740f9648fc6efa5ff1327a16e122f4138a38cebe (patch) | |
tree | 06eba34a03ac2cd951abe88254acac6e7b8b7ad1 | |
parent | 2278c88fdc2b95de4fe2ff8f34479e60d5efb689 (diff) |
cgroup-util: Merge the unified_cache and unified_systemd_v232 caches
Conceptually, the addition of bool unified_systemd_v232 split
CGROUP_UNIFIED_SYSTEMD in to two separate values. So, split it.
The "tricky" part is when to switch the old CGROUP_UNIFIED_SYSTEMD to
CGROUP_UNIFIED_SYSTEMD232 and when to switch it to
CGROUP_UNIFIED_SYSTEMD233. All ">= CGROUP_UNIFIED_SYSTEMD" checks go to
232, since that preserves the existing behavior.
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | meson.build | 2 | ||||
-rw-r--r-- | src/basic/cgroup-util.c | 21 | ||||
-rw-r--r-- | src/basic/cgroup-util.h | 5 | ||||
-rw-r--r-- | src/nspawn/nspawn-cgroup.c | 8 | ||||
-rw-r--r-- | src/nspawn/nspawn.c | 2 |
6 files changed, 14 insertions, 26 deletions
diff --git a/configure.ac b/configure.ac index c7537aafc0..afbb4e8ae5 100644 --- a/configure.ac +++ b/configure.ac @@ -645,7 +645,7 @@ AC_ARG_WITH(default-hierarchy, AS_CASE("$DEFAULT_HIERARCHY", [legacy], [mode=CGROUP_UNIFIED_NONE], - [hybrid], [mode=CGROUP_UNIFIED_SYSTEMD], + [hybrid], [mode=CGROUP_UNIFIED_SYSTEMD233], [unified], [mode=CGROUP_UNIFIED_ALL], AC_MSG_ERROR(Bad default hierarchy mode ${DEFAULT_HIERARCHY})) AC_DEFINE_UNQUOTED(DEFAULT_HIERARCHY, [$mode], [Default cgroup hierarchy]) diff --git a/meson.build b/meson.build index 20b27c8600..1e1677ca7e 100644 --- a/meson.build +++ b/meson.build @@ -544,7 +544,7 @@ conf.set_quoted('DEFAULT_HIERARCHY_NAME', default_hierarchy, if default_hierarchy == 'legacy' conf.set('DEFAULT_HIERARCHY', 'CGROUP_UNIFIED_NONE') elif default_hierarchy == 'hybrid' - conf.set('DEFAULT_HIERARCHY', 'CGROUP_UNIFIED_SYSTEMD') + conf.set('DEFAULT_HIERARCHY', 'CGROUP_UNIFIED_SYSTEMD233') else conf.set('DEFAULT_HIERARCHY', 'CGROUP_UNIFIED_ALL') endif diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index f849df6d0e..5287d7867a 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -2382,17 +2382,6 @@ 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_controller(SYSTEMD_CGROUP_CONTROLLER) and %false on cg_hybrid_unified(). - */ -static thread_local bool unified_systemd_v232; - static int cg_unified_update(void) { struct statfs fs; @@ -2413,12 +2402,10 @@ static int cg_unified_update(void) { 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)) { - unified_cache = CGROUP_UNIFIED_SYSTEMD; - unified_systemd_v232 = false; + unified_cache = CGROUP_UNIFIED_SYSTEMD233; } 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; + unified_cache = CGROUP_UNIFIED_SYSTEMD232; } else { if (statfs("/sys/fs/cgroup/systemd/", &fs) < 0) return -errno; @@ -2465,7 +2452,7 @@ int cg_hybrid_unified(void) { if (r < 0) return r; - return unified_cache == CGROUP_UNIFIED_SYSTEMD && !unified_systemd_v232; + return unified_cache == CGROUP_UNIFIED_SYSTEMD233; } int cg_unified_flush(void) { @@ -2560,7 +2547,7 @@ bool cg_is_hybrid_wanted(void) { static thread_local int wanted = -1; int r; bool b; - const bool is_default = DEFAULT_HIERARCHY >= CGROUP_UNIFIED_SYSTEMD; + const bool is_default = DEFAULT_HIERARCHY >= CGROUP_UNIFIED_SYSTEMD232; /* We default to true if the default is "hybrid", obviously, * but also when the default is "unified", because if we get * called, it means that unified hierarchy was not mounted. */ diff --git a/src/basic/cgroup-util.h b/src/basic/cgroup-util.h index c16a33723c..65821ece36 100644 --- a/src/basic/cgroup-util.h +++ b/src/basic/cgroup-util.h @@ -120,8 +120,9 @@ static inline bool CGROUP_BLKIO_WEIGHT_IS_OK(uint64_t x) { typedef enum CGroupUnified { CGROUP_UNIFIED_UNKNOWN = -1, CGROUP_UNIFIED_NONE = 0, /* Both systemd and controllers on legacy */ - CGROUP_UNIFIED_SYSTEMD = 1, /* Only systemd on unified */ - CGROUP_UNIFIED_ALL = 2, /* Both systemd and controllers on unified */ + CGROUP_UNIFIED_SYSTEMD232 = 1, /* Only systemd on unified, as done by SD232 */ + CGROUP_UNIFIED_SYSTEMD233 = 2, /* Only systemd on unified, as done by SD233+ */ + CGROUP_UNIFIED_ALL = 3, /* Both systemd and controllers on unified */ } CGroupUnified; /* diff --git a/src/nspawn/nspawn-cgroup.c b/src/nspawn/nspawn-cgroup.c index ad5f8eeb5b..600f7b9393 100644 --- a/src/nspawn/nspawn-cgroup.c +++ b/src/nspawn/nspawn-cgroup.c @@ -88,7 +88,7 @@ int sync_cgroup(pid_t pid, CGroupUnified inner_cgver, uid_t uid_shift) { unified_controller = cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER); if (unified_controller < 0) return log_error_errno(unified_controller, "Failed to determine whether the systemd hierarchy is unified: %m"); - if ((unified_controller > 0) == (inner_cgver >= CGROUP_UNIFIED_SYSTEMD)) + if ((unified_controller > 0) == (inner_cgver >= CGROUP_UNIFIED_SYSTEMD232)) return 0; /* When the host uses the legacy cgroup setup, but the @@ -373,7 +373,7 @@ static int mount_legacy_cgns_supported( } skip_controllers: - if (inner_cgver >= CGROUP_UNIFIED_SYSTEMD) { + if (inner_cgver >= CGROUP_UNIFIED_SYSTEMD232) { r = mount_legacy_cgroup_hierarchy("", SYSTEMD_CGROUP_CONTROLLER_HYBRID, "unified", false); if (r < 0) return r; @@ -486,7 +486,7 @@ static int mount_legacy_cgns_unsupported( } skip_controllers: - if (inner_cgver >= CGROUP_UNIFIED_SYSTEMD) { + if (inner_cgver >= CGROUP_UNIFIED_SYSTEMD232) { r = mount_legacy_cgroup_hierarchy(dest, SYSTEMD_CGROUP_CONTROLLER_HYBRID, "unified", false); if (r < 0) return r; @@ -579,7 +579,7 @@ int mount_systemd_cgroup_writable( return mount_systemd_cgroup_writable_one(strjoina(dest, "/sys/fs/cgroup", own_cgroup_path), prefix_roota(dest, "/sys/fs/cgroup")); - if (inner_cgver >= CGROUP_UNIFIED_SYSTEMD) { + if (inner_cgver >= CGROUP_UNIFIED_SYSTEMD232) { r = mount_systemd_cgroup_writable_one(strjoina(dest, "/sys/fs/cgroup/unified", own_cgroup_path), prefix_roota(dest, "/sys/fs/cgroup/unified")); if (r < 0) diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 588bf2b2bf..3018110029 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -352,7 +352,7 @@ static int detect_unified_cgroup_hierarchy(const char *directory) { if (r < 0) return log_error_errno(r, "Failed to determine systemd version in container: %m"); if (r > 0) - arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_SYSTEMD; + arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_SYSTEMD233; else arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_NONE; } else |