aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-11-29 10:42:58 -0500
committerTejun Heo <tj@kernel.org>2013-11-29 10:42:58 -0500
commit62236858f3cc558135d1ab6b2af44d22c489bb7f (patch)
treedc3b917fe5e4ad9f22daf443f8efe50d23a9e64c /kernel/cgroup.c
parentb1a21367314f36a819c0676e0999f34db12ee6ed (diff)
cgroup: introduce struct cgroup_pidlist_open_file
For pidlist files, seq_file->private pointed to the loaded cgroup_pidlist; however, pidlist loading is planned to be moved to cgroup_pidlist_start() for kernfs conversion and seq_file->private needs to carry more information from open to allow that. This patch introduces struct cgroup_pidlist_open_file which contains type, cgrp and pidlist and updates pidlist seq_file->private to point to it using seq_open_private() and seq_release_private(). Note that this eventually will be replaced by kernfs_open_file. While this patch makes more information available to seq_file operations, they don't use it yet and this patch doesn't introduce any behavior changes except for allocation of the extra private struct. v2: use __seq_open_private() instead of seq_open_private() for brevity as suggested by Li. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r--kernel/cgroup.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index acdcddf8ab82..ef019c075d5d 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -3468,6 +3468,13 @@ struct cgroup_pidlist {
3468 struct delayed_work destroy_dwork; 3468 struct delayed_work destroy_dwork;
3469}; 3469};
3470 3470
3471/* seq_file->private points to the following */
3472struct cgroup_pidlist_open_file {
3473 enum cgroup_filetype type;
3474 struct cgroup *cgrp;
3475 struct cgroup_pidlist *pidlist;
3476};
3477
3471/* 3478/*
3472 * The following two functions "fix" the issue where there are more pids 3479 * The following two functions "fix" the issue where there are more pids
3473 * than kmalloc will give memory for; in such cases, we use vmalloc/vfree. 3480 * than kmalloc will give memory for; in such cases, we use vmalloc/vfree.
@@ -3739,7 +3746,8 @@ static void *cgroup_pidlist_start(struct seq_file *s, loff_t *pos)
3739 * after a seek to the start). Use a binary-search to find the 3746 * after a seek to the start). Use a binary-search to find the
3740 * next pid to display, if any 3747 * next pid to display, if any
3741 */ 3748 */
3742 struct cgroup_pidlist *l = s->private; 3749 struct cgroup_pidlist_open_file *of = s->private;
3750 struct cgroup_pidlist *l = of->pidlist;
3743 int index = 0, pid = *pos; 3751 int index = 0, pid = *pos;
3744 int *iter; 3752 int *iter;
3745 3753
@@ -3769,13 +3777,15 @@ static void *cgroup_pidlist_start(struct seq_file *s, loff_t *pos)
3769 3777
3770static void cgroup_pidlist_stop(struct seq_file *s, void *v) 3778static void cgroup_pidlist_stop(struct seq_file *s, void *v)
3771{ 3779{
3772 struct cgroup_pidlist *l = s->private; 3780 struct cgroup_pidlist_open_file *of = s->private;
3773 up_read(&l->rwsem); 3781
3782 up_read(&of->pidlist->rwsem);
3774} 3783}
3775 3784
3776static void *cgroup_pidlist_next(struct seq_file *s, void *v, loff_t *pos) 3785static void *cgroup_pidlist_next(struct seq_file *s, void *v, loff_t *pos)
3777{ 3786{
3778 struct cgroup_pidlist *l = s->private; 3787 struct cgroup_pidlist_open_file *of = s->private;
3788 struct cgroup_pidlist *l = of->pidlist;
3779 pid_t *p = v; 3789 pid_t *p = v;
3780 pid_t *end = l->list + l->length; 3790 pid_t *end = l->list + l->length;
3781 /* 3791 /*
@@ -3820,11 +3830,11 @@ static void cgroup_release_pid_array(struct cgroup_pidlist *l)
3820 3830
3821static int cgroup_pidlist_release(struct inode *inode, struct file *file) 3831static int cgroup_pidlist_release(struct inode *inode, struct file *file)
3822{ 3832{
3823 struct cgroup_pidlist *l; 3833 struct cgroup_pidlist_open_file *of;
3824 3834
3825 l = ((struct seq_file *)file->private_data)->private; 3835 of = ((struct seq_file *)file->private_data)->private;
3826 cgroup_release_pid_array(l); 3836 cgroup_release_pid_array(of->pidlist);
3827 return seq_release(inode, file); 3837 return seq_release_private(inode, file);
3828} 3838}
3829 3839
3830static const struct file_operations cgroup_pidlist_operations = { 3840static const struct file_operations cgroup_pidlist_operations = {
@@ -3843,6 +3853,7 @@ static const struct file_operations cgroup_pidlist_operations = {
3843static int cgroup_pidlist_open(struct file *file, enum cgroup_filetype type) 3853static int cgroup_pidlist_open(struct file *file, enum cgroup_filetype type)
3844{ 3854{
3845 struct cgroup *cgrp = __d_cgrp(file->f_dentry->d_parent); 3855 struct cgroup *cgrp = __d_cgrp(file->f_dentry->d_parent);
3856 struct cgroup_pidlist_open_file *of;
3846 struct cgroup_pidlist *l; 3857 struct cgroup_pidlist *l;
3847 int retval; 3858 int retval;
3848 3859
@@ -3853,12 +3864,16 @@ static int cgroup_pidlist_open(struct file *file, enum cgroup_filetype type)
3853 /* configure file information */ 3864 /* configure file information */
3854 file->f_op = &cgroup_pidlist_operations; 3865 file->f_op = &cgroup_pidlist_operations;
3855 3866
3856 retval = seq_open(file, &cgroup_pidlist_seq_operations); 3867 of = __seq_open_private(file, &cgroup_pidlist_seq_operations,
3857 if (retval) { 3868 sizeof(*of));
3869 if (!of) {
3858 cgroup_release_pid_array(l); 3870 cgroup_release_pid_array(l);
3859 return retval; 3871 return -ENOMEM;
3860 } 3872 }
3861 ((struct seq_file *)file->private_data)->private = l; 3873
3874 of->type = type;
3875 of->cgrp = cgrp;
3876 of->pidlist = l;
3862 return 0; 3877 return 0;
3863} 3878}
3864static int cgroup_tasks_open(struct inode *unused, struct file *file) 3879static int cgroup_tasks_open(struct inode *unused, struct file *file)