From: Kamalesh Babulal Date: Mon, 10 Oct 2022 15:52:14 +0000 (+0530) Subject: tools/cgget: add support to print cgroup setup X-Git-Tag: v3.1.0~284 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca42f62cdf5e4b0c3bb3920ab5aa52476cbe8096;p=thirdparty%2Flibcgroup.git tools/cgget: add support to print cgroup setup Add a new switch (-m), that will print the current cgroup mode the system/VM is booted it. It uses the API, cgroup_setup_mode() that returns one of the modes (Legacy/Unified/Hybrid) the system is booted with. $ cgget -m Legacy Mode (Cgroup v1 only). Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/src/tools/cgget.c b/src/tools/cgget.c index bf3e0aad..54528846 100644 --- a/src/tools/cgget.c +++ b/src/tools/cgget.c @@ -17,6 +17,8 @@ #define LL_MAX 100 +static int find_cgroup_mount_type(void); + static const struct option long_options[] = { {"variable", required_argument, NULL, 'r'}, {"help", no_argument, NULL, 'h'}, @@ -41,6 +43,7 @@ static void usage(int status, const char *program_name) info(" -r, --variable Define parameter to display\n"); info(" -v, --values-only Print only values, not "); info("parameter names\n"); + info(" -m Display the cgroup mode\n"); } static int get_controller_from_name(const char * const name, char **controller) @@ -395,7 +398,7 @@ static int parse_opts(int argc, char *argv[], struct cgroup **cg_list[], int * c int c; /* Parse arguments. */ - while ((c = getopt_long(argc, argv, "r:hnvg:a", long_options, NULL)) > 0) { + while ((c = getopt_long(argc, argv, "r:hnvg:am", long_options, NULL)) > 0) { switch (c) { case 'h': usage(0, argv[0]); @@ -434,6 +437,11 @@ static int parse_opts(int argc, char *argv[], struct cgroup **cg_list[], int * c if (ret) goto err; break; + case 'm': + ret = find_cgroup_mount_type(); + if (ret) + goto err; + break; default: usage(1, argv[0]); exit(EXIT_BADARGS); @@ -750,3 +758,28 @@ err: return ret; } + +static int find_cgroup_mount_type(void) +{ + enum cg_setup_mode_t setup_mode; + int ret = 0; + + setup_mode = cgroup_setup_mode(); + switch(setup_mode) { + case CGROUP_MODE_LEGACY: + info("Legacy Mode (Cgroup v1 only).\n"); + break; + case CGROUP_MODE_HYBRID: + info("Hybrid mode (Cgroup v1/v2).\n"); + break; + case CGROUP_MODE_UNIFIED: + info("Unified Mode (Cgroup v2 only).\n"); + break; + default: + err("Unable to determine the Cgroup setup mode.\n"); + ret = 1; + break; + } + + return ret; +}