From 6ac3bd9b9d9873c49478334a41b13243771dd9af Mon Sep 17 00:00:00 2001 From: Ivana Hutarova Varekova Date: Thu, 31 Jul 2014 11:40:00 +0200 Subject: [PATCH] cgcreate: use "*" character as a meta character for all mounted controllers This patch adds the possibility to use meta character "*" as a shortcut for all mounted controllers. This meta character can be used in "-g" option. For example: $ cgcreate -g *:first -g cpu:second $ lssubsys cpuset:/ cpuset:/first cpu,cpuacct:/ cpu,cpuacct:/first cpu,cpuacct:/second memory:/ memory:/first devices:/ devices:/first freezer:/ freezer:/first net_cls,net_prio:/ net_cls,net_prio:/first blkio:/ blkio:/first perf_event:/ perf_event:/first hugetlb:/ hugetlb:/first Signed-off-by: Ivana Hutarova Varekova Reviewed-by: Jan Chaloupka --- doc/man/cgcreate.1 | 3 ++- src/tools/cgcreate.c | 32 ++++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/doc/man/cgcreate.1 b/doc/man/cgcreate.1 index 70680736..557b5aee 100644 --- a/doc/man/cgcreate.1 +++ b/doc/man/cgcreate.1 @@ -38,7 +38,8 @@ others permissions to the owners permissions). .TP .B -g : defines control groups to be added. -\fBcontrollers\fR is a list of controllers and +\fBcontrollers\fR is a list of controllers. Character "*" can be used +as a shortcut for "all mounted controllers". \fBpath\fR is the relative path to control groups in the given controllers list. This option can be specified multiple times. diff --git a/src/tools/cgcreate.c b/src/tools/cgcreate.c index 73abd91d..65b188a9 100644 --- a/src/tools/cgcreate.c +++ b/src/tools/cgcreate.c @@ -54,7 +54,6 @@ static void usage(int status, const char *program_name) printf(" -t : Owner of the tasks file\n"); } - int main(int argc, char *argv[]) { int ret = 0; @@ -195,16 +194,29 @@ int main(int argc, char *argv[]) /* add controllers to the new cgroup */ j = 0; while (cgroup_list[i]->controllers[j]) { - cgc = cgroup_add_controller(cgroup, - cgroup_list[i]->controllers[j]); - if (!cgc) { - ret = ECGINVAL; - fprintf(stderr, "%s: " - "controller %s can't be add\n", - argv[0], + if (strcmp(cgroup_list[i]->controllers[j], "*") == 0) { + /* it is meta character, add all controllers */ + ret = cgroup_add_all_controllers(cgroup); + if (ret != 0) { + ret = ECGINVAL; + fprintf(stderr, "%s: can't add ", + argv[0]); + fprintf(stderr, "all controllers\n"); + cgroup_free(&cgroup); + goto err; + } + } else { + cgc = cgroup_add_controller(cgroup, cgroup_list[i]->controllers[j]); - cgroup_free(&cgroup); - goto err; + if (!cgc) { + ret = ECGINVAL; + fprintf(stderr, "%s: ", argv[0]); + fprintf(stderr, "controller %s", + cgroup_list[i]->controllers[j]); + fprintf(stderr, "can't be add\n"); + cgroup_free(&cgroup); + goto err; + } } j++; } -- 2.47.2