summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Osmialowski <p.osmialowsk@samsung.com>2015-04-20 15:58:46 +0200
committerPaul Osmialowski <p.osmialowsk@samsung.com>2015-04-20 16:10:11 +0200
commit7f68a68be45880d3ca509a62053f6dbb2d21047c (patch)
treed02cd7d80a3da16d38f5d8389fb5fd772269b6dc
parent8b8d02954ead87c1eb8db520e993a819efa868a3 (diff)
downloadlinux-3.10-7f68a68be45880d3ca509a62053f6dbb2d21047c.tar.gz
linux-3.10-7f68a68be45880d3ca509a62053f6dbb2d21047c.tar.bz2
linux-3.10-7f68a68be45880d3ca509a62053f6dbb2d21047c.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.h10
-rw-r--r--kernel/cgroup.c69
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
*/