summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2016-12-27 14:49:03 -0500
committerTejun Heo <tj@kernel.org>2016-12-27 14:49:03 -0500
commite90cbebc3fa5caea4c8bfeb0d0157a0cee53efc7 (patch)
tree86c2bdab65cfde9766a6779979bd3836e71bdd74
parent0e67db2f9fe91937e798e3d7d22c50a8438187e1 (diff)
cgroup add cftype->open/release() callbacks
Pipe the newly added kernfs->open/release() callbacks through cftype. While at it, as cleanup operations now can be performed from ->release() instead of ->seq_stop(), make the latter optional. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Acked-by: Zefan Li <lizefan@huawei.com>
-rw-r--r--include/linux/cgroup-defs.h3
-rw-r--r--kernel/cgroup.c24
2 files changed, 26 insertions, 1 deletions
diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h
index 861b4677fc5b..8a916dc96e84 100644
--- a/include/linux/cgroup-defs.h
+++ b/include/linux/cgroup-defs.h
@@ -388,6 +388,9 @@ struct cftype {
388 struct list_head node; /* anchored at ss->cfts */ 388 struct list_head node; /* anchored at ss->cfts */
389 struct kernfs_ops *kf_ops; 389 struct kernfs_ops *kf_ops;
390 390
391 int (*open)(struct kernfs_open_file *of);
392 void (*release)(struct kernfs_open_file *of);
393
391 /* 394 /*
392 * read_u64() is a shortcut for the common case of returning a 395 * read_u64() is a shortcut for the common case of returning a
393 * single integer. Use it in place of read() 396 * single integer. Use it in place of read()
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 2ee9ec3051b2..87167e40c4fa 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -3503,6 +3503,23 @@ static int cgroup_events_show(struct seq_file *seq, void *v)
3503 return 0; 3503 return 0;
3504} 3504}
3505 3505
3506static int cgroup_file_open(struct kernfs_open_file *of)
3507{
3508 struct cftype *cft = of->kn->priv;
3509
3510 if (cft->open)
3511 return cft->open(of);
3512 return 0;
3513}
3514
3515static void cgroup_file_release(struct kernfs_open_file *of)
3516{
3517 struct cftype *cft = of->kn->priv;
3518
3519 if (cft->release)
3520 cft->release(of);
3521}
3522
3506static ssize_t cgroup_file_write(struct kernfs_open_file *of, char *buf, 3523static ssize_t cgroup_file_write(struct kernfs_open_file *of, char *buf,
3507 size_t nbytes, loff_t off) 3524 size_t nbytes, loff_t off)
3508{ 3525{
@@ -3553,7 +3570,8 @@ static void *cgroup_seqfile_next(struct seq_file *seq, void *v, loff_t *ppos)
3553 3570
3554static void cgroup_seqfile_stop(struct seq_file *seq, void *v) 3571static void cgroup_seqfile_stop(struct seq_file *seq, void *v)
3555{ 3572{
3556 seq_cft(seq)->seq_stop(seq, v); 3573 if (seq_cft(seq)->seq_stop)
3574 seq_cft(seq)->seq_stop(seq, v);
3557} 3575}
3558 3576
3559static int cgroup_seqfile_show(struct seq_file *m, void *arg) 3577static int cgroup_seqfile_show(struct seq_file *m, void *arg)
@@ -3575,12 +3593,16 @@ static int cgroup_seqfile_show(struct seq_file *m, void *arg)
3575 3593
3576static struct kernfs_ops cgroup_kf_single_ops = { 3594static struct kernfs_ops cgroup_kf_single_ops = {
3577 .atomic_write_len = PAGE_SIZE, 3595 .atomic_write_len = PAGE_SIZE,
3596 .open = cgroup_file_open,
3597 .release = cgroup_file_release,
3578 .write = cgroup_file_write, 3598 .write = cgroup_file_write,
3579 .seq_show = cgroup_seqfile_show, 3599 .seq_show = cgroup_seqfile_show,
3580}; 3600};
3581 3601
3582static struct kernfs_ops cgroup_kf_ops = { 3602static struct kernfs_ops cgroup_kf_ops = {
3583 .atomic_write_len = PAGE_SIZE, 3603 .atomic_write_len = PAGE_SIZE,
3604 .open = cgroup_file_open,
3605 .release = cgroup_file_release,
3584 .write = cgroup_file_write, 3606 .write = cgroup_file_write,
3585 .seq_start = cgroup_seqfile_start, 3607 .seq_start = cgroup_seqfile_start,
3586 .seq_next = cgroup_seqfile_next, 3608 .seq_next = cgroup_seqfile_next,