lkml.org 
[lkml]   [2008]   [Apr]   [3]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
/
DateWed, 2 Apr 2008 21:36:13 -0700
From"Paul Menage" <>
SubjectRe: [PATCH 1/1] cgroups: introduce cft->read_seq()
On Wed, Apr 2, 2008 at 6:01 PM, Serge E. Hallyn <serue@us.ibm.com> wrote:
>  +       /*
>  +        * read_seq() is used for outputting a simple sequence
>  +        * using seqfile.
>  +        */
>  +       int (*read_seq) (struct cgroup *cont, struct cftype *cft,
>  +                        struct seq_file *m);

Maybe make it read_seq_string() to emphasise that it's not intended
for structured data?

>>  -static int cgroup_seqfile_show(struct seq_file *m, void *arg)
>  +static int cgroup_map_seqfile_show(struct seq_file *m, void *arg)
>   {
>         struct cgroup_seqfile_state *state = m->private;
>         struct cftype *cft = state->cft;
>  @@ -1529,6 +1529,13 @@ static int cgroup_seqfile_show(struct seq_file *m, void *arg)
>         return cft->read_map(state->cgroup, cft, &cb);
>   }

I think you can make this simpler - have cgroup_seqfile_show() switch
based on whether the cft has a read_seq_string or a read_map, and then
you only need one function.

>>  +static int cgroup_simple_seqfile_show(struct seq_file *m, void *arg)
>  +{
>  +       struct cgroup_seqfile_state *state = m->private;
>  +       struct cftype *cft = state->cft;
>  +       return cft->read_seq(state->cgroup, cft, m);
>  +}
>  +
>   int cgroup_seqfile_release(struct inode *inode, struct file *file)
>   {
>         struct seq_file *seq = file->private_data;
>  @@ -1562,7 +1569,18 @@ static int cgroup_file_open(struct inode *inode, struct file *file)
>                 state->cft = cft;
>                 state->cgroup = __d_cgrp(file->f_dentry->d_parent);
>                 file->f_op = &cgroup_seqfile_operations;
>  -               err = single_open(file, cgroup_seqfile_show, state);
>  +               err = single_open(file, cgroup_map_seqfile_show, state);
>  +               if (err < 0)
>  +                       kfree(state);
>  +       } else if (cft->read_seq) {
>  +               struct cgroup_seqfile_state *state =
>  +                       kzalloc(sizeof(*state), GFP_USER);
>  +               if (!state)
>  +                       return -ENOMEM;
>  +               state->cft = cft;
>  +               state->cgroup = __d_cgrp(file->f_dentry->d_parent);
>  +               file->f_op = &cgroup_seqfile_operations;
>  +               err = single_open(file, cgroup_simple_seqfile_show, state);
>                 if (err < 0)
>                         kfree(state);

and this arm can just be eliminated, by adding "||
cft->read_seq_string" to the test for cft_read_seq_map above.
It was always my intention that cgroup_seqfile_show() be able to
handle multiple data types, but up until now we only had one.

Paul


\
 
 \ /
  Last update: 2008-04-03 06:39    [from the cache]
©2003-2008