From: Tom Hromatka Date: Wed, 24 Mar 2021 16:38:22 +0000 (-0600) Subject: lssubsys: Add cgroup v2 support X-Git-Tag: v2.0.rc1~3^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=68fef57c291b511d88eea632300a48403e0dfb4e;p=thirdparty%2Flibcgroup.git lssubsys: Add cgroup v2 support Ignore a hierarchy value of zero for cgroup v2 controllers. This change adds minimal cgroup v2 support to lssubsys. Signed-off-by: Tom Hromatka --- diff --git a/src/libcgroup.map b/src/libcgroup.map index 89679656..29f6dd16 100644 --- a/src/libcgroup.map +++ b/src/libcgroup.map @@ -137,4 +137,5 @@ CGROUP_0.43 { cgroup_test_subsys_mounted; cg_mount_table; cg_mount_table_lock; + cgroup_get_controller_version; } CGROUP_0.42; diff --git a/src/tools/lssubsys.c b/src/tools/lssubsys.c index bd2e5d5f..d0a88b62 100644 --- a/src/tools/lssubsys.c +++ b/src/tools/lssubsys.c @@ -95,6 +95,7 @@ static int print_all_controllers_in_hierarchy(const char *tname, int first = 1; cont_name_t cont_names; cont_name_t cont_name; + enum cg_version_t version; /* * Initialize libcgroup and intentionally ignore its result, @@ -110,8 +111,14 @@ static int print_all_controllers_in_hierarchy(const char *tname, } while (ret != ECGEOF) { - /* controller is in the hierrachy */ - if (info.hierarchy != hierarchy) + ret = cgroup_get_controller_version(info.name, &version); + if (ret) + goto end; + + /* v1 controllers should be in the hierachy. v2 controllers + * will have a hierarchy value of zero + */ + if (version == CGROUP_V1 && info.hierarchy != hierarchy) goto next; if (first) { @@ -162,7 +169,7 @@ static int cgroup_list_all_controllers(const char *tname, ret = cgroup_get_all_controller_begin(&handle, &info); while (ret == 0) { if (info.hierarchy == 0) { - /* the controller is not attached to any hierrachy */ + /* the controller is not attached to any hierachy */ if (flags & FL_ALL) /* display only if -a flag is set */ printf("%s\n", info.name);