diff options
author | Tejun Heo <tj@kernel.org> | 2013-04-14 23:50:08 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2013-05-14 14:42:07 -0400 |
commit | 857a2beb09ab83e9a8185821ae16db7dfbe8b837 (patch) | |
tree | 2ea1456855d7046dd5503cd7a0a6c78e804aa299 | |
parent | 1a574231669f8c3065c83974e9557fcbbd94b8a6 (diff) |
cgroup: implement task_cgroup_path_from_hierarchy()
kdbus folks want a sane way to determine the cgroup path that a given
task belongs to on a given hierarchy, which is a reasonble thing to
expect from cgroup core.
Implement task_cgroup_path_from_hierarchy().
v2: Dropped unnecessary NULL check on the return value of
task_cgroup_from_root() as suggested by Li Zefan.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Greg Kroah-Hartman <greg@kroah.com>
Acked-by: Li Zefan <lizefan@huawei.com>
Cc: Kay Sievers <kay@vrfy.org>
Cc: Lennart Poettering <lennart@poettering.net>
Cc: Daniel Mack <daniel@zonque.org>
-rw-r--r-- | include/linux/cgroup.h | 2 | ||||
-rw-r--r-- | kernel/cgroup.c | 32 |
2 files changed, 34 insertions, 0 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 5047355b9a0f..383c630f36f9 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h | |||
@@ -542,6 +542,8 @@ int cgroup_is_removed(const struct cgroup *cgrp); | |||
542 | bool cgroup_is_descendant(struct cgroup *cgrp, struct cgroup *ancestor); | 542 | bool cgroup_is_descendant(struct cgroup *cgrp, struct cgroup *ancestor); |
543 | 543 | ||
544 | int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen); | 544 | int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen); |
545 | int task_cgroup_path_from_hierarchy(struct task_struct *task, int hierarchy_id, | ||
546 | char *buf, size_t buflen); | ||
545 | 547 | ||
546 | int cgroup_task_count(const struct cgroup *cgrp); | 548 | int cgroup_task_count(const struct cgroup *cgrp); |
547 | 549 | ||
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index dcb417c6c242..6b2b1d945df2 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -1827,6 +1827,38 @@ out: | |||
1827 | } | 1827 | } |
1828 | EXPORT_SYMBOL_GPL(cgroup_path); | 1828 | EXPORT_SYMBOL_GPL(cgroup_path); |
1829 | 1829 | ||
1830 | /** | ||
1831 | * task_cgroup_path_from_hierarchy - cgroup path of a task on a hierarchy | ||
1832 | * @task: target task | ||
1833 | * @hierarchy_id: the hierarchy to look up @task's cgroup from | ||
1834 | * @buf: the buffer to write the path into | ||
1835 | * @buflen: the length of the buffer | ||
1836 | * | ||
1837 | * Determine @task's cgroup on the hierarchy specified by @hierarchy_id and | ||
1838 | * copy its path into @buf. This function grabs cgroup_mutex and shouldn't | ||
1839 | * be used inside locks used by cgroup controller callbacks. | ||
1840 | */ | ||
1841 | int task_cgroup_path_from_hierarchy(struct task_struct *task, int hierarchy_id, | ||
1842 | char *buf, size_t buflen) | ||
1843 | { | ||
1844 | struct cgroupfs_root *root; | ||
1845 | struct cgroup *cgrp = NULL; | ||
1846 | int ret = -ENOENT; | ||
1847 | |||
1848 | mutex_lock(&cgroup_mutex); | ||
1849 | |||
1850 | root = idr_find(&cgroup_hierarchy_idr, hierarchy_id); | ||
1851 | if (root) { | ||
1852 | cgrp = task_cgroup_from_root(task, root); | ||
1853 | ret = cgroup_path(cgrp, buf, buflen); | ||
1854 | } | ||
1855 | |||
1856 | mutex_unlock(&cgroup_mutex); | ||
1857 | |||
1858 | return ret; | ||
1859 | } | ||
1860 | EXPORT_SYMBOL_GPL(task_cgroup_path_from_hierarchy); | ||
1861 | |||
1830 | /* | 1862 | /* |
1831 | * Control Group taskset | 1863 | * Control Group taskset |
1832 | */ | 1864 | */ |