]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api: Add functions for iterating through the cgroup struct
authorTom Hromatka <tom.hromatka@oracle.com>
Tue, 20 Dec 2022 22:35:54 +0000 (22:35 +0000)
committerTom Hromatka <tom.hromatka@oracle.com>
Fri, 6 Jan 2023 15:28:47 +0000 (08:28 -0700)
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>
include/libcgroup/groups.h
src/api.c
src/libcgroup.map

index dc8479a6c3c90f9c39677f3fb38292cf1e1544c3..779d21a11f2dc72eaa97d5ccefbfb67c3b92705a 100644 (file)
@@ -650,6 +650,31 @@ int cgroup_get_controller_version(const char * const controller,
  */
 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);
+
 /**
  * @}
  * @}
index 1932832ce8640abee636daa9e2251b32e26c1716..484b46ab43561793ef3fcd48a30ddf6f83a3ed8f 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -6177,3 +6177,30 @@ out:
        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;
+}
index 0d582982f7d9d92d3b63415d8cfb07c3e02ac916..ce6c0546411c8e74b7725c419fe8a2f1fd4b56fb 100644 (file)
@@ -151,4 +151,7 @@ CGROUP_3.0 {
        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;