From a3fae4de61bc64d499e5a288a0e853b73475684c Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Fri, 3 Feb 2023 08:22:15 +0000 Subject: [PATCH] tools/cgxset add support for default systemd delegation slice/scope 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 Signed-off-by: Tom Hromatka --- src/tools/cgxset.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/tools/cgxset.c b/src/tools/cgxset.c index 583902ee..eaac1b09 100644 --- a/src/tools/cgxset.c +++ b/src/tools/cgxset.c @@ -82,6 +82,10 @@ static void usage(int status, const char *program_name) info(" -r, --variable Define parameter to set\n"); info(" --copy-from 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); -- 2.47.2