]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api.c: add cgroup_add_all_controllers function
authorIvana Hutarova Varekova <varekova@redhat.com>
Thu, 31 Jul 2014 09:37:26 +0000 (11:37 +0200)
committerIvana Hutarova Varekova <varekova@redhat.com>
Thu, 31 Jul 2014 09:37:26 +0000 (11:37 +0200)
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 <varekova@redhat.com>
Reviewed-by: Jan Chaloupka <jchaloup@redhat.com>
include/libcgroup/groups.h
src/libcgroup.map
src/wrapper.c

index d5c87aa55c1f04ae9c2640cdd05d66902806ef18..201558f69c60cff2ab97bf102c7af66f94af7f67 100644 (file)
@@ -149,6 +149,16 @@ struct cgroup *cgroup_new_cgroup(const char *name);
 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
index f8b0fb966ce40e94510bf6a0aadadf4d91c4ca4e..8fe199058e82de1c4d4346fe25382741fd2c6cb4 100644 (file)
@@ -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;
index c03472aa39eafe886f46722dc65fcceadde97ae7..3a9331fef148f5b66b2282fdc7af8b9c41c136b4 100644 (file)
@@ -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;