All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH cgroup/for-3.12] cgroup: replace task_cgroup_path_from_hierarchy() with task_cgroup_path()
@ 2013-07-11 23:34 Tejun Heo
       [not found] ` <20130711233448.GA2359-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Tejun Heo @ 2013-07-11 23:34 UTC (permalink / raw)
  To: Li Zefan
  Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	cgroups-u79uwXL29TY76Z2rM5mHXA, Lennart Poettering, Kay Sievers,
	Jan Kaluža


task_cgroup_path_from_hierarchy() was added for the planned new users
and none of the currently planned users wants to know about multiple
hierarchies.  This patch drops the multiple hierarchy part and makes
it always return the path in the first non-dummy hierarchy.

As unified hierarchy will always have id 1, this is guaranteed to
return the path for the unified hierarchy if mounted; otherwise, it
will return the path from the hierarchy which happens to occupy the
lowest hierarchy id, which will usually be the first hierarchy mounted
after boot.

Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: Lennart Poettering <lennart-mdGvqq1h2p+GdvJs77BJ7Q@public.gmane.org>
Cc: Kay Sievers <kay.sievers-tD+1rO4QERM@public.gmane.org>
Cc: Jan Kaluža <jkaluza-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 include/linux/cgroup.h |    3 +--
 kernel/cgroup.c        |   31 +++++++++++++++++++------------
 2 files changed, 20 insertions(+), 14 deletions(-)

--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -533,8 +533,7 @@ int cgroup_rm_cftypes(struct cgroup_subs
 bool cgroup_is_descendant(struct cgroup *cgrp, struct cgroup *ancestor);
 
 int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen);
-int task_cgroup_path_from_hierarchy(struct task_struct *task, int hierarchy_id,
-				    char *buf, size_t buflen);
+int task_cgroup_path(struct task_struct *task, char *buf, size_t buflen);
 
 int cgroup_task_count(const struct cgroup *cgrp);
 
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1797,36 +1797,43 @@ out:
 EXPORT_SYMBOL_GPL(cgroup_path);
 
 /**
- * task_cgroup_path_from_hierarchy - cgroup path of a task on a hierarchy
+ * task_cgroup_path - cgroup path of a task in the first cgroup hierarchy
  * @task: target task
- * @hierarchy_id: the hierarchy to look up @task's cgroup from
  * @buf: the buffer to write the path into
  * @buflen: the length of the buffer
  *
- * Determine @task's cgroup on the hierarchy specified by @hierarchy_id and
- * copy its path into @buf.  This function grabs cgroup_mutex and shouldn't
- * be used inside locks used by cgroup controller callbacks.
+ * Determine @task's cgroup on the first (the one with the lowest non-zero
+ * hierarchy_id) cgroup hierarchy and copy its path into @buf.  This
+ * function grabs cgroup_mutex and shouldn't be used inside locks used by
+ * cgroup controller callbacks.
+ *
+ * Returns 0 on success, fails with -%ENAMETOOLONG if @buflen is too short.
  */
-int task_cgroup_path_from_hierarchy(struct task_struct *task, int hierarchy_id,
-				    char *buf, size_t buflen)
+int task_cgroup_path(struct task_struct *task, char *buf, size_t buflen)
 {
 	struct cgroupfs_root *root;
-	struct cgroup *cgrp = NULL;
-	int ret = -ENOENT;
+	struct cgroup *cgrp;
+	int hierarchy_id = 1, ret = 0;
+
+	if (buflen < 2)
+		return -ENAMETOOLONG;
 
 	mutex_lock(&cgroup_mutex);
 
-	root = idr_find(&cgroup_hierarchy_idr, hierarchy_id);
+	root = idr_get_next(&cgroup_hierarchy_idr, &hierarchy_id);
+
 	if (root) {
 		cgrp = task_cgroup_from_root(task, root);
 		ret = cgroup_path(cgrp, buf, buflen);
+	} else {
+		/* if no hierarchy exists, everyone is in "/" */
+		memcpy(buf, "/", 2);
 	}
 
 	mutex_unlock(&cgroup_mutex);
-
 	return ret;
 }
-EXPORT_SYMBOL_GPL(task_cgroup_path_from_hierarchy);
+EXPORT_SYMBOL_GPL(task_cgroup_path);
 
 /*
  * Control Group taskset

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH cgroup/for-3.12] cgroup: replace task_cgroup_path_from_hierarchy() with task_cgroup_path()
       [not found] ` <20130711233448.GA2359-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
