diff options
author | Paul Osmialowski <p.osmialowsk@samsung.com> | 2015-04-20 15:58:46 +0200 |
---|---|---|
committer | Maciej Wereski <m.wereski@partner.samsung.com> | 2015-06-09 11:31:26 +0200 |
commit | 48112584b20798290f037cc157c58d4014245dd0 (patch) | |
tree | 48b7465bbf693e92a494ffd7a4fa1359bd38731a | |
parent | f723a3f5e6392b7d73df168a47b4c7f5ef70461e (diff) | |
download | linux-3.10-48112584b20798290f037cc157c58d4014245dd0.tar.gz linux-3.10-48112584b20798290f037cc157c58d4014245dd0.tar.bz2 linux-3.10-48112584b20798290f037cc157c58d4014245dd0.zip |
kdbus: fix nasty warning when calling task_cgroup_path()
Change-Id: Ic6b472ec9f426cbdb1eea384cb3ddf699c5654f5
Signed-off-by: Paul Osmialowski <p.osmialowsk@samsung.com>
-rw-r--r-- | compat/include/linux/cgroup.h | 10 | ||||
-rw-r--r-- | kernel/cgroup.c | 69 |
2 files changed, 79 insertions, 0 deletions
diff --git a/compat/include/linux/cgroup.h b/compat/include/linux/cgroup.h new file mode 100644 index 00000000000..420554c72f1 --- /dev/null +++ b/compat/include/linux/cgroup.h @@ -0,0 +1,10 @@ +#ifndef __COMPAT_LINUX_CGROUP_H +#define __COMPAT_LINUX_CGROUP_H + +#include_next <linux/cgroup.h> + +extern char *__task_cgroup_path(struct task_struct *task, char *buf, size_t buflen); + +#define task_cgroup_path(task, buf, buflen) __task_cgroup_path(task, buf, buflen) + +#endif /* _COMPAT_LINUX_CGROUP_H */ diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 52519f1652b..49f54577d51 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -1838,6 +1838,35 @@ out: } EXPORT_SYMBOL_GPL(cgroup_path); +static char *__cgroup_path(const struct cgroup *cgrp, char *buf, int buflen) +{ + char *p = buf + buflen; + const char *name; + int len; + + *--p = '\0'; + + rcu_read_lock(); + do { + if (cgrp->parent) { + name = cgroup_name(cgrp); + len = strlen(name); + if (p - buf < len + 1) { + buf[0] = '\0'; + p = NULL; + break; + } + p -= len; + memcpy(p, name, len); + } + *--p = '/'; + cgrp = cgrp->parent; + } while (cgrp && cgrp->parent); + rcu_read_unlock(); + + return p; +} + /** * task_cgroup_path - cgroup path of a task in the first cgroup hierarchy * @task: target task @@ -1877,6 +1906,46 @@ int task_cgroup_path(struct task_struct *task, char *buf, size_t buflen) } EXPORT_SYMBOL_GPL(task_cgroup_path); +/** + * __task_cgroup_path - cgroup path of a task in the first cgroup hierarchy + * @task: target task + * @buf: the buffer to write the path into + * @buflen: the length of the buffer + * + * 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. + * + * Return value is the same as kernfs_path(). + */ +char *__task_cgroup_path(struct task_struct *task, char *buf, size_t buflen) +{ + struct cgroupfs_root *root; + struct cgroup *cgrp; + int hierarchy_id = 1; + char *path = NULL; + + if (buflen < 2) + return NULL; + + mutex_lock(&cgroup_mutex); + + root = idr_get_next(&cgroup_hierarchy_idr, &hierarchy_id); + + if (root) { + cgrp = task_cgroup_from_root(task, root); + path = __cgroup_path(cgrp, buf, buflen); + } else { + /* if no hierarchy exists, everyone is in "/" */ + memcpy(buf, "/", 2); + } + + mutex_unlock(&cgroup_mutex); + return path; +} +EXPORT_SYMBOL_GPL(__task_cgroup_path); + /* * Control Group taskset */ |