mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-10 01:17:44 +03:00
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.
This commit is contained in:
parent
2977724b09
commit
f08e928720
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user