[Devel] [PATCH RHEL7 COMMIT] cgroup/ve: don't add cgroup files on ve_root twice.

Konstantin Khorenko khorenko at virtuozzo.com
Thu Feb 2 08:45:35 PST 2017


The commit is pushed to "branch-rh7-3.10.0-514.6.1.vz7.28.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-514.6.1.vz7.28.3
------>
commit 1553c5a736cb00add6a53e8fe8fd18ce876c4010
Author: Andrey Ryabinin <aryabinin at virtuozzo.com>
Date:   Thu Feb 2 20:45:35 2017 +0400

    cgroup/ve: don't add cgroup files on ve_root twice.
    
    We have single pids cgroup hierarchy which is shared among all VEs.
    So when we start several VEs, cgroup_add_ve_root_files() will be called
    more than once for the single pids cgroup, leading to:
           "cgroup_add_ve_root_files: failed to add cgroup.subgroups_limit, err=-17"
    
    This may seem as harmless message at first, but it is not because cgroup_add_file()
    doesn't handle error properly:
    
    	cfe = kzalloc(sizeof(*cfe), GFP_KERNEL);
    	....
    	dentry->d_fsdata = cfe;
    	....
    	error = cgroup_create_file(dentry, mode | S_IFREG, cgrp->root->sb);
    	if (!error) {
    		list_add_tail(&cfe->node, &parent->files);
    		cfe = NULL;
    	}
    
    	....
    	kfree(cfe);
    	return error;
    
    As one can see above we leave freed cfe in dentry if cgroup_create_file() fails.
    So let's make sure that we call cgroup_add_ve_root_files() only once per
    cgroup to avoid that problem and message in dmesg as well.
    
    https://jira.sw.ru/browse/PSBM-59693
    
    Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
 kernel/cgroup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 3e2de0b4..e8ec5f2 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -4271,8 +4271,8 @@ void cgroup_mark_ve_root(struct ve_struct *ve)
 	mutex_lock(&cgroup_mutex);
 	for_each_active_root(root) {
 		cgrp = task_cgroup_from_root(ve->init_task, root);
-		set_bit(CGRP_VE_ROOT, &cgrp->flags);
-		cgroup_add_ve_root_files(cgrp, NULL, files);
+		if (!test_and_set_bit(CGRP_VE_ROOT, &cgrp->flags))
+			cgroup_add_ve_root_files(cgrp, NULL, files);
 	}
 	mutex_unlock(&cgroup_mutex);
 }


More information about the Devel mailing list