Commit fa069904 authored by Tejun Heo's avatar Tejun Heo

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: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarAcked-by: Zefan Li <lizefan@huawei.com>
parent 633feee3
...@@ -95,8 +95,8 @@ extern const struct file_operations proc_cgroupstats_operations; ...@@ -95,8 +95,8 @@ extern const struct file_operations proc_cgroupstats_operations;
bool cgroup_ssid_no_v1(int ssid); bool cgroup_ssid_no_v1(int ssid);
void cgroup_pidlist_destroy_all(struct cgroup *cgrp); void cgroup_pidlist_destroy_all(struct cgroup *cgrp);
int cgroup_rename(struct kernfs_node *kn, struct kernfs_node *new_parent, int cgroup1_rename(struct kernfs_node *kn, struct kernfs_node *new_parent,
const char *new_name_str); const char *new_name_str);
void cgroup_release_agent(struct work_struct *work); void cgroup_release_agent(struct work_struct *work);
void check_for_release(struct cgroup *cgrp); void check_for_release(struct cgroup *cgrp);
......
...@@ -800,8 +800,8 @@ void cgroup_release_agent(struct work_struct *work) ...@@ -800,8 +800,8 @@ void cgroup_release_agent(struct work_struct *work)
/* /*
* cgroup_rename - Only allow simple rename of directories in place. * cgroup_rename - Only allow simple rename of directories in place.
*/ */
int cgroup_rename(struct kernfs_node *kn, struct kernfs_node *new_parent, int cgroup1_rename(struct kernfs_node *kn, struct kernfs_node *new_parent,
const char *new_name_str) const char *new_name_str)
{ {
struct cgroup *cgrp = kn->priv; struct cgroup *cgrp = kn->priv;
int ret; int ret;
...@@ -811,13 +811,6 @@ int cgroup_rename(struct kernfs_node *kn, struct kernfs_node *new_parent, ...@@ -811,13 +811,6 @@ int cgroup_rename(struct kernfs_node *kn, struct kernfs_node *new_parent,
if (kn->parent != new_parent) if (kn->parent != new_parent)
return -EIO; return -EIO;
/*
* This isn't a proper migration and its usefulness is very
* limited. Disallow on the default hierarchy.
*/
if (cgroup_on_dfl(cgrp))
return -EPERM;
/* /*
* We're gonna grab cgroup_mutex which nests outside kernfs * We're gonna grab cgroup_mutex which nests outside kernfs
* active_ref. kernfs_rename() doesn't require active_ref * active_ref. kernfs_rename() doesn't require active_ref
......
...@@ -1232,6 +1232,7 @@ struct cgroup *task_cgroup_from_root(struct task_struct *task, ...@@ -1232,6 +1232,7 @@ struct cgroup *task_cgroup_from_root(struct task_struct *task,
* update of a tasks cgroup pointer by cgroup_attach_task() * update of a tasks cgroup pointer by cgroup_attach_task()
*/ */
static struct kernfs_syscall_ops cgroup1_kf_syscall_ops;
static struct kernfs_syscall_ops cgroup_kf_syscall_ops; static struct kernfs_syscall_ops cgroup_kf_syscall_ops;
static char *cgroup_file_name(struct cgroup *cgrp, const struct cftype *cft, 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,16 +1567,15 @@ static int cgroup_show_path(struct seq_file *sf, struct kernfs_node *kf_node,
return len; return len;
} }
static int cgroup_show_options(struct seq_file *seq, struct kernfs_root *kf_root) static int cgroup1_show_options(struct seq_file *seq, struct kernfs_root *kf_root)
{ {
struct cgroup_root *root = cgroup_root_from_kf(kf_root); struct cgroup_root *root = cgroup_root_from_kf(kf_root);
struct cgroup_subsys *ss; struct cgroup_subsys *ss;
int ssid; int ssid;
if (root != &cgrp_dfl_root) for_each_subsys(ss, ssid)
for_each_subsys(ss, ssid) if (root->subsys_mask & (1 << ssid))
if (root->subsys_mask & (1 << ssid)) seq_show_option(seq, ss->legacy_name, NULL);
seq_show_option(seq, ss->legacy_name, NULL);
if (root->flags & CGRP_ROOT_NOPREFIX) if (root->flags & CGRP_ROOT_NOPREFIX)
seq_puts(seq, ",noprefix"); seq_puts(seq, ",noprefix");
if (root->flags & CGRP_ROOT_XATTR) if (root->flags & CGRP_ROOT_XATTR)
...@@ -1736,18 +1736,13 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts) ...@@ -1736,18 +1736,13 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
return 0; return 0;
} }
static int cgroup_remount(struct kernfs_root *kf_root, int *flags, char *data) static int cgroup1_remount(struct kernfs_root *kf_root, int *flags, char *data)
{ {
int ret = 0; int ret = 0;
struct cgroup_root *root = cgroup_root_from_kf(kf_root); struct cgroup_root *root = cgroup_root_from_kf(kf_root);
struct cgroup_sb_opts opts; struct cgroup_sb_opts opts;
u16 added_mask, removed_mask; u16 added_mask, removed_mask;
if (root == &cgrp_dfl_root) {
pr_err("remount is not allowed\n");
return -EINVAL;
}
cgroup_lock_and_drain_offline(&cgrp_dfl_root.cgrp); cgroup_lock_and_drain_offline(&cgrp_dfl_root.cgrp);
/* See what subsystems are wanted */ /* See what subsystems are wanted */
...@@ -1798,6 +1793,12 @@ static int cgroup_remount(struct kernfs_root *kf_root, int *flags, char *data) ...@@ -1798,6 +1793,12 @@ static int cgroup_remount(struct kernfs_root *kf_root, int *flags, char *data)
return ret; return ret;
} }
static int cgroup_remount(struct kernfs_root *kf_root, int *flags, char *data)
{
pr_err("remount is not allowed\n");
return -EINVAL;
}
/* /*
* To reduce the fork() overhead for systems that are not actually using * To reduce the fork() overhead for systems that are not actually using
* their cgroups capability, we don't maintain the lists running through * 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,6 +1901,7 @@ static int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask)
{ {
LIST_HEAD(tmp_links); LIST_HEAD(tmp_links);
struct cgroup *root_cgrp = &root->cgrp; struct cgroup *root_cgrp = &root->cgrp;
struct kernfs_syscall_ops *kf_sops;
struct css_set *cset; struct css_set *cset;
int i, ret; int i, ret;
...@@ -1931,7 +1933,10 @@ static int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask) ...@@ -1931,7 +1933,10 @@ static int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask)
if (ret) if (ret)
goto cancel_ref; goto cancel_ref;
root->kf_root = kernfs_create_root(&cgroup_kf_syscall_ops, kf_sops = root == &cgrp_dfl_root ?
&cgroup_kf_syscall_ops : &cgroup1_kf_syscall_ops;
root->kf_root = kernfs_create_root(kf_sops,
KERNFS_ROOT_CREATE_DEACTIVATED, KERNFS_ROOT_CREATE_DEACTIVATED,
root_cgrp); root_cgrp);
if (IS_ERR(root->kf_root)) { if (IS_ERR(root->kf_root)) {
...@@ -4813,12 +4818,19 @@ static int cgroup_rmdir(struct kernfs_node *kn) ...@@ -4813,12 +4818,19 @@ static int cgroup_rmdir(struct kernfs_node *kn)
return ret; return ret;
} }
static struct kernfs_syscall_ops cgroup1_kf_syscall_ops = {
.remount_fs = cgroup1_remount,
.show_options = cgroup1_show_options,
.rename = cgroup1_rename,
.mkdir = cgroup_mkdir,
.rmdir = cgroup_rmdir,
.show_path = cgroup_show_path,
};
static struct kernfs_syscall_ops cgroup_kf_syscall_ops = { static struct kernfs_syscall_ops cgroup_kf_syscall_ops = {
.remount_fs = cgroup_remount, .remount_fs = cgroup_remount,
.show_options = cgroup_show_options,
.mkdir = cgroup_mkdir, .mkdir = cgroup_mkdir,
.rmdir = cgroup_rmdir, .rmdir = cgroup_rmdir,
.rename = cgroup_rename,
.show_path = cgroup_show_path, .show_path = cgroup_show_path,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment