]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
tools/cgget: add support to print cgroup setup
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Tue, 25 Oct 2022 21:18:55 +0000 (15:18 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Tue, 25 Oct 2022 21:18:58 +0000 (15:18 -0600)
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 <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit ca42f62cdf5e4b0c3bb3920ab5aa52476cbe8096)

src/tools/cgget.c

index bf3e0aadc880de5b3493df68420e806c02cd2f58..545288465c16a37735124d5ee5de0a4fde2feed1 100644 (file)
@@ -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 <name>           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;
+}