aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Gushchin <guro@fb.com>2017-11-06 13:30:28 -0500
committerTejun Heo <tj@kernel.org>2017-11-06 15:01:54 -0500
commit01ee6cfb1483fe57c9cbd8e73817dfbf9bacffd3 (patch)
treee518d99f865f2dcb535737c4cce8402ba1278a20
parentc3ba13298709f46e72b22d087d0aa02bd012e4b0 (diff)
cgroup: export list of delegatable control files using sysfs
Delegatable cgroup v2 control files may require special handling (e.g. chowning), and the exact list of such files varies between kernel versions (and likely to be extended in the future). To guarantee correctness of this list and simplify the life of userspace (systemd, first of all), let's export the list via /sys/kernel/cgroup/delegate pseudo-file. Format is siple: each control file name is printed on a new line. Example: $ cat /sys/kernel/cgroup/delegate cgroup.procs cgroup.subtree_control Signed-off-by: Roman Gushchin <guro@fb.com> Cc: Tejun Heo <tj@kernel.org> Cc: kernel-team@fb.com Signed-off-by: Tejun Heo <tj@kernel.org>
-rw-r--r--kernel/cgroup/cgroup.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index d6ed725f36d9..eed92ed624e5 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -5832,3 +5832,64 @@ int cgroup_bpf_update(struct cgroup *cgrp, struct bpf_prog *prog,
5832 return ret; 5832 return ret;
5833} 5833}
5834#endif /* CONFIG_CGROUP_BPF */ 5834#endif /* CONFIG_CGROUP_BPF */
5835
5836#ifdef CONFIG_SYSFS
5837static ssize_t show_delegatable_files(struct cftype *files, char *buf,
5838 ssize_t size, const char *prefix)
5839{
5840 struct cftype *cft;
5841 ssize_t ret = 0;
5842
5843 for (cft = files; cft && cft->name[0] != '\0'; cft++) {
5844 if (!(cft->flags & CFTYPE_NS_DELEGATABLE))
5845 continue;
5846
5847 if (prefix)
5848 ret += snprintf(buf + ret, size - ret, "%s.", prefix);
5849
5850 ret += snprintf(buf + ret, size - ret, "%s\n", cft->name);
5851
5852 if (unlikely(ret >= size)) {
5853 WARN_ON(1);
5854 break;
5855 }
5856 }
5857
5858 return ret;
5859}
5860
5861static ssize_t delegate_show(struct kobject *kobj, struct kobj_attribute *attr,
5862 char *buf)
5863{
5864 struct cgroup_subsys *ss;
5865 int ssid;
5866 ssize_t ret = 0;
5867
5868 ret = show_delegatable_files(cgroup_base_files, buf, PAGE_SIZE - ret,
5869 NULL);
5870
5871 for_each_subsys(ss, ssid)
5872 ret += show_delegatable_files(ss->dfl_cftypes, buf + ret,
5873 PAGE_SIZE - ret,
5874 cgroup_subsys_name[ssid]);
5875
5876 return ret;
5877}
5878static struct kobj_attribute cgroup_delegate_attr = __ATTR_RO(delegate);
5879
5880static struct attribute *cgroup_sysfs_attrs[] = {
5881 &cgroup_delegate_attr.attr,
5882 NULL,
5883};
5884
5885static const struct attribute_group cgroup_sysfs_attr_group = {
5886 .attrs = cgroup_sysfs_attrs,
5887 .name = "cgroup",
5888};
5889
5890static int __init cgroup_sysfs_init(void)
5891{
5892 return sysfs_create_group(kernel_kobj, &cgroup_sysfs_attr_group);
5893}
5894subsys_initcall(cgroup_sysfs_init);
5895#endif /* CONFIG_SYSFS */