[lxc-devel] [cgmanager/master] Make unified hierarchy mountable on 4.5.0+ kernels

maciejsszmigiero on Github lxc-bot at linuxcontainers.org
Sat Oct 28 13:51:38 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 782 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20171028/49798d84/attachment.bin>
-------------- next part --------------
From 1c7ca8ebd7aca835b576d09528626c58f066bc15 Mon Sep 17 00:00:00 2001
From: "Maciej S. Szmigiero" <mail at maciej.szmigiero.name>
Date: Sat, 28 Oct 2017 15:40:33 +0200
Subject: [PATCH] Make unified hierarchy mountable on 4.5.0+ kernels

Starting from kernel 4.5.0 the unified hierarchy is accessible via a
separate "cgroup2" file system type.
The same kernel version also removed the ability to mount it via a
"__DEVEL__sane_behavior" option provided to the "cgroup" file system type.

Adapt to these changes by first trying to mount the "cgroup2" file system,
then, if this file system type is not known, by trying to mount the unified
hierarchy the old way via the "__DEVEL__sane_behavior" mount option.

Signed-off-by: Maciej S. Szmigiero <mail at maciej.szmigiero.name>
---
 fs.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/fs.c b/fs.c
index f1c5f02..4a106e0 100644
--- a/fs.c
+++ b/fs.c
@@ -336,6 +336,17 @@ static bool set_release_agent(struct controller_mounts *m)
 	return true;
 }
 
+static bool do_mount_unified(char *src, char *dest)
+{
+	if (mount(src, dest, "cgroup2", 0, NULL) == 0)
+		return true;
+
+	if (errno != ENODEV)
+		return false;
+
+	return mount(src, dest, "cgroup", 0, "__DEVEL__sane_behavior") == 0;
+}
+
 static bool do_mount_subsys(int i)
 {
 	char *src, *dest, *controller;
@@ -357,7 +368,7 @@ static bool do_mount_subsys(int i)
 	}
 
 	if (m->unified) {
-		if (mount(m->controller, dest, "cgroup", 0, "__DEVEL__sane_behavior") < 0) {
+		if (!do_mount_unified(m->controller, dest)) {
 			nih_error("Failed mounting %s: %s\n", m->controller,
 					strerror(errno));
 			return false;
@@ -859,7 +870,7 @@ static bool mount_transient_unified(void)
 {
 	if (mkdir(UNIFIED_DIR, 0755) < 0 && errno != EEXIST)
 		return false;
-	if (mount("cgroup", UNIFIED_DIR, "cgroup", 0, "__DEVEL__sane_behavior") < 0) {
+	if (!do_mount_unified("cgroup", UNIFIED_DIR)) {
 		nih_error("Error mounting unified: %s\n", strerror(errno));
 		return false;
 	}
@@ -1020,7 +1031,7 @@ static bool pin_and_process_unified(void)
 	return record_unified_controllers(ctrlcopy);
 }
 
-static bool do_mount_unified(void)
+static bool mount_unified(void)
 {
 	int i;
 	bool found = false;
@@ -1041,7 +1052,7 @@ static bool do_mount_unified(void)
 		return false;
 	}
 
-	if (mount("unified", dest, "cgroup", 0, "__DEVEL__sane_behavior") < 0) {
+	if (!do_mount_unified("unified", dest)) {
 		nih_fatal("Failed to mount unified hierarchy: %s\n", strerror(errno));
 		return false;
 	}
@@ -1247,7 +1258,7 @@ int setup_cgroup_mounts(void)
 		return false;
 	}
 
-	if (!do_mount_unified())
+	if (!mount_unified())
 		return -1;
 
 	for (i=0; i<num_controllers; i++) {


More information about the lxc-devel mailing list