diff options
author | Tejun Heo <tj@kernel.org> | 2014-05-13 12:16:21 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2014-05-13 12:16:21 -0400 |
commit | b41686401e501430ffe93b575ef7959d2ecc6f2e (patch) | |
tree | 9d38bb6b2878c3107aaad43ab53ac145c4ed9a9e /kernel/cgroup.c | |
parent | ec903c0c858e4963a9e0724bdcadfa837253341c (diff) |
cgroup: implement cftype->write()
During the recent conversion to kernfs, cftype's seq_file operations
are updated so that they are directly mapped to kernfs operations and
thus can fully access the associated kernfs and cgroup contexts;
however, write path hasn't seen similar updates and none of the
existing write operations has access to, for example, the associated
kernfs_open_file.
Let's introduce a new operation cftype->write() which maps directly to
the kernfs write operation and has access to all the arguments and
contexts. This will replace ->write_string() and ->trigger() and ease
manipulation of kernfs active protection from cgroup file operations.
Two accessors - of_cft() and of_css() - are introduced to enable
accessing the associated cgroup context from cftype->write() which
only takes kernfs_open_file for the context information. The
accessors for seq_file operations - seq_cft() and seq_css() - are
rewritten to wrap the of_ accessors.
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.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 671d8a6dae37..a16f91d12f4e 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -283,11 +283,10 @@ static inline bool cgroup_is_dead(const struct cgroup *cgrp) | |||
283 | return test_bit(CGRP_DEAD, &cgrp->flags); | 283 | return test_bit(CGRP_DEAD, &cgrp->flags); |
284 | } | 284 | } |
285 | 285 | ||
286 | struct cgroup_subsys_state *seq_css(struct seq_file *seq) | 286 | struct cgroup_subsys_state *of_css(struct kernfs_open_file *of) |
287 | { | 287 | { |
288 | struct kernfs_open_file *of = seq->private; | ||
289 | struct cgroup *cgrp = of->kn->parent->priv; | 288 | struct cgroup *cgrp = of->kn->parent->priv; |
290 | struct cftype *cft = seq_cft(seq); | 289 | struct cftype *cft = of_cft(of); |
291 | 290 | ||
292 | /* | 291 | /* |
293 | * This is open and unprotected implementation of cgroup_css(). | 292 | * This is open and unprotected implementation of cgroup_css(). |
@@ -302,7 +301,7 @@ struct cgroup_subsys_state *seq_css(struct seq_file *seq) | |||
302 | else | 301 | else |
303 | return &cgrp->dummy_css; | 302 | return &cgrp->dummy_css; |
304 | } | 303 | } |
305 | EXPORT_SYMBOL_GPL(seq_css); | 304 | EXPORT_SYMBOL_GPL(of_css); |
306 | 305 | ||
307 | /** | 306 | /** |
308 | * cgroup_is_descendant - test ancestry | 307 | * cgroup_is_descendant - test ancestry |
@@ -1035,8 +1034,8 @@ static umode_t cgroup_file_mode(const struct cftype *cft) | |||
1035 | if (cft->read_u64 || cft->read_s64 || cft->seq_show) | 1034 | if (cft->read_u64 || cft->read_s64 || cft->seq_show) |
1036 | mode |= S_IRUGO; | 1035 | mode |= S_IRUGO; |
1037 | 1036 | ||
1038 | if (cft->write_u64 || cft->write_s64 || cft->write_string || | 1037 | if (cft->write_u64 || cft->write_s64 || cft->write || |
1039 | cft->trigger) | 1038 | cft->write_string || cft->trigger) |
1040 | mode |= S_IWUSR; | 1039 | mode |= S_IWUSR; |
1041 | 1040 | ||
1042 | return mode; | 1041 | return mode; |
@@ -2726,6 +2725,9 @@ static ssize_t cgroup_file_write(struct kernfs_open_file *of, char *buf, | |||
2726 | struct cgroup_subsys_state *css; | 2725 | struct cgroup_subsys_state *css; |
2727 | int ret; | 2726 | int ret; |
2728 | 2727 | ||
2728 | if (cft->write) | ||
2729 | return cft->write(of, buf, nbytes, off); | ||
2730 | |||
2729 | /* | 2731 | /* |
2730 | * kernfs guarantees that a file isn't deleted with operations in | 2732 | * kernfs guarantees that a file isn't deleted with operations in |
2731 | * flight, which means that the matching css is and stays alive and | 2733 | * flight, which means that the matching css is and stays alive and |