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

Andrey Ryabinin aryabinin at virtuozzo.com
Thu Feb 2 04:59:47 PST 2017


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);
 }
-- 
2.10.2



More information about the Devel mailing list