]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
cgcreate: use "*" character as a meta character for all mounted controllers
authorIvana Hutarova Varekova <varekova@redhat.com>
Thu, 31 Jul 2014 09:40:00 +0000 (11:40 +0200)
committerIvana Hutarova Varekova <varekova@redhat.com>
Thu, 31 Jul 2014 09:40:00 +0000 (11:40 +0200)
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 <varekova@redhat.com>
Reviewed-by: Jan Chaloupka <jchaloup@redhat.com>
doc/man/cgcreate.1
src/tools/cgcreate.c

index 70680736fe9d21ee495297b77799d3fe9ab32e74..557b5aee09b8066fceda1d1fdf89c5d800ab5ca4 100644 (file)
@@ -38,7 +38,8 @@ others permissions to the owners permissions).
 .TP
 .B -g <controllers>:<path>
 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.
index 73abd91dd1ae9e0a002877b2ccc82e4de5cfeb9b..65b188a97c4417514f6f71d85ed3954f01b72b60 100644 (file)
@@ -54,7 +54,6 @@ static void usage(int status, const char *program_name)
        printf("  -t <tuid>:<tgid>              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++;
                }