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

Submitted by Andrey Ryabinin on Feb. 2, 2017, 12:59 p.m.

Details

Message ID 20170202125947.7150-1-aryabinin@virtuozzo.com
State New
Series "cgroup/ve: don't add cgroup files on ve_root twice."
Headers show

Commit Message

Andrey Ryabinin Feb. 2, 2017, 12:59 p.m.
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@virtuozzo.com>
---
 kernel/cgroup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

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