From 04b44514288156b1fe6351d73fc3047f3b46a18e Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Fri, 10 Feb 2023 14:48:33 -0700 Subject: [PATCH] tools/cgset: add support for default systemd delegation slice/scope Enhance the cgset 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, it 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/cgset -r cpu.weight=99 cgrp-d1 will set the cpu controller::cpu.weight setting 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/cgset -r cpu.weight=99 /cgrp1 or use the newly introduced -b switch to ignore the systemd slice/scope: $ sudo ./src/tools/cgset -b -r cpu.weight=99 cgrp1 Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka (cherry picked from commit 4dccb28d4a85990896940ec831cb88a90e778036) --- src/tools/cgset.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/tools/cgset.c b/src/tools/cgset.c index 77966165..89a73ca7 100644 --- a/src/tools/cgset.c +++ b/src/tools/cgset.c @@ -68,6 +68,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 */ @@ -121,6 +125,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; @@ -139,8 +144,16 @@ int main(int argc, char *argv[]) } /* parse arguments */ +#ifdef WITH_SYSTEMD + while ((c = getopt_long (argc, argv, "r:hb", long_options, NULL)) != -1) { + switch (c) { + case 'b': + ignore_default_systemd_delegate_slice = 1; + break; +#else while ((c = getopt_long (argc, argv, "r:h", long_options, NULL)) != -1) { switch (c) { +#endif case 'h': usage(0, argv[0]); ret = 0; @@ -209,6 +222,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