Add functions to iterate through the cgroup structure:
cgroup_get_controller_count() - returns the number of controllers
within the cgroup struct
cgroup_get_controller_by_index() - returns the cgroup_controller
pointer corresponding with the requested index
cgroup_get_controller_name() - given a cgroup_controller pointer,
get the controller's name
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
*/
enum cg_setup_mode_t cgroup_setup_mode(void);
+/**
+ * Return the number of controllers for the specified cgroup in libcgroup
+ * internal structures.
+ *
+ * @param cgroup
+ * @return Count of the controllers or -1 on error.
+ */
+int cgroup_get_controller_count(struct cgroup *cgroup);
+
+/**
+ * Return requested controller from given group
+ *
+ * @param cgroup
+ * @param index The index into the cgroup controller list
+ */
+struct cgroup_controller *cgroup_get_controller_by_index(struct cgroup *cgroup, int index);
+
+/**
+ * Given a controller pointer, get the name of the controller
+ *
+ * @param controller
+ * @return controller name string, NULL if there's an error
+ */
+char *cgroup_get_controller_name(struct cgroup_controller *controller);
+
/**
* @}
* @}
pthread_rwlock_unlock(&cg_mount_table_lock);
return setup_mode;
}
+
+int cgroup_get_controller_count(struct cgroup *cgroup)
+{
+ if (!cgroup)
+ return -1;
+
+ return cgroup->index;
+}
+
+struct cgroup_controller *cgroup_get_controller_by_index(struct cgroup *cgroup, int index)
+{
+ if (!cgroup)
+ return NULL;
+
+ if (index >= cgroup->index)
+ return NULL;
+
+ return cgroup->controller[index];
+}
+
+char *cgroup_get_controller_name(struct cgroup_controller *controller)
+{
+ if (!controller)
+ return NULL;
+
+ return controller->name;
+}
cgroup_setup_mode;
cgroup_create_scope;
cgroup_set_default_scope_opts;
+ cgroup_get_controller_count;
+ cgroup_get_controller_by_index;
+ cgroup_get_controller_name;
} CGROUP_2.0;