Hi,

A new "--cancel-sticky" option of cgclassify command cancels the
unchanged processes. So cgrulesengd can change both the specified
processes and their children to right cgroup based on /etc/cgrules.conf
automatically.

Example:
 1. cgrulesengd changes processes to "unsticky" cgroup based on
  /etc/cgrules.conf.
  # cat /dev/cgroups/cpuset/unsticky/tasks
  23820
  23826
  23827
  #

 2. cgclassify changes the process 23827 to "sticky" cgroup
    with "--sticky" option.
  # cgclassify -g cpuset:sticky --sticky 23827
  # cat /dev/cgroups/cpuset/unsticky/tasks
  23820
  23826
  # cat /dev/cgroups/cpuset/sticky/tasks
  23827
  #

 3. The process 23941 is fork(2)ed from 23827, and cgrulesengd
    does not change 23941 due to "--sticky" option.
  # cat /dev/cgroups/cpuset/sticky/tasks
  23827
  23941
  #

 4.  cgclassify changes the process 23827 to unsticky process
    by "--cancel-sticky" option.
  # cgclassify -g cpuset:sticky --cancel-sticky 23827
  # cat /dev/cgroups/cpuset/sticky/tasks
  23827
  #

 5. The process 23962 is fork(2)ed from 23827, and cgrulesengd
    changes 23962.
  # cat /dev/cgroups/cpuset/sticky/tasks
  23827
  # cat /dev/cgroups/cpuset/unsticky/tasks
  23820
  23826
  23962
  #


Signed-off-by: Ken'ichi Ohmichi <[email protected]>
---
diff --git a/doc/man/cgclassify.1 b/doc/man/cgclassify.1
index c03003f..2d8921b 100644
--- a/doc/man/cgclassify.1
+++ b/doc/man/cgclassify.1
@@ -6,7 +6,7 @@
 cgclassify \- move running task(s) to given cgroups
 
 .SH SYNOPSIS
-\fBcgclassify\fR [\fB-g\fR <\fIcontrollers>:<path\fR>] [--sticky] 
<\fIpidlist\fR>
+\fBcgclassify\fR [\fB-g\fR <\fIcontrollers>:<path\fR>] [--sticky | 
--cancel-sticky] <\fIpidlist\fR>
 
 .SH DESCRIPTION
 this command moves processes defined by the list
@@ -41,6 +41,13 @@ children tasks. Without this option, the daemon does not 
change the
 specified \fBpidlist\fR but it changes their children tasks to the
 right cgroup based on \fB/etc/cgrules.conf\fR automatically.
 
+.TP
+.B --cancel-sticky
+If this option is used, the daemon of service cgred (cgrulesengd
+process) can change both the specified \fBpidlist\fR and their
+children tasks to right cgroup based on \fB/etc/cgrules.conf\fR
+automatically.
+
 .SH FILES
 .LP
 .PD .1v
diff --git a/src/tools/cgclassify.c b/src/tools/cgclassify.c
index a0d047b..3181105 100644
--- a/src/tools/cgclassify.c
+++ b/src/tools/cgclassify.c
@@ -93,6 +93,7 @@ out:
 
 static struct option longopts[] = {
        {"sticky", no_argument, NULL, 's'},
+       {"cancel-sticky", no_argument, NULL, 'u'},
        {0, 0, 0, 0}
 };
 
@@ -101,7 +102,7 @@ int main(int argc, char *argv[])
        int ret = 0, i, exit_code = 0;
        pid_t pid;
        int cg_specified = 0;
-       int flag_child = 0;
+       int flag = 0;
        struct cgroup_group_spec *cgroup_list[CG_HIER_MAX];
        int c;
 
@@ -109,7 +110,7 @@ int main(int argc, char *argv[])
        if (argc < 2) {
                fprintf(stderr, "usage is %s "
                        "[-g <list of controllers>:<relative path to cgroup>] "
-                       "[--sticky] <list of pids>  \n",
+                       "[--sticky | --cancel-sticky] <list of pids>  \n",
                        argv[0]);
                exit(2);
        }
@@ -128,7 +129,10 @@ int main(int argc, char *argv[])
                        cg_specified = 1;
                        break;
                case 's':
-                       flag_child |= CGROUP_DAEMON_UNCHANGE_CHILDREN;
+                       flag |= CGROUP_DAEMON_UNCHANGE_CHILDREN;
+                       break;
+               case 'u':
+                       flag |= CGROUP_DAEMON_CANCEL_UNCHANGE_PROCESS;
                        break;
                default:
                        fprintf(stderr, "Invalid command line option\n");
@@ -148,8 +152,8 @@ int main(int argc, char *argv[])
        for (i = optind; i < argc; i++) {
                pid = (uid_t) atoi(argv[i]);
 
-               if (flag_child)
-                       ret = cgroup_register_unchanged_process(pid, 
flag_child);
+               if (flag)
+                       ret = cgroup_register_unchanged_process(pid, flag);
                if (ret)
                        exit_code = 1;
 

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to