[lxc-devel] [lxcfs/master] bindings: add mountpoint for unified hierarchy

brauner on Github lxc-bot at linuxcontainers.org
Wed May 17 10:12:22 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 365 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170517/2ddb33a2/attachment.bin>
-------------- next part --------------
From 51c7ca35d2646d452da3e3db7c6292bec5492e27 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 17 May 2017 12:11:20 +0200
Subject: [PATCH] bindings: add mountpoint for unified hierarchy

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 bindings.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/bindings.c b/bindings.c
index 6387012..5b5860e 100644
--- a/bindings.c
+++ b/bindings.c
@@ -4383,11 +4383,13 @@ static bool cgfs_mount_hierarchies(void)
 
 	for (i = 0; i < num_hierarchies; i++) {
 		char *controller = hierarchies[i];
+
 		clen = strlen(controller);
 		len = strlen(BASEDIR) + clen + 2;
 		target = malloc(len);
 		if (!target)
 			return false;
+
 		ret = snprintf(target, len, "%s/%s", BASEDIR, controller);
 		if (ret < 0 || ret >= len) {
 			free(target);
@@ -4397,8 +4399,12 @@ static bool cgfs_mount_hierarchies(void)
 			free(target);
 			return false;
 		}
-		if (mount(controller, target, "cgroup", 0, controller) < 0) {
-			lxcfs_error("Failed mounting cgroup %s\n", controller);
+		if (!strcmp(controller, "unified"))
+			ret = mount("none", target, "cgroup2", 0, NULL);
+		else
+			ret = mount(controller, target, "cgroup", 0, controller);
+		if (ret < 0) {
+			lxcfs_error("Failed mounting cgroup %s: %s\n", controller, strerror(errno));
 			free(target);
 			return false;
 		}
@@ -4449,6 +4455,7 @@ static void __attribute__((constructor)) collect_and_mount_subsystems(void)
 	char cwd[MAXPATHLEN];
 	size_t len = 0;
 	int i, init_ns = -1;
+	bool found_unified = false;
 
 	if ((f = fopen("/proc/self/cgroup", "r")) == NULL) {
 		lxcfs_error("Error opening /proc/self/cgroup: %s\n", strerror(errno));
@@ -4456,11 +4463,12 @@ static void __attribute__((constructor)) collect_and_mount_subsystems(void)
 	}
 
 	while (getline(&line, &len, f) != -1) {
-		char *p, *p2;
+		char *idx, *p, *p2;
 
 		p = strchr(line, ':');
 		if (!p)
 			goto out;
+		idx = line;
 		*(p++) = '\0';
 
 		p2 = strrchr(p, ':');
@@ -4473,8 +4481,10 @@ static void __attribute__((constructor)) collect_and_mount_subsystems(void)
 		 * because it parses out the empty string "" and later on passes
 		 * it to mount(). Let's skip such entries.
 		 */
-		if (!strcmp(p, ""))
-			continue;
+		if (!strcmp(p, "") && !strcmp(idx, "0") && !found_unified) {
+			found_unified = true;
+			p = "unified";
+		}
 
 		if (!store_hierarchy(line, p))
 			goto out;


More information about the lxc-devel mailing list