@ 2013-07-12  7:49     ` Li Zefan
  2013-07-12 20:02   ` Tejun Heo
  2013-07-12 20:02   ` Tejun Heo
  2 siblings, 0 replies; 6+ messages in thread
From: Li Zefan @ 2013-07-12  7:49 UTC (permalink / raw)
  To: Tejun Heo
  Cc: cgroups-u79uwXL29TY76Z2rM5mHXA,
	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	Kay Sievers, Lennart Poettering, Jan Kaluža

On 2013/7/12 7:34, Tejun Heo wrote:
> 
> task_cgroup_path_from_hierarchy() was added for the planned new users
> and none of the currently planned users wants to know about multiple
> hierarchies.  This patch drops the multiple hierarchy part and makes
> it always return the path in the first non-dummy hierarchy.
> 
> As unified hierarchy will always have id 1, this is guaranteed to
> return the path for the unified hierarchy if mounted; otherwise, it
> will return the path from the hierarchy which happens to occupy the
> lowest hierarchy id, which will usually be the first hierarchy mounted
> after boot.
> 
> Signed-off-by: Tejun Heo <tj@kernel.org>
> Cc: Lennart Poettering <lennart@poettering.net>
> Cc: Kay Sievers <kay.sievers@vrfy.org>
> Cc: Jan Kaluža <jkaluza@redhat.com>

Acked-by: Li Zefan <lizefan@huawei.com>

_______________________________________________
Containers mailing list
Containers@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/containers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH cgroup/for-3.12] cgroup: replace task_cgroup_path_from_hierarchy() with task_cgroup_path()
@ 2013-07-12  7:49     ` Li Zefan
  0 siblings, 0 replies; 6+ messages in thread
From: Li Zefan @ 2013-07-12  7:49 UTC (permalink / raw)
  To: Tejun Heo
  Cc: cgroups-u79uwXL29TY76Z2rM5mHXA,
	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	Kay Sievers, Lennart Poettering, Jan Kaluža

On 2013/7/12 7:34, Tejun Heo wrote:
> 
> task_cgroup_path_from_hierarchy() was added for the planned new users
> and none of the currently planned users wants to know about multiple
> hierarchies.  This patch drops the multiple hierarchy part and makes
> it always return the path in the first non-dummy hierarchy.
> 
> As unified hierarchy will always have id 1, this is guaranteed to
> return the path for the unified hierarchy if mounted; otherwise, it
> will return the path from the hierarchy which happens to occupy the
> lowest hierarchy id, which will usually be the first hierarchy mounted
> after boot.
> 
> Signed-off-by: Tejun Heo <tj@kernel.org>
> Cc: Lennart Poettering <lennart@poettering.net>
> Cc: Kay Sievers <kay.sievers@vrfy.org>
> Cc: Jan Kaluža <jkaluza@redhat.com>

Acked-by: Li Zefan <lizefan@huawei.com>

_______________________________________________
Containers mailing list
Containers@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/containers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH cgroup/for-3.12] cgroup: replace task_cgroup_path_from_hierarchy() with task_cgroup_path()
       [not found] ` <20130711233448.GA2359-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
  2013-07-12  7:49     ` Li Zefan
@ 2013-07-12 20:02   ` Tejun Heo
  2013-07-12 20:02   ` Tejun Heo
  2 siblings, 0 replies; 6+ messages in thread
