Commit acbef755 authored by Tejun Heo's avatar Tejun Heo

cgroup: convert "tasks" and "cgroup.procs" handle to use cftype->write()

cgroup_tasks_write() and cgroup_procs_write() are currently using
cftype->write_u64().  This patch converts them to use cftype->write()
instead.  This allows access to the associated kernfs_open_file which
will be necessary to implement the planned kernfs active protection
manipulation for these files.

This shifts buffer parsing to attach_task_by_pid() and makes it return
@nbytes on success.  Let's rename it to __cgroup_procs_write() to
clearly indicate that this is a write handler implementation.

This patch doesn't introduce any visible behavior changes.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarLi Zefan <lizefan@huawei.com>
parent 6770c64e
...@@ -2232,12 +2232,18 @@ static int cgroup_attach_task(struct cgroup *dst_cgrp, ...@@ -2232,12 +2232,18 @@ static int cgroup_attach_task(struct cgroup *dst_cgrp,
* function to attach either it or all tasks in its threadgroup. Will lock * function to attach either it or all tasks in its threadgroup. Will lock
* cgroup_mutex and threadgroup. * cgroup_mutex and threadgroup.
*/ */
static int attach_task_by_pid(struct cgroup *cgrp, u64 pid, bool threadgroup) static ssize_t __cgroup_procs_write(struct kernfs_open_file *of, char *buf,
size_t nbytes, loff_t off, bool threadgroup)
{ {
struct task_struct *tsk; struct task_struct *tsk;
const struct cred *cred = current_cred(), *tcred; const struct cred *cred = current_cred(), *tcred;
struct cgroup *cgrp = of_css(of)->cgroup;
pid_t pid;
int ret; int ret;
if (kstrtoint(strstrip(buf), 0, &pid) || pid < 0)
return -EINVAL;
if (!cgroup_lock_live_group(cgrp)) if (!cgroup_lock_live_group(cgrp))
return -ENODEV; return -ENODEV;
...@@ -2305,7 +2311,7 @@ static int attach_task_by_pid(struct cgroup *cgrp, u64 pid, bool threadgroup) ...@@ -2305,7 +2311,7 @@ static int attach_task_by_pid(struct cgroup *cgrp, u64 pid, bool threadgroup)
put_task_struct(tsk); put_task_struct(tsk);
out_unlock_cgroup: out_unlock_cgroup:
mutex_unlock(&cgroup_mutex); mutex_unlock(&cgroup_mutex);
return ret; return ret ?: nbytes;
} }
/** /**
...@@ -2339,16 +2345,16 @@ int cgroup_attach_task_all(struct task_struct *from, struct task_struct *tsk) ...@@ -2339,16 +2345,16 @@ int cgroup_attach_task_all(struct task_struct *from, struct task_struct *tsk)
} }
EXPORT_SYMBOL_GPL(cgroup_attach_task_all); EXPORT_SYMBOL_GPL(cgroup_attach_task_all);
static int cgroup_tasks_write(struct cgroup_subsys_state *css, static ssize_t cgroup_tasks_write(struct kernfs_open_file *of,
struct cftype *cft, u64 pid) char *buf, size_t nbytes, loff_t off)
{ {
return attach_task_by_pid(css->cgroup, pid, false); return __cgroup_procs_write(of, buf, nbytes, off, false);
} }
static int cgroup_procs_write(struct cgroup_subsys_state *css, static ssize_t cgroup_procs_write(struct kernfs_open_file *of,
struct cftype *cft, u64 tgid) char *buf, size_t nbytes, loff_t off)
{ {
return attach_task_by_pid(css->cgroup, tgid, true); return __cgroup_procs_write(of, buf, nbytes, off, true);
} }
static ssize_t cgroup_release_agent_write(struct kernfs_open_file *of, static ssize_t cgroup_release_agent_write(struct kernfs_open_file *of,
...@@ -3953,7 +3959,7 @@ static struct cftype cgroup_base_files[] = { ...@@ -3953,7 +3959,7 @@ static struct cftype cgroup_base_files[] = {
.seq_stop = cgroup_pidlist_stop, .seq_stop = cgroup_pidlist_stop,
.seq_show = cgroup_pidlist_show, .seq_show = cgroup_pidlist_show,
.private = CGROUP_FILE_PROCS, .private = CGROUP_FILE_PROCS,
.write_u64 = cgroup_procs_write, .write = cgroup_procs_write,
.mode = S_IRUGO | S_IWUSR, .mode = S_IRUGO | S_IWUSR,
}, },
{ {
...@@ -4002,7 +4008,7 @@ static struct cftype cgroup_base_files[] = { ...@@ -4002,7 +4008,7 @@ static struct cftype cgroup_base_files[] = {
.seq_stop = cgroup_pidlist_stop, .seq_stop = cgroup_pidlist_stop,
.seq_show = cgroup_pidlist_show, .seq_show = cgroup_pidlist_show,
.private = CGROUP_FILE_TASKS, .private = CGROUP_FILE_TASKS,
.write_u64 = cgroup_tasks_write, .write = cgroup_tasks_write,
.mode = S_IRUGO | S_IWUSR, .mode = S_IRUGO | S_IWUSR,
}, },
{ {
......
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