[Devel] [PATCH RHEL7 COMMIT] ve/proc: fix mangling cgroup mount source path in container

Konstantin Khorenko khorenko at virtuozzo.com
Thu Oct 8 03:05:35 PDT 2015


The commit is pushed to "branch-rh7-3.10.0-229.7.2.vz7.8.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-229.7.2.vz7.8.4
------>
commit 24239bb62335a3c701b2d3538ab5a4f066954ff8
Author: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Date:   Thu Oct 8 14:05:35 2015 +0400

    ve/proc: fix mangling cgroup mount source path in container
    
    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.
    
    v2: fix compilation
    
    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..4268373 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(dentry, 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
 



More information about the Devel mailing list