[Devel] [PATCH RHEL7 COMMIT] ub: cleanup cgroup attaching code

Konstantin Khorenko khorenko at virtuozzo.com
Thu May 28 07:08:56 PDT 2015


The commit is pushed to "branch-rh7-3.10.0-123.1.2-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-123.1.2.vz7.5.7
------>
commit 45d5878990a65140137d10899e2da540f5333280
Author: Vladimir Davydov <vdavydov at parallels.com>
Date:   Thu May 28 18:08:56 2015 +0400

    ub: cleanup cgroup attaching code
    
    Signed-off-by: Vladimir Davydov <vdavydov at parallels.com>
    Reviewed-by: Kirill Tkhai <ktkhai at odin.com>
---
 kernel/bc/beancounter.c | 52 ++++++++++++-------------------------------------
 1 file changed, 12 insertions(+), 40 deletions(-)

diff --git a/kernel/bc/beancounter.c b/kernel/bc/beancounter.c
index 4ea2375..0ef99f0 100644
--- a/kernel/bc/beancounter.c
+++ b/kernel/bc/beancounter.c
@@ -105,70 +105,42 @@ static void ub_cgroup_close(struct cgroup *root, struct cgroup *cg)
 		cgroup_kernel_close(cg);
 }
 
-static int ub_mem_cgroup_attach_task(struct user_beancounter *ub,
-				     struct task_struct *tsk)
+static int ub_cgroup_attach_task(struct cgroup *root,
+		struct user_beancounter *ub, struct task_struct *tsk)
 {
 	struct cgroup *cg;
 	int ret;
 
-	cg = ub_cgroup_open(mem_cgroup_root, ub);
+	cg = ub_cgroup_open(root, ub);
 	if (IS_ERR(cg))
 		return PTR_ERR(cg);
 	ret = cgroup_kernel_attach(cg, tsk);
-	ub_cgroup_close(mem_cgroup_root, cg);
-	return ret;
-}
-
-static int ub_blkio_cgroup_attach_task(struct user_beancounter *ub,
-				       struct task_struct *tsk)
-{
-	struct cgroup *cg;
-	int ret;
-
-	cg = ub_cgroup_open(blkio_cgroup_root, ub);
-	if (IS_ERR(cg))
-		return PTR_ERR(cg);
-	ret = cgroup_kernel_attach(cg, tsk);
-	ub_cgroup_close(blkio_cgroup_root, cg);
-	return ret;
-}
- 
-static int ub_cgroup_attach_task(struct user_beancounter *ub,
-				 struct task_struct *tsk)
-{
-	struct cgroup *cg;
-	int ret;
-
-	cg = ub_cgroup_open(ub_cgroup_root, ub);
-	if (IS_ERR(cg))
-		return PTR_ERR(cg);
-	ret = cgroup_kernel_attach(cg, tsk);
-	ub_cgroup_close(ub_cgroup_root, cg);
+	ub_cgroup_close(root, cg);
 	return ret;
 }
 
 int ub_attach_task(struct user_beancounter *ub, struct task_struct *tsk)
 {
-	int ret;
+	int ret = 0;
 	struct user_beancounter *old_ub = tsk->task_bc.exec_ub;
 
-	ret = ub_mem_cgroup_attach_task(ub, tsk);
+	if (ub == old_ub)
+		goto out;
+	ret = ub_cgroup_attach_task(mem_cgroup_root, ub, tsk);
 	if (ret)
 		goto out;
-	ret = ub_blkio_cgroup_attach_task(ub, tsk);
+	ret = ub_cgroup_attach_task(blkio_cgroup_root, ub, tsk);
 	if (ret)
 		goto fail_blkio;
-	ret = ub_cgroup_attach_task(ub, tsk);
+	ret = ub_cgroup_attach_task(ub_cgroup_root, ub, tsk);
 	if (ret)
 		goto fail_ub;
 out:
 	return ret;
 fail_ub:
-	if (ub != old_ub)
-		ub_blkio_cgroup_attach_task(old_ub, tsk);
+	ub_cgroup_attach_task(blkio_cgroup_root, old_ub, tsk);
 fail_blkio:
-	if (ub != old_ub)
-		ub_mem_cgroup_attach_task(old_ub, tsk);
+	ub_cgroup_attach_task(mem_cgroup_root, old_ub, tsk);
 	goto out;
 }
 



More information about the Devel mailing list