Skip to contentSkip to conversation

cgroup: make cgroup_path() not print double slashes

PATCH In review Tejun Heo 2 participants 5 messages Apr 14, 2013 – Apr 15, 2013 2 messages not in the archive cgroup

lore
Share & tools
lore

Tejun Heo

author
#0 lore raw

PATCH 1/1 cgroup: make cgroup_path() not print double slashes

From 277f3d4be79aefe2071d9053a9c7c89c4e5dad30 Mon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
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.

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

Fix it by special casing root cgroup.

---
Applying to cgroup/for-3.10.

Thanks.

 kernel/cgroup.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
kernel/cgroup.c +8 -5
index 678a22c..faf55f5 100644
@@ -1811,11 +1811,17 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen)
 	int ret = -ENAMETOOLONG;
 	char *start;
 
+	if (!cgrp->parent) {
+		if (strlcpy(buf, "/", buflen) >= buflen)
+			return -ENAMETOOLONG;
+		return 0;
+	}
+
 	start = buf + buflen - 1;
 	*start = '\0';
 
 	rcu_read_lock();
-	while (cgrp) {
+	do {
 		const char *name = cgroup_name(cgrp);
 		int len;
 
@@ -1824,15 +1830,12 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen)
 			goto out;
 		memcpy(start, name, len);
 
-		if (!cgrp->parent)
-			break;
-
 		if (--start < buf)
 			goto out;
 		*start = '/';
 
 		cgrp = cgrp->parent;
-	}
+	} while (cgrp->parent);
 	ret = 0;
 	memmove(buf, start, buf + buflen - start);
 out:
Signature · 1 line
1.8.1.4

A message that is not in the archive (sent off-list or not yet received): 20130414173704.GB3050-Gd/HAXX7CRxy/[email protected]

author
#2 lore raw

PATCH 1/1 cgroup: make cgroup_path() not print double slashes

From da1f296fd2bfd5ad3c53d72a1ece593e821cf374 Mon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
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 treating the root cgroup which has the name '/' like non-root cgroups.

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

Fix it by special casing root cgroup case and not looping over it in the normal path.

---
The description was wrong. Updated.

Thanks.

 kernel/cgroup.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
kernel/cgroup.c +8 -5
index 678a22c..faf55f5 100644
@@ -1811,11 +1811,17 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen)
 	int ret = -ENAMETOOLONG;
 	char *start;
 
+	if (!cgrp->parent) {
+		if (strlcpy(buf, "/", buflen) >= buflen)
+			return -ENAMETOOLONG;
+		return 0;
+	}
+
 	start = buf + buflen - 1;
 	*start = '\0';
 
 	rcu_read_lock();
-	while (cgrp) {
+	do {
 		const char *name = cgroup_name(cgrp);
 		int len;
 
@@ -1824,15 +1830,12 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen)
 			goto out;
 		memcpy(start, name, len);
 
-		if (!cgrp->parent)
-			break;
-
 		if (--start < buf)
 			goto out;
 		*start = '/';
 
 		cgrp = cgrp->parent;
-	}
+	} while (cgrp->parent);
 	ret = 0;
 	memmove(buf, start, buf + buflen - start);
 out:
Signature · 1 line
1.8.1.4
#3 lore raw
In reply to a message not in the archive
Quoted 10 lines · Tejun Heo
Quoted 1 line

From 277f3d4be79aefe2071d9053a9c7c89c4e5dad30 Mon Sep 17 00:00:00 2001

From: Tejun Heo <[email protected]>
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...

Quoted 5 lines
 $ 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.

Quoted 10 lines

---
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
---
 kernel/cgroup.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
kernel/cgroup.c +4 -3
index 06aeb42..2a28425 100644
@@ -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);
Signature · 1 line
1.8.0.2

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#5 lore raw
Quoted 17 lines · Li Zefan
Quoted 10 lines · Tejun Heo
Quoted 1 line

From 277f3d4be79aefe2071d9053a9c7c89c4e5dad30 Mon Sep 17 00:00:00 2001

From: Tejun Heo <[email protected]>
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...

Quoted 3 lines
 $ grep systemd /proc/self/cgroup
 1:name=systemd://user/root/1
Quoted 7 lines
Quoted 2 lines

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.

Already applied the special case patch this morning. Neither seems much better than each other so I'll just leave it that way.

Thanks!

Signature · 1 line
tejun
author
#6 lore raw
In reply to a message not in the archive
Quoted 17 lines · Li Zefan
Quoted 10 lines · Tejun Heo
Quoted 1 line

From 277f3d4be79aefe2071d9053a9c7c89c4e5dad30 Mon Sep 17 00:00:00 2001

From: Tejun Heo <[email protected]>
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...

Quoted 3 lines
 $ grep systemd /proc/self/cgroup
 1:name=systemd://user/root/1
Quoted 7 lines
Quoted 2 lines

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.

Already applied the special case patch this morning. Neither seems much better than each other so I'll just leave it that way.

Thanks!

Signature · 1 line
tejun