On 07/31/2014 10:12 AM, Ivana Hutarova Varekova wrote: > cgroup_add_all_controllers function attach all mounted controllers to a given > cgroup. This function just modifies internal libcgroup structure, not the > kernel control group. > input parameter: cgroup > output parameter: zero or error number > > > Signed-off-by: Ivana Hutarova Varekova <varek...@redhat.com>
Reviewed-by: Jan Chaloupka<jchal...@redhat.com> > --- > include/libcgroup/groups.h | 10 +++++++++ > src/libcgroup.map | 7 ++++++ > src/wrapper.c | 50 > ++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 67 insertions(+) > > diff --git a/include/libcgroup/groups.h b/include/libcgroup/groups.h > index d5c87aa..201558f 100644 > --- a/include/libcgroup/groups.h > +++ b/include/libcgroup/groups.h > @@ -150,6 +150,16 @@ struct cgroup_controller *cgroup_add_controller(struct > cgroup *cgroup, > const char *name); > > /** > + * Attach all mounted controllers to given cgroup. This function just > modifies > + * internal libcgroup structure, not the kernel control group. > + * > + * @param cgroup > + * @return zero or error number > + */ > +int cgroup_add_all_controllers(struct cgroup *cgroup); > + > + > +/** > * Return appropriate controller from given group. > * The controller must be added before using cgroup_add_controller() or > loaded > * from kernel using cgroup_get_cgroup(). > diff --git a/src/libcgroup.map b/src/libcgroup.map > index f8b0fb9..8fe1990 100644 > --- a/src/libcgroup.map > +++ b/src/libcgroup.map > @@ -122,3 +122,10 @@ CGROUP_0.40 { > cgroup_templates_cache_set_source_files; > cgroup_load_templates_cache_from_files; > } CGROUP_0.39; > + > +CGROUP_0.41 { > +} CGROUP_0.40; > + > +CGROUP_0.42 { > + cgroup_add_all_controllers; > +} CGROUP_0.41; > diff --git a/src/wrapper.c b/src/wrapper.c > index c03472a..3a9331f 100644 > --- a/src/wrapper.c > +++ b/src/wrapper.c > @@ -92,6 +92,56 @@ struct cgroup_controller *cgroup_add_controller(struct > cgroup *cgroup, > return controller; > } > > +int cgroup_add_all_controllers(struct cgroup *cgroup) > +{ > + int ret; > + void *handle; > + struct controller_data info; > + struct cgroup_controller *cgc; > + > + /* go through the controller list */ > + ret = cgroup_get_all_controller_begin(&handle, &info); > + if ((ret != 0) && (ret != ECGEOF)) { > + fprintf(stderr, "cannot read controller data: %s\n", > + cgroup_strerror(ret)); > + return ret; > + } > + > + while (ret == 0) { > + if (info.hierarchy == 0) { > + /* the controller is not attached to any hierarchy > + skip it */ > + goto next; > + } > + > + /* add mounted controller to cgroup structure */ > + cgc = cgroup_add_controller(cgroup, info.name); > + if (!cgc) { > + ret = ECGINVAL; > + fprintf(stderr, "controller %s can't be add\n", > + info.name); > + } > + > +next: > + ret = cgroup_get_all_controller_next(&handle, &info); > + if (ret && ret != ECGEOF) > + goto end; > + } > + > +end: > + cgroup_get_all_controller_end(&handle); > + > + if (ret == ECGEOF) > + ret = 0; > + > + if (ret) > + fprintf(stderr, > + "cgroup_get_controller_begin/next failed (%s)\n", > + cgroup_strerror(ret)); > + > + return ret; > +} > + > void cgroup_free_controllers(struct cgroup *cgroup) > { > int i, j; > > > ------------------------------------------------------------------------------ > Infragistics Professional > Build stunning WinForms apps today! > Reboot your WinForms applications with our WinForms controls. > Build a bridge from your legacy apps to the future. > http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk > _______________________________________________ > Libcg-devel mailing list > Libcg-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/libcg-devel -- Jan Chaloupka ------------------------------ * Software Engineer * * ENG Base Operating Systems * * Red Hat Czech, s. r. o. * * UTC+1 (CET), jchaloup * ------------------------------------------------------------------------------ Infragistics Professional Build stunning WinForms apps today! Reboot your WinForms applications with our WinForms controls. Build a bridge from your legacy apps to the future. http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel