[PATCH cgroup/for-3.10] cgroup: make cgroup_path() not print double slashes

Li Zefan lizefan at huawei.com
Mon Apr 15 03:10:33 UTC 2013


On 2013/4/15 1:37, Tejun Heo wrote:
>>From 277f3d4be79aefe2071d9053a9c7c89c4e5dad30 Mon Sep 17 00:00:00 2001
> From: Tejun Heo <tj at kernel.org>
> Date: Sun, 14 Apr 2013 10:32:19 -0700
> 
> While reimplementing cgroup_path(), 65dff759d2 ("cgroup: fix
> cgroup_path() vs rename() race") introduced a bug where the path of a
> non-root cgroup would have two slahses at the beginning, which is
> caused by adding '/' before the name of the root cgroup which is an
> empty string.
> 

I guess I booted a wrong kernel when testing that patch...

>  $ grep systemd /proc/self/cgroup
>  1:name=systemd://user/root/1
> 
> Fix it by special casing root cgroup.
> 

I made a patch to fix it before the weekend, but didn't post it. It doesn't
treat root-only cgroup specially.

You can apply whichever you like better.

> Signed-off-by: Tejun Heo <tj at kernel.org>
> Cc: Li Zefan <lizefan at huawei.com>
> ---
> Applying to cgroup/for-3.10.
> 
> Thanks.
> 
>  kernel/cgroup.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 

[PATCH] cgroup: make cgroup_path() not print double slashes

While reimplementing cgroup_path(), 65dff759d2 ("cgroup: fix
cgroup_path() vs rename() race") introduced a bug where the path of a
non-root cgroup would have two slahses at the beginning, which is
caused by treating the root cgroup which has the name '/' like
non-root cgroups.

Fix it by not adding '/' if it's the root cgroup.

 $ grep systemd /proc/self/cgroup
 1:name=systemd://user/root/1

Signed-off-by: Li Zefan <lizefan at huawei.com>
---
 kernel/cgroup.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 06aeb42..2a28425 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1809,14 +1809,15 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen)
 			goto out;
 		memcpy(start, name, len);
 
-		if (!cgrp->parent)
+		cgrp = cgrp->parent;
+		if (!cgrp)
 			break;
+		if (!cgrp->parent)
+			continue;
 
 		if (--start < buf)
 			goto out;
 		*start = '/';
-
-		cgrp = cgrp->parent;
 	}
 	ret = 0;
 	memmove(buf, start, buf + buflen - start);
-- 
1.8.0.2



More information about the Containers mailing list