This commit adds cgroup_get_controller_version() which returns
which version (cgroup v1 or cgroup v2) of a controller is mounted.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
return 0;
}
+int cgroup_get_controller_version(const char * const controller,
+ enum cg_version_t * const version)
+{
+ int i;
+
+ if (!version)
+ return ECGINVAL;
+
+ *version = CGROUP_UNK;
+
+ for (i = 0; cg_mount_table[i].name[0] != '\0'; i++) {
+ if (strncmp(cg_mount_table[i].name, controller,
+ sizeof(cg_mount_table[i].name)) == 0) {
+ *version = cg_mount_table[i].version;
+ return 0;
+ }
+ }
+ return ECGROUPNOTEXIST;
+}
};
enum cg_version_t {
+ CGROUP_UNK = 0,
CGROUP_V1,
CGROUP_V2,
};
*/
int cg_chmod_path(const char *path, mode_t mode, int owner_is_umask);
+/**
+ * Get the cgroup version of a controller. Version is set to CGROUP_UNK
+ * if the version cannot be determined.
+ *
+ * @param controller The controller of interest
+ * @param version The version of the controller
+ */
+int cgroup_get_controller_version(const char * const controller,
+ enum cg_version_t * const version);
/**
* Functions that are defined as STATIC can be placed within the UNIT_TEST
* ifdef. This will allow them to be included in the unit tests while