summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/cgroup.h1
-rw-r--r--kernel/cgroup.c35
2 files changed, 36 insertions, 0 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index a20320c666fd..984f73b719a9 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -87,6 +87,7 @@ struct cgroup_subsys_state *css_tryget_online_from_dir(struct dentry *dentry,
87 struct cgroup_subsys *ss); 87 struct cgroup_subsys *ss);
88 88
89struct cgroup *cgroup_get_from_path(const char *path); 89struct cgroup *cgroup_get_from_path(const char *path);
90struct cgroup *cgroup_get_from_fd(int fd);
90 91
91int cgroup_attach_task_all(struct task_struct *from, struct task_struct *); 92int cgroup_attach_task_all(struct task_struct *from, struct task_struct *);
92int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from); 93int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from);
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 75c0ff00aca6..50787cd61da2 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -62,6 +62,7 @@
62#include <linux/proc_ns.h> 62#include <linux/proc_ns.h>
63#include <linux/nsproxy.h> 63#include <linux/nsproxy.h>
64#include <linux/proc_ns.h> 64#include <linux/proc_ns.h>
65#include <linux/file.h>
65#include <net/sock.h> 66#include <net/sock.h>
66 67
67/* 68/*
@@ -6209,6 +6210,40 @@ struct cgroup *cgroup_get_from_path(const char *path)
6209} 6210}
6210EXPORT_SYMBOL_GPL(cgroup_get_from_path); 6211EXPORT_SYMBOL_GPL(cgroup_get_from_path);
6211 6212
6213/**
6214 * cgroup_get_from_fd - get a cgroup pointer from a fd
6215 * @fd: fd obtained by open(cgroup2_dir)
6216 *
6217 * Find the cgroup from a fd which should be obtained
6218 * by opening a cgroup directory. Returns a pointer to the
6219 * cgroup on success. ERR_PTR is returned if the cgroup
6220 * cannot be found.
6221 */
6222struct cgroup *cgroup_get_from_fd(int fd)
6223{
6224 struct cgroup_subsys_state *css;
6225 struct cgroup *cgrp;
6226 struct file *f;
6227
6228 f = fget_raw(fd);
6229 if (!f)
6230 return ERR_PTR(-EBADF);
6231
6232 css = css_tryget_online_from_dir(f->f_path.dentry, NULL);
6233 fput(f);
6234 if (IS_ERR(css))
6235 return ERR_CAST(css);
6236
6237 cgrp = css->cgroup;
6238 if (!cgroup_on_dfl(cgrp)) {
6239 cgroup_put(cgrp);
6240 return ERR_PTR(-EBADF);
6241 }
6242
6243 return cgrp;
6244}
6245EXPORT_SYMBOL_GPL(cgroup_get_from_fd);
6246
6212/* 6247/*
6213 * sock->sk_cgrp_data handling. For more info, see sock_cgroup_data 6248 * sock->sk_cgrp_data handling. For more info, see sock_cgroup_data
6214 * definition in cgroup-defs.h. 6249 * definition in cgroup-defs.h.