From: Tejun Heo @ 2013-07-12 20:02 UTC (permalink / raw)
  To: Li Zefan
  Cc: cgroups-u79uwXL29TY76Z2rM5mHXA,
	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	Kay Sievers, Lennart Poettering, Jan Kaluža

On Thu, Jul 11, 2013 at 04:34:48PM -0700, Tejun Heo wrote:
> task_cgroup_path_from_hierarchy() was added for the planned new users
> and none of the currently planned users wants to know about multiple
> hierarchies.  This patch drops the multiple hierarchy part and makes
> it always return the path in the first non-dummy hierarchy.
> 
> As unified hierarchy will always have id 1, this is guaranteed to
> return the path for the unified hierarchy if mounted; otherwise, it
> will return the path from the hierarchy which happens to occupy the
> lowest hierarchy id, which will usually be the first hierarchy mounted
> after boot.
> 
> Signed-off-by: Tejun Heo <tj@kernel.org>
> Cc: Lennart Poettering <lennart@poettering.net>
> Cc: Kay Sievers <kay.sievers@vrfy.org>
> Cc: Jan Kaluža <jkaluza@redhat.com>

Applied this to cgroup/for-3.11-fixes so that the out-of-tree usages
currently being developed can target 3.11 kernel.  This function
currently doesn't have any in-tree users so this won't affect
anything.

Thanks.

-- 
tejun
_______________________________________________
Containers mailing list
Containers@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/containers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH cgroup/for-3.12] cgroup: replace task_cgroup_path_from_hierarchy() with task_cgroup_path()
       [not found] ` <20130711233448.GA2359-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
  2013-07-12  7:49     ` Li Zefan
  2013-07-12 20:02   ` Tejun Heo
@ 2013-07-12 20:02   ` Tejun Heo
  2 siblings, 0 replies; 6+ messages in thread
From: Tejun Heo @ 2013-07-12 20:02 UTC (permalink / raw)
  To: Li Zefan
  Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	cgroups-u79uwXL29TY76Z2rM5mHXA, Lennart Poettering, Kay Sievers,
	Jan Kaluža

On Thu, Jul 11, 2013 at 04:34:48PM -0700, Tejun Heo wrote:
> task_cgroup_path_from_hierarchy() was added for the planned new users
> and none of the currently planned users wants to know about multiple
> hierarchies.  This patch drops the multiple hierarchy part and makes
> it always return the path in the first non-dummy hierarchy.
> 
> As unified hierarchy will always have id 1, this is guaranteed to
> return the path for the unified hierarchy if mounted; otherwise, it
> will return the path from the hierarchy which happens to occupy the
> lowest hierarchy id, which will usually be the first hierarchy mounted
> after boot.
> 
> Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> Cc: Lennart Poettering <lennart-mdGvqq1h2p+GdvJs77BJ7Q@public.gmane.org>
> Cc: Kay Sievers <kay.sievers-tD+1rO4QERM@public.gmane.org>
> Cc: Jan Kaluža <jkaluza-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

Applied this to cgroup/for-3.11-fixes so that the out-of-tree usages
currently being developed can target 3.11 kernel.  This function
currently doesn't have any in-tree users so this won't affect
anything.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH cgroup/for-3.12] cgroup: replace task_cgroup_path_from_hierarchy() with task_cgroup_path()
@ 2013-07-11 23:34 Tejun Heo
  0 siblings, 0 replies; 6+ messages in thread
From: Tejun Heo @ 2013-07-11 23:34 UTC (permalink / raw)
  To: Li Zefan
  Cc: cgroups-u79uwXL29TY76Z2rM5mHXA,
	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	Kay Sievers, Lennart Poettering, Jan Kaluža


task_cgroup_path_from_hierarchy() was added for the planned new users
and none of the currently planned users wants to know about multiple
hierarchies.  This patch drops the multiple hierarchy part and makes
it always return the path in the first non-dummy hierarchy.

As unified hierarchy will always have id 1, this is guaranteed to
return the path for the unified hierarchy if mounted; otherwise, it
will return the path from the hierarchy which happens to occupy the
lowest hierarchy id, which will usually be the first hierarchy mounted
after boot.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Lennart Poettering <lennart@poettering.net>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Cc: Jan Kaluža <jkaluza@redhat.com>
---
 include/linux/cgroup.h |    3 +--
 kernel/cgroup.c        |   31 +++++++++++++++++++------------
 2 files changed, 20 insertions(+), 14 deletions(-)

--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -533,8 +533,7 @@ int cgroup_rm_cftypes(struct cgroup_subs
 bool cgroup_is_descendant(struct cgroup *cgrp, struct cgroup *ancestor);
 
 int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen);
-int task_cgroup_path_from_hierarchy(struct task_struct *task, int hierarchy_id,
-				    char *buf, size_t buflen);
+int task_cgroup_path(struct task_struct *task, char *buf, size_t buflen);
 
 int cgroup_task_count(const struct cgroup *cgrp);
 
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1797,36 +1797,43 @@ out:
 EXPORT_SYMBOL_GPL(cgroup_path);
 
 /**
- * task_cgroup_path_from_hierarchy - cgroup path of a task on a hierarchy
+ * task_cgroup_path - cgroup path of a task in the first cgroup hierarchy
  * @task: target task
- * @hierarchy_id: the hierarchy to look up @task's cgroup from
  * @buf: the buffer to write the path into
  * @buflen: the length of the buffer
  *
- * Determine @task's cgroup on the hierarchy specified by @hierarchy_id and
- * copy its path into @buf.  This function grabs cgroup_mutex and shouldn't
- * be used inside locks used by cgroup controller callbacks.
+ * Determine @task's cgroup on the first (the one with the lowest non-zero
+ * hierarchy_id) cgroup hierarchy and copy its path into @buf.  This
+ * function grabs cgroup_mutex and shouldn't be used inside locks used by
+ * cgroup controller callbacks.
+ *
+ * Returns 0 on success, fails with -%ENAMETOOLONG if @buflen is too short.
  */
-int task_cgroup_path_from_hierarchy(struct task_struct *task, int hierarchy_id,
-				    char *buf, size_t buflen)
+int task_cgroup_path(struct task_struct *task, char *buf, size_t buflen)
 {
 	struct cgroupfs_root *root;
-	struct cgroup *cgrp = NULL;
-	int ret = -ENOENT;
+	struct cgroup *cgrp;
+	int hierarchy_id = 1, ret = 0;
+
+	if (buflen < 2)
+		return -ENAMETOOLONG;
 
 	mutex_lock(&cgroup_mutex);
 
-	root = idr_find(&cgroup_hierarchy_idr, hierarchy_id);
+	root = idr_get_next(&cgroup_hierarchy_idr, &hierarchy_id);
+
 	if (root) {
 		cgrp = task_cgroup_from_root(task, root);
 		ret = cgroup_path(cgrp, buf, buflen);
+	} else {
+		/* if no hierarchy exists, everyone is in "/" */
+		memcpy(buf, "/", 2);
 	}
 
 	mutex_unlock(&cgroup_mutex);
-
 	return ret;
 }
-EXPORT_SYMBOL_GPL(task_cgroup_path_from_hierarchy);
+EXPORT_SYMBOL_GPL(task_cgroup_path);
 
 /*
  * Control Group taskset
_______________________________________________
Containers mailing list
Containers@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/containers

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-07-12 20:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-11 23:34 [PATCH cgroup/for-3.12] cgroup: replace task_cgroup_path_from_hierarchy() with task_cgroup_path() Tejun Heo
     [not found] ` <20130711233448.GA2359-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2013-07-12  7:49   ` Li Zefan
2013-07-12  7:49     ` Li Zefan
2013-07-12 20:02   ` Tejun Heo
2013-07-12 20:02   ` Tejun Heo
  -- strict thread matches above, loose matches on Subject: below --
2013-07-11 23:34 Tejun Heo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.