OpenVZ Forum


Home » Mailing lists » Devel » [PATCH][DOCUMENTATION] Minimal controller code for a quick start
Re: [PATCH][DOCUMENTATION] Minimal controller code for a quick start [message #27066 is a reply to message #27057] Thu, 07 February 2008 20:45 Go to previous messageGo to previous message
Paul Menage is currently offline  Paul Menage
Messages: 642
Registered: September 2006
Senior Member
On Feb 7, 2008 7:37 AM, Pavel Emelyanov <xemul@openvz.org> wrote:
> The Documentation/cgroups.txt file contains the info on how
> to write some controller for cgroups subsystem, but even with
> this, one need to write quite a lot of code before developing
> the core (or copy-n-paste it from some other place).

Good idea.

> +
> +static ssize_t foo_bar_read(struct cgroup *cg, struct cftype *cft,
> +               struct file *file, char __user *userbuf,
> +               size_t nbytes, loff_t *ppos)
> +{
> +       struct foo_cgroup *foo;
> +
> +       foo = foo_from_cgroup(cg);
> +
> +       /*
> +        * produce some output
> +        */
> +
> +       return nbytes;
> +}
> +
> +static ssize_t foo_bar_write(struct cgroup *cg, struct cftype *cft,
> +               struct file *file, const char __user *userbuf,
> +               size_t nbytes, loff_t *ppos)
> +{
> +       struct foo_cgroup *foo;
> +
> +       foo = foo_from_cgroup(cg);
> +
> +       /*
> +        * read and tune the foo
> +        */
> +
> +       return nbytes;
> +}
> +
> +static struct cftype foo_files[] = {
> +       {
> +               .name = "bar",
> +               .read = foo_bar_read,
> +               .write = foo_bar_write,
> +       },
> +};

Can you structure this example so as to encourage people to use the
more formatted read/write routines, such as read_int64 and
write_int64?

> +
> +static struct cgroup_subsys_state *foo_create(struct cgroup_subsys *cs,
> +               struct cgroup *cg)
> +{
> +       struct foo_cgroup *foo;
> +

Maybe add a comment here that mentions that if your cgroup needs very
early initialization, you can check for cg->parent being NULL, and
return a statically-constructed structure here. (And set
foo_subsys.early_init = 1)

Paul
_______________________________________________
Containers mailing list
Containers@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: RE: cgroup: limit network bandwidth
Next Topic: [PATCH 2.6.24-rc8-mm1 00/15] IPC: code rewrite + new functionalities
Goto Forum:
  


Current Time: Thu Jul 03 16:45:06 GMT 2025

Total time taken to generate the page: 0.02202 seconds