summaryrefslogtreecommitdiffstats
path: root/kernel/cgroup/cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2016-12-27 14:49:07 -0500
committerTejun Heo <tj@kernel.org>2016-12-27 14:49:07 -0500
commitfa069904dd38c2d8e121a3c7e37f8daaddb6dafa (patch)
tree770d75ea020938331ac3d2150ea1ec3848d7a067 /kernel/cgroup/cgroup.c
parent633feee310de6b6c3191011140b88fe772f560cf (diff)
cgroup: separate out cgroup1_kf_syscall_ops
Currently, cgroup_kf_syscall_ops is shared by v1 and v2 and the specific methods test the version and take different actions. Split out v1 functions and put them in cgroup1_kf_syscall_ops and remove the now unnecessary explicit branches in specific methods. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Acked-by: Zefan Li <lizefan@huawei.com>
Diffstat (limited to 'kernel/cgroup/cgroup.c')
-rw-r--r--kernel/cgroup/cgroup.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 228dd9ae708b..de6a2ac41d0b 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -1232,6 +1232,7 @@ struct cgroup *task_cgroup_from_root(struct task_struct *task,
1232 * update of a tasks cgroup pointer by cgroup_attach_task() 1232 * update of a tasks cgroup pointer by cgroup_attach_task()
1233 */ 1233 */
1234 1234
1235static struct kernfs_syscall_ops cgroup1_kf_syscall_ops;
1235static struct kernfs_syscall_ops cgroup_kf_syscall_ops; 1236static struct kernfs_syscall_ops cgroup_kf_syscall_ops;
1236 1237
1237static char *cgroup_file_name(struct cgroup *cgrp, const struct cftype *cft, 1238static char *cgroup_file_name(struct cgroup *cgrp, const struct cftype *cft,
@@ -1566,16 +1567,15 @@ static int cgroup_show_path(struct seq_file *sf, struct kernfs_node *kf_node,
1566 return len; 1567 return len;
1567} 1568}
1568 1569
1569static int cgroup_show_options(struct seq_file *seq, struct kernfs_root *kf_root) 1570static int cgroup1_show_options(struct seq_file *seq, struct kernfs_root *kf_root)
1570{ 1571{
1571 struct cgroup_root *root = cgroup_root_from_kf(kf_root); 1572 struct cgroup_root *root = cgroup_root_from_kf(kf_root);
1572 struct cgroup_subsys *ss; 1573 struct cgroup_subsys *ss;
1573 int ssid; 1574 int ssid;
1574 1575
1575 if (root != &cgrp_dfl_root) 1576 for_each_subsys(ss, ssid)
1576 for_each_subsys(ss, ssid) 1577 if (root->subsys_mask & (1 << ssid))
1577 if (root->subsys_mask & (1 << ssid)) 1578 seq_show_option(seq, ss->legacy_name, NULL);
1578 seq_show_option(seq, ss->legacy_name, NULL);
1579 if (root->flags & CGRP_ROOT_NOPREFIX) 1579 if (root->flags & CGRP_ROOT_NOPREFIX)
1580 seq_puts(seq, ",noprefix"); 1580 seq_puts(seq, ",noprefix");
1581 if (root->flags & CGRP_ROOT_XATTR) 1581 if (root->flags & CGRP_ROOT_XATTR)
@@ -1736,18 +1736,13 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
1736 return 0; 1736 return 0;
1737} 1737}
1738 1738
1739static int cgroup_remount(struct kernfs_root *kf_root, int *flags, char *data) 1739static int cgroup1_remount(struct kernfs_root *kf_root, int *flags, char *data)
1740{ 1740{
1741 int ret = 0; 1741 int ret = 0;
1742 struct cgroup_root *root = cgroup_root_from_kf(kf_root); 1742 struct cgroup_root *root = cgroup_root_from_kf(kf_root);
1743 struct cgroup_sb_opts opts; 1743 struct cgroup_sb_opts opts;
1744 u16 added_mask, removed_mask; 1744 u16 added_mask, removed_mask;
1745 1745
1746 if (root == &cgrp_dfl_root) {
1747 pr_err("remount is not allowed\n");
1748 return -EINVAL;
1749 }
1750
1751 cgroup_lock_and_drain_offline(&cgrp_dfl_root.cgrp); 1746 cgroup_lock_and_drain_offline(&cgrp_dfl_root.cgrp);
1752 1747
1753 /* See what subsystems are wanted */ 1748 /* See what subsystems are wanted */
@@ -1798,6 +1793,12 @@ static int cgroup_remount(struct kernfs_root *kf_root, int *flags, char *data)
1798 return ret; 1793 return ret;
1799} 1794}
1800 1795
1796static int cgroup_remount(struct kernfs_root *kf_root, int *flags, char *data)
1797{
1798 pr_err("remount is not allowed\n");
1799 return -EINVAL;
1800}
1801
1801/* 1802/*
1802 * To reduce the fork() overhead for systems that are not actually using 1803 * To reduce the fork() overhead for systems that are not actually using
1803 * their cgroups capability, we don't maintain the lists running through 1804 * their cgroups capability, we don't maintain the lists running through
@@ -1900,6 +1901,7 @@ static int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask)
1900{ 1901{
1901 LIST_HEAD(tmp_links); 1902 LIST_HEAD(tmp_links);
1902 struct cgroup *root_cgrp = &root->cgrp; 1903 struct cgroup *root_cgrp = &root->cgrp;
1904 struct kernfs_syscall_ops *kf_sops;
1903 struct css_set *cset; 1905 struct css_set *cset;
1904 int i, ret; 1906 int i, ret;
1905 1907
@@ -1931,7 +1933,10 @@ static int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask)
1931 if (ret) 1933 if (ret)
1932 goto cancel_ref; 1934 goto cancel_ref;
1933 1935
1934 root->kf_root = kernfs_create_root(&cgroup_kf_syscall_ops, 1936 kf_sops = root == &cgrp_dfl_root ?
1937 &cgroup_kf_syscall_ops : &cgroup1_kf_syscall_ops;
1938
1939 root->kf_root = kernfs_create_root(kf_sops,
1935 KERNFS_ROOT_CREATE_DEACTIVATED, 1940 KERNFS_ROOT_CREATE_DEACTIVATED,
1936 root_cgrp); 1941 root_cgrp);
1937 if (IS_ERR(root->kf_root)) { 1942 if (IS_ERR(root->kf_root)) {
@@ -4813,12 +4818,19 @@ static int cgroup_rmdir(struct kernfs_node *kn)
4813 return ret; 4818 return ret;
4814} 4819}
4815 4820
4821static struct kernfs_syscall_ops cgroup1_kf_syscall_ops = {
4822 .remount_fs = cgroup1_remount,
4823 .show_options = cgroup1_show_options,
4824 .rename = cgroup1_rename,
4825 .mkdir = cgroup_mkdir,
4826 .rmdir = cgroup_rmdir,
4827 .show_path = cgroup_show_path,
4828};
4829
4816static struct kernfs_syscall_ops cgroup_kf_syscall_ops = { 4830static struct kernfs_syscall_ops cgroup_kf_syscall_ops = {
4817 .remount_fs = cgroup_remount, 4831 .remount_fs = cgroup_remount,
4818 .show_options = cgroup_show_options,
4819 .mkdir = cgroup_mkdir, 4832 .mkdir = cgroup_mkdir,
4820 .rmdir = cgroup_rmdir, 4833 .rmdir = cgroup_rmdir,
4821 .rename = cgroup_rename,
4822 .show_path = cgroup_show_path, 4834 .show_path = cgroup_show_path,
4823}; 4835};
4824 4836