[Devel] [PATCH RH7] proc: fix mangling cgroup mount source path in container

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Tue Oct 6 02:23:24 PDT 2015


Docker uses /proc/self/cgroup to know where he is in cgroup tree
and also it uses /proc/self/mountinfo to get from where cgroup
sub-tree(on which he is) is mounted, using both it can understand
where his cgroups are in his /sys/fs/cgroup sub-tree.

We need to mangle cgroup paths in mountinfo output consistently
with cgroup output, in /proc/self/cgroup we remove prefix "/$ctid"
do the same in mountinfo. It is not enought to show just "/" for
docker in docker: docker will bindmount in container sub-tree of
this container.

https://jira.sw.ru/browse/PSBM-34295

Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 kernel/cgroup.c | 38 +++++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index ad61c97..d9214c2 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1375,11 +1375,39 @@ static int cgroup_remount(struct super_block *sb, int *flags, char *data)
 #ifdef CONFIG_VE
 int cgroup_show_path(struct seq_file *m, struct dentry *dentry)
 {
-	if (!ve_is_super(get_exec_env()))
-		seq_puts(m, "/");
-	else
-		seq_dentry(m, dentry, " \t\n\\");
-	return 0;
+	char *buf;
+	size_t size = seq_get_buf(m, &buf);
+	int res = -1, err = 0;
+
+	if (size) {
+		char *p = dentry_path(mnt->mnt_root, buf, size);
+		if (!IS_ERR(p)) {
+			char *end;
+			if (!ve_is_super(get_exec_env())) {
+				while (*++p != '/') {
+					/*
+					 * Mangle one level when showing
+					 * cgroup mount source in container
+					 * e.g.: "/111" -> "/",
+					 * "/111/test.slice/test.scope" ->
+					 * "/test.slice/test.scope"
+					 */
+					if (*p == '\0') {
+						*--p = '/';
+						break;
+					}
+				}
+			}
+			end = mangle_path(buf, p, " \t\n\\");
+			if (end)
+				res = end - buf;
+		} else {
+			err = PTR_ERR(p);
+		}
+	}
+	seq_commit(m, res);
+
+	return err;
 }
 #endif
 
-- 
1.9.3




More information about the Devel mailing list