Store the cgroup version in struct cgroup_controller. Each controller can be mounted separately, and thus the cgroup version is applicable at the controller level.
Note that this commit requires cgroup_init() to be called by cgconfigparser. Storing the version in the cgroup_controller struct requires the cg_mount_table[] to be populated. Signed-off-by: Tom Hromatka <tom.hroma...@oracle.com> --- src/libcgroup-internal.h | 13 +++++++------ src/tools/cgconfig.c | 7 +++++++ src/wrapper.c | 11 ++++++++++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/libcgroup-internal.h b/src/libcgroup-internal.h index edc5abb9bdf6..cbec4cd361b9 100644 --- a/src/libcgroup-internal.h +++ b/src/libcgroup-internal.h @@ -85,6 +85,12 @@ extern "C" { #define max(x,y) ((y)<(x)?(x):(y)) #define min(x,y) ((y)>(x)?(x):(y)) +enum cg_version_t { + CGROUP_UNK = 0, + CGROUP_V1, + CGROUP_V2, +}; + struct control_value { char name[FILENAME_MAX]; char value[CG_CONTROL_VALUE_MAX]; @@ -99,6 +105,7 @@ struct cgroup_controller { struct control_value *values[CG_NV_MAX]; struct cgroup *cgroup; int index; + enum cg_version_t version; }; struct cgroup { @@ -119,12 +126,6 @@ struct cg_mount_point { struct cg_mount_point *next; }; -enum cg_version_t { - CGROUP_UNK = 0, - CGROUP_V1, - CGROUP_V2, -}; - struct cg_mount_table_s { /** Controller name. */ char name[FILENAME_MAX]; diff --git a/src/tools/cgconfig.c b/src/tools/cgconfig.c index e8bb5a2e553b..b5058db42e26 100644 --- a/src/tools/cgconfig.c +++ b/src/tools/cgconfig.c @@ -94,6 +94,13 @@ int main(int argc, char *argv[]) return -1; } + ret = cgroup_init(); + if (ret) { + fprintf(stderr, "%s: libcgroup initialization failed: %s\n", + argv[0], cgroup_strerror(ret)); + goto err; + } + error = cgroup_string_list_init(&cfg_files, argc/2); if (error) goto err; diff --git a/src/wrapper.c b/src/wrapper.c index 98ebcc266c41..0379da76c830 100644 --- a/src/wrapper.c +++ b/src/wrapper.c @@ -56,7 +56,7 @@ struct cgroup *cgroup_new_cgroup(const char *name) struct cgroup_controller *cgroup_add_controller(struct cgroup *cgroup, const char *name) { - int i; + int i, ret; struct cgroup_controller *controller; if (!cgroup) @@ -86,6 +86,15 @@ struct cgroup_controller *cgroup_add_controller(struct cgroup *cgroup, controller->cgroup = cgroup; controller->index = 0; + ret = cgroup_get_controller_version(controller->name, + &controller->version); + if (ret) { + cgroup_dbg("failed to get cgroup version for controller %s\n", + controller->name); + free(controller); + return NULL; + } + cgroup->controller[cgroup->index] = controller; cgroup->index++; -- 2.25.1 _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel