diff options
author | Tejun Heo <tj@kernel.org> | 2016-12-27 14:49:07 -0500 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2016-12-27 14:49:07 -0500 |
commit | fa069904dd38c2d8e121a3c7e37f8daaddb6dafa (patch) | |
tree | 770d75ea020938331ac3d2150ea1ec3848d7a067 | |
parent | 633feee310de6b6c3191011140b88fe772f560cf (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>
-rw-r--r-- | kernel/cgroup/cgroup-internal.h | 4 | ||||
-rw-r--r-- | kernel/cgroup/cgroup-v1.c | 11 | ||||
-rw-r--r-- | kernel/cgroup/cgroup.c | 40 |
3 files changed, 30 insertions, 25 deletions
diff --git a/kernel/cgroup/cgroup-internal.h b/kernel/cgroup/cgroup-internal.h index dca3193bd9d2..5790e5ff9a0f 100644 --- a/kernel/cgroup/cgroup-internal.h +++ b/kernel/cgroup/cgroup-internal.h | |||
@@ -95,8 +95,8 @@ extern const struct file_operations proc_cgroupstats_operations; | |||
95 | 95 | ||
96 | bool cgroup_ssid_no_v1(int ssid); | 96 | bool cgroup_ssid_no_v1(int ssid); |
97 | void cgroup_pidlist_destroy_all(struct cgroup *cgrp); | 97 | void cgroup_pidlist_destroy_all(struct cgroup *cgrp); |
98 | int cgroup_rename(struct kernfs_node *kn, struct kernfs_node *new_parent, | 98 | int cgroup1_rename(struct kernfs_node *kn, struct kernfs_node *new_parent, |
99 | const char *new_name_str); | 99 | const char *new_name_str); |
100 | void cgroup_release_agent(struct work_struct *work); | 100 | void cgroup_release_agent(struct work_struct *work); |
101 | void check_for_release(struct cgroup *cgrp); | 101 | void check_for_release(struct cgroup *cgrp); |
102 | 102 | ||
diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c index 7af745a46f91..0b2c24f0b310 100644 --- a/kernel/cgroup/cgroup-v1.c +++ b/kernel/cgroup/cgroup-v1.c | |||
@@ -800,8 +800,8 @@ out_free: | |||
800 | /* | 800 | /* |
801 | * cgroup_rename - Only allow simple rename of directories in place. | 801 | * cgroup_rename - Only allow simple rename of directories in place. |
802 | */ | 802 | */ |
803 | int cgroup_rename(struct kernfs_node *kn, struct kernfs_node *new_parent, | 803 | int cgroup1_rename(struct kernfs_node *kn, struct kernfs_node *new_parent, |
804 | const char *new_name_str) | 804 | const char *new_name_str) |
805 | { | 805 | { |
806 | struct cgroup *cgrp = kn->priv; | 806 | struct cgroup *cgrp = kn->priv; |
807 | int ret; | 807 | int ret; |
@@ -812,13 +812,6 @@ int cgroup_rename(struct kernfs_node *kn, struct kernfs_node *new_parent, | |||
812 | return -EIO; | 812 | return -EIO; |
813 | 813 | ||
814 | /* | 814 | /* |
815 | * This isn't a proper migration and its usefulness is very | ||
816 | * limited. Disallow on the default hierarchy. | ||
817 | */ | ||
818 | if (cgroup_on_dfl(cgrp)) | ||
819 | return -EPERM; | ||
820 | |||
821 | /* | ||
822 | * We're gonna grab cgroup_mutex which nests outside kernfs | 815 | * We're gonna grab cgroup_mutex which nests outside kernfs |
823 | * active_ref. kernfs_rename() doesn't require active_ref | 816 | * active_ref. kernfs_rename() doesn't require active_ref |
824 | * protection. Break them before grabbing cgroup_mutex. | 817 | * protection. Break them before grabbing cgroup_mutex. |
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 | ||
1235 | static struct kernfs_syscall_ops cgroup1_kf_syscall_ops; | ||
1235 | static struct kernfs_syscall_ops cgroup_kf_syscall_ops; | 1236 | static struct kernfs_syscall_ops cgroup_kf_syscall_ops; |
1236 | 1237 | ||
1237 | static char *cgroup_file_name(struct cgroup *cgrp, const struct cftype *cft, | 1238 | static 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 | ||
1569 | static int cgroup_show_options(struct seq_file *seq, struct kernfs_root *kf_root) | 1570 | static 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 | ||
1739 | static int cgroup_remount(struct kernfs_root *kf_root, int *flags, char *data) | 1739 | static 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 | ||
1796 | static 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 | ||
4821 | static 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 | |||
4816 | static struct kernfs_syscall_ops cgroup_kf_syscall_ops = { | 4830 | static 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 | ||