mirror of
https://github.com/systemd/systemd.git
synced 2025-03-19 22:50:17 +03:00
core/main: refuse bootup with legacy cgroup hierarchy
First step towards a unified-only future (rework of internals coming soon (TM))
This commit is contained in:
parent
a822bad9f4
commit
1aa77b3a1b
@ -3302,6 +3302,23 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
log_execution_mode(&first_boot);
|
||||
|
||||
r = cg_has_legacy();
|
||||
if (r < 0) {
|
||||
error_message = "Failed to check cgroup hierarchy";
|
||||
goto finish;
|
||||
}
|
||||
if (r > 0) {
|
||||
r = log_full_errno(LOG_EMERG, SYNTHETIC_ERRNO(EPROTO),
|
||||
"Detected cgroup v1 hierarchy at /sys/fs/cgroup/, which is no longer supported by current version of systemd.\n"
|
||||
"Please instruct your initrd to mount cgroup v2 (unified) hierarchy,\n"
|
||||
"possibly by removing any stale kernel command line options, such as:\n"
|
||||
" systemd.legacy_systemd_cgroup_controller=1\n"
|
||||
" systemd.unified_cgroup_hierarchy=0");
|
||||
|
||||
error_message = "Detected unsupported legacy cgroup hierarchy, refusing execution";
|
||||
goto finish;
|
||||
}
|
||||
|
||||
r = initialize_runtime(skip_setup,
|
||||
first_boot,
|
||||
&saved_rlimit_nofile,
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "fs-util.h"
|
||||
#include "missing_magic.h"
|
||||
#include "mkdir.h"
|
||||
#include "parse-util.h"
|
||||
#include "path-util.h"
|
||||
@ -951,3 +952,29 @@ int cg_uninstall_release_agent(const char *controller) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cg_has_legacy(void) {
|
||||
struct statfs fs;
|
||||
|
||||
/* Checks if any legacy controller/hierarchy is mounted. */
|
||||
|
||||
if (statfs("/sys/fs/cgroup/", &fs) < 0) {
|
||||
if (errno == ENOENT) /* sysfs not mounted? */
|
||||
return false;
|
||||
|
||||
return log_debug_errno(errno, "Failed to statfs /sys/fs/cgroup/: %m");
|
||||
}
|
||||
|
||||
if (is_fs_type(&fs, CGROUP2_SUPER_MAGIC) ||
|
||||
is_fs_type(&fs, SYSFS_MAGIC)) /* not mounted yet */
|
||||
return false;
|
||||
|
||||
if (is_fs_type(&fs, TMPFS_MAGIC)) {
|
||||
log_debug("Found tmpfs on /sys/fs/cgroup/, assuming legacy hierarchy.");
|
||||
return true;
|
||||
}
|
||||
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(ENOMEDIUM),
|
||||
"Unknown filesystem type %llx mounted on /sys/fs/cgroup/.",
|
||||
(unsigned long long) fs.f_type);
|
||||
}
|
||||
|
@ -40,3 +40,5 @@ int cg_trim_v1_controllers(CGroupMask supported, CGroupMask mask, const char *pa
|
||||
|
||||
int cg_install_release_agent(const char *controller, const char *agent);
|
||||
int cg_uninstall_release_agent(const char *controller);
|
||||
|
||||
int cg_has_legacy(void);
|
||||
|
Loading…
x
Reference in New Issue
Block a user