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.hroma...@oracle.com> --- src/api.c | 19 +++++++++++++++++++ src/libcgroup-internal.h | 10 ++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/api.c b/src/api.c index b786dc614005..c4870046e8c2 100644 --- a/src/api.c +++ b/src/api.c @@ -5306,4 +5306,23 @@ int cgroup_get_subsys_mount_point_end(void **handle) 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; +} diff --git a/src/libcgroup-internal.h b/src/libcgroup-internal.h index 8c6b36c29966..57c870a8c41f 100644 --- a/src/libcgroup-internal.h +++ b/src/libcgroup-internal.h @@ -114,6 +114,7 @@ struct cg_mount_point { }; enum cg_version_t { + CGROUP_UNK = 0, CGROUP_V1, CGROUP_V2, }; @@ -297,6 +298,15 @@ extern void cgroup_dictionary_iterator_end(void **handle); */ 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 -- 2.25.3 _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel