From: Kamalesh Babulal Date: Tue, 10 Jan 2023 14:13:43 +0000 (+0000) Subject: tools/cgclassify: add support for default systemd delegation slice/scope X-Git-Tag: v3.1.0~204 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08ee9e36dee97bd32b0e648090b2e7570a1935fb;p=thirdparty%2Flibcgroup.git tools/cgclassify: add support for default systemd delegation slice/scope Enhance the cgclassify 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 create a cgroup in 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 cgclassify -g cpu:cgrp-d1 1379 (pid) will create the cgroup under the cpu controller hirearchy cgroup_root:systemd_default_cgroup:cgrp-d1 and for creating a cgroup cgrp1, the user can use: $ sudo cgclassify -g cpu:/cgrp1 1379 (pid) or use the newly introduced -b switch to ignore the systemd slice/scope: $ sudo cgclassify -b -g cpu:cgrp1 1379 (pid) Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/src/tools/cgclassify.c b/src/tools/cgclassify.c index 147b9dbf..f9f8aa88 100644 --- a/src/tools/cgclassify.c +++ b/src/tools/cgclassify.c @@ -41,6 +41,9 @@ static void usage(int status, const char *program_name) info(" --cancel-sticky cgred daemon change pidlist and children tasks\n"); info(" --sticky cgred daemon does not change "); info("pidlist and children tasks\n"); +#ifdef WITH_SYSTEMD + info(" -b Ignore default systemd delegate hierarchy\n"); +#endif } /* @@ -113,6 +116,7 @@ static struct option longopts[] = { int main(int argc, char *argv[]) { struct cgroup_group_spec *cgroup_list[CG_HIER_MAX]; + int ignore_default_systemd_delegate_slice = 0; int ret = 0, i, exit_code = 0; int cg_specified = 0; int flag = 0; @@ -126,8 +130,16 @@ int main(int argc, char *argv[]) } memset(cgroup_list, 0, sizeof(cgroup_list)); +#ifdef WITH_SYSTEMD + while ((c = getopt_long(argc, argv, "+g:shb", longopts, NULL)) > 0) { + switch (c) { + case 'b': + ignore_default_systemd_delegate_slice = 1; + break; +#else while ((c = getopt_long(argc, argv, "+g:sh", longopts, NULL)) > 0) { switch (c) { +#endif case 'h': usage(0, argv[0]); exit(0); @@ -160,6 +172,10 @@ int main(int argc, char *argv[]) return ret; } + /* this is false always for disable-systemd */ + if (!ignore_default_systemd_delegate_slice) + cgroup_set_default_systemd_cgroup(); + for (i = optind; i < argc; i++) { pid = (pid_t) strtol(argv[i], &endptr, 10); if (endptr[0] != '\0') {