]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
tools/cgxset add support for default systemd delegation slice/scope
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Fri, 3 Feb 2023 08:22:15 +0000 (08:22 +0000)
committerTom Hromatka <tom.hromatka@oracle.com>
Fri, 10 Feb 2023 21:44:25 +0000 (14:44 -0700)
Enhance the cgxset tool to support default systemd delegation slice/scope,
if set in the cgconfig.conf's systemd setting.  Parse the configuration
file and read the systemd::delegate setting, if any, and set it as
the default systemd slice/scope in systemd_default_cgroup.
Setting it appends the slice/scope name to the constructed default cgroup
mount path.

When the user passes the relative cgroup name, its appends to the
sub-tree (delegated slice/scope) by default and if the user wishes to set
controller::value in a cgroup under another subtree or cgroup root
hierarchy, they need to use the absolute path. For example:
  cgroup_root
 /     \
/      \
 systemd.slice*      cgrp1
|
 systemd.scope
|
    cgrp-d1

* default system delegation slice/scope - read from cgconfig.conf

$ sudo ./src/tools/cgxset 1 -r cpu.weight=99 cgrp-d1

will set the cpu controller:cpu.weight information under the
cgroup_root:systemd_default_cgroup:cgrp-d1

and for setting the cpu controller information of cgrp1, the user can
use:
$ sudo ./src/tools/cgxset -r cpu.weight=99 /cgrp1

or use the newly introduced -b switch to ignore the systemd
slice/scope:
$ sudo ./src/tools/cgxset -b -r cpu.weight=99 cgrp1

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/tools/cgxset.c

index 583902eea7e8f686d124b79729cda5dc3ce3b691..eaac1b09c93f249ae9f2eb24b2a0ba315c912b54 100644 (file)
@@ -82,6 +82,10 @@ static void usage(int status, const char *program_name)
        info("  -r, --variable <name>                   Define parameter to set\n");
        info("  --copy-from <source_cgroup_path>        Control group whose ");
        info("parameters will be copied\n");
+#ifdef WITH_SYSTEMD
+       info("  -b                                      Ignore default systemd ");
+       info("delegate hierarchy\n");
+#endif
 }
 #endif /* !UNIT_TEST */
 
@@ -135,6 +139,7 @@ err:
 #ifndef UNIT_TEST
 int main(int argc, char *argv[])
 {
+       int ignore_default_systemd_delegate_slice = 0;
        struct control_value *name_value = NULL;
        int nv_number = 0;
        int nv_max = 0;
@@ -155,9 +160,17 @@ int main(int argc, char *argv[])
                return -1;
        }
 
+#ifdef WITH_SYSTEMD
        /* parse arguments */
+       while ((c = getopt_long (argc, argv, "r:h12ib", long_options, NULL)) != -1) {
+               switch (c) {
+               case 'b':
+                       ignore_default_systemd_delegate_slice = 1;
+                       break;
+#else
        while ((c = getopt_long (argc, argv, "r:h12i", long_options, NULL)) != -1) {
                switch (c) {
+#endif
                case 'h':
                        usage(0, argv[0]);
                        ret = 0;
@@ -235,6 +248,10 @@ int main(int argc, char *argv[])
                goto err;
        }
 
+       /* this is false always for disable-systemd */
+       if (!ignore_default_systemd_delegate_slice)
+               cgroup_set_default_systemd_cgroup();
+
        /* copy the name-value pairs from -r options */
        if ((flags & FL_RULES) != 0) {
                src_cgroup = create_cgroup_from_name_value_pairs("tmp", name_value, nv_number);