Skip to content

Commit 913ffdb

Browse files
committed
cgroup: replace task_cgroup_path_from_hierarchy() with task_cgroup_path()
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 <[email protected]> Acked-by: Li Zefan <[email protected]> Cc: Lennart Poettering <[email protected]> Cc: Kay Sievers <[email protected]> Cc: Jan Kaluža <[email protected]>
1 parent add0c59 commit 913ffdb

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

include/linux/cgroup.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,7 @@ int cgroup_rm_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
540540
bool cgroup_is_descendant(struct cgroup *cgrp, struct cgroup *ancestor);
541541

542542
int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen);
543-
int task_cgroup_path_from_hierarchy(struct task_struct *task, int hierarchy_id,
544-
char *buf, size_t buflen);
543+
int task_cgroup_path(struct task_struct *task, char *buf, size_t buflen);
545544

546545
int cgroup_task_count(const struct cgroup *cgrp);
547546

kernel/cgroup.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,36 +1846,43 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen)
18461846
EXPORT_SYMBOL_GPL(cgroup_path);
18471847

18481848
/**
1849-
* task_cgroup_path_from_hierarchy - cgroup path of a task on a hierarchy
1849+
* task_cgroup_path - cgroup path of a task in the first cgroup hierarchy
18501850
* @task: target task
1851-
* @hierarchy_id: the hierarchy to look up @task's cgroup from
18521851
* @buf: the buffer to write the path into
18531852
* @buflen: the length of the buffer
18541853
*
1855-
* Determine @task's cgroup on the hierarchy specified by @hierarchy_id and
1856-
* copy its path into @buf. This function grabs cgroup_mutex and shouldn't
1857-
* be used inside locks used by cgroup controller callbacks.
1854+
* Determine @task's cgroup on the first (the one with the lowest non-zero
1855+
* hierarchy_id) cgroup hierarchy and copy its path into @buf. This
1856+
* function grabs cgroup_mutex and shouldn't be used inside locks used by
1857+
* cgroup controller callbacks.
1858+
*
1859+
* Returns 0 on success, fails with -%ENAMETOOLONG if @buflen is too short.
18581860
*/
1859-
int task_cgroup_path_from_hierarchy(struct task_struct *task, int hierarchy_id,
1860-
char *buf, size_t buflen)
1861+
int task_cgroup_path(struct task_struct *task, char *buf, size_t buflen)
18611862
{
18621863
struct cgroupfs_root *root;
1863-
struct cgroup *cgrp = NULL;
1864-
int ret = -ENOENT;
1864+
struct cgroup *cgrp;
1865+
int hierarchy_id = 1, ret = 0;
1866+
1867+
if (buflen < 2)
1868+
return -ENAMETOOLONG;
18651869

18661870
mutex_lock(&cgroup_mutex);
18671871

1868-
root = idr_find(&cgroup_hierarchy_idr, hierarchy_id);
1872+
root = idr_get_next(&cgroup_hierarchy_idr, &hierarchy_id);
1873+
18691874
if (root) {
18701875
cgrp = task_cgroup_from_root(task, root);
18711876
ret = cgroup_path(cgrp, buf, buflen);
1877+
} else {
1878+
/* if no hierarchy exists, everyone is in "/" */
1879+
memcpy(buf, "/", 2);
18721880
}
18731881

18741882
mutex_unlock(&cgroup_mutex);
1875-
18761883
return ret;
18771884
}
1878-
EXPORT_SYMBOL_GPL(task_cgroup_path_from_hierarchy);
1885+
EXPORT_SYMBOL_GPL(task_cgroup_path);
18791886

18801887
/*
18811888
* Control Group taskset

0 commit comments

Comments
 (0)