summaryrefslogtreecommitdiffstats
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* adds lscgroup toolIvana Hutarova Varekova2009-10-092-1/+298
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Description: create tool which shows cgroups which are on system: Usage: lscgroup [<controllers>:<path>] [...] list all cgroups Changes since V1(the previous versions was not enumerated): * fix the format of comments which have more than 1 line * printf of help -> fprintf(stdout,... * change the sequence of processing of cgroups on input (now first) and internal controller list(first in the previous version), now the cgroups are output in order in which they are put to input * fix return values/error messages - now if the controller is not mount the tool return error - it returns 0 otherwise Changes since V2 * fix problem with slash characters ( $ lscgroup cpu:/1/2 cpu:/1/2/ cpu:/1/2/1 $ lscgroup cpu:1/2 cpu:/2/ cpu:/2/1 ) Changes since V3 * rename the variables (dp1 -> cgroup_dir_path, dp2 -> input_dir_path) * improve the coding style Examples: $ lscgroup devices:/ devices:/sysdefault cpuset,cpuacct:/ cpuset,cpuacct:/sysdefault cpuset,cpuacct:/daemons cpuset,cpuacct:/daemons/ftp $ lscgroup cpuset:/ cpuset,cpuacct:/ cpuset,cpuacct:/sysdefault cpuset,cpuacct:/daemons cpuset,cpuacct:/daemons/ftp $ lscgroup cpuset:/daemons cpuset,cpuacct:/daemons/ cpuset,cpuacct:/daemons/ftp Signed-off-by: Ivana Hutarova Varekova <varekova@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Restrict the effective range of SIGUSR2 signal.Ken'ichi Ohmichi2009-10-041-30/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hi, If a cgrulesengd daemon receives a SIGUSR2 signal (for reloading rules configuration) while waiting in select(), a daemon finishes incorrectly due to an "Interrupted system call" error. If applying a patch "Add the strings of errno to cgrulesengd daemon's message." and running `service cgred reload`, you can see the message "selecting error: Interrupted system call". This patch fixes the problem. There were some problems the deadlock happens related to a SIGUSR2 signal and they have been fixed by the followings already: * [PATCH] Fix the deadlock of vsyslog() call. http://libcg.git.sourceforge.net/git/gitweb.cgi?p=libcg;a=commit;h=70111cd03653c3ceab9d907c14fa35e5881b2735 * [PATCH] Fix the deadlock of rl_lock. http://libcg.git.sourceforge.net/git/gitweb.cgi?p=libcg;a=commit;h=0241c6f1df5068c006f756005c8e7faa63058c27 The above two patches fixed the problems by protecting the important codes from receiving a SIGUSR2 signal. But this way was not good, because the protecting code will be necessary if increasing the important codes. Instead of protecting the important codes, this patch restricts the effective range of receiving SIGUSR2 signal. So we will not need to add a new protecting code by this patch. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Add the strings of errno to cgrulesengd daemon's message.Ken'ichi Ohmichi2009-10-041-11/+12
| | | | | | | | | | | | | | | | Hi, This patch adds the strings of errno to cgrulesengd daemon's message. For investigating a problem that cgrulesengd daemon finishes by `service cgred reload`, I added the strings of errno to the daemon's message. This strings were useful for investigating. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* adds lssubsys toolIvana Hutarova Varekova2009-08-292-1/+219
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Description: Show controller, which are mounted/which are on input and if option -m is used shows the mount point on which are mounted: Changes since V1(the previous versions was not enumerated): * fix the size of array cont_name - so no allocation and c_max variable removed * change the sequence of processing of controllers list on input (now first) and internal controller list(first in the previous version), now the controllers are output in order in which they are put to input * fix return values/error messages - now if the controller is not mount the tool return error - it returns 0 otherwise Changes since V2 * fix the format of comments which have more than 1 line Changes since V3 * printf of help -> fprintf(stdout, Syntax: lssubsys [-m] [controller1] [controller2] [...] -m - show mount points Examples: $lssubsys -m cpuacct cpuset,cpuacct /mnt/cgroups/cpuset $ lssubsys devices cpuset,cpuacct Signed-off-by: Ivana Hutarova Varekova <varekova@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Remove VERSION macro from api.cJan Safranek2009-08-291-11/+0
| | | | | | | | | The macro and assosicated cg_version is not used anywhere and it generates warning: api.c:58:1: warning: "VERSION" redefined Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Remove unnecessary includes from libcgroup.hJan Safranek2009-08-293-0/+3
| | | | | | | | libcgroup.h includes some header files, which are not then used. These should be removed, resp. moved to the source files where they are actually needed. Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Shorten error text of ECGOTHERJan Safranek2009-08-291-4/+1
| | | | | | | | | | | | | | | Let's reformat cgroup_strerror output from Cgroup generic error, error message: Device or resource busy to shorter and clearer Device or resource busy The patch assumes that _GNU_SOURCE is defined. Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* libcgroup: Fix compile errorDhaval Giani2009-08-061-1/+1
| | | | | | The correct error code is ECGOTHER and not CGOTHER Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* add api for generating the list of all controllers (not only mount ones)Ivana Hutarova Varekova2009-08-062-0/+79
| | | | | | | | | | | | | | | | | | | | | | this patch add api for generating the list of all controllers (not only mount ones) - it uses three functions: cgroup_get_all_controller_begin cgroup_get_all_controller_next cgroup_get_all_controller_end and structure: struct controller_data { char name[FILENAME_MAX]; int hierarchy; int num_cgroups; int enabled; }; the data are read from /proc/cgroups file Signed-off-by: Ivana Hutarova Varekova <varekova@redhat.com> Reviewed-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Refactor cgclear to use new recursive deleteJan Safranek2009-08-061-92/+14
| | | | | | | | | | | | Let's rework cgroup_config_unload_controller to use the brand new recursive removal of groups. It saves *lot of* fopen() and fclose() calls: On my (semi-broken) Fedora 11 with 196 running processes and 3 cgroup hierarchies, the old cgclear does 668 open("*/tasks"). With the optimized cgclear, I can see just 22 open("*/tasks") calls. Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Add cgdelete toolJan Safranek2009-08-062-1/+147
| | | | | | | | | | | | | | | | | The cgdelete command line tool removes given control groups. Usage: cgdelete [-r] <controllers>:<group> [...] # I have group 1 with many subgroups: $ cgdelete cpu,freezer:1 cgdelete: cannot remove group '1': Cgroup generic error, error message: Device or resource busy $ cgdelete -r cpu,freezer:1 $ Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Add recursive cgroup_delete_cgroup_ext.Jan Safranek2009-08-062-26/+125
| | | | | | | | | | | | | | | | | | | Changelog: - add braces to cgroup_delete_cgroup_ext to improve readability - use enum instead of macro to define flags The new function allows to recursively delete whole tree of groups. There is new infrastructure created around (cg_delete_cgroup_controller_recursive). It has inconsistent behavior when root group removal is requested - it removes all children (if requested), but does not remove the root itself and returns success value. This allows simple rewrite of cgclear functions to use this function. Original cgroup_delete_cgroup now leads to cgroup_delete_cgroup_ext. Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Split cgroup removal to separate functions.Jan Safranek2009-08-061-49/+154
| | | | | | | | | | | | | | | | | | | | | | | Changelog: - simplify error handling in cg_move_task_files cgroup_delete_cgroup does all the stuff on it's own. This patch refactors the function and moves the parts with complete error handling. The new functions are cg_delete_cgroup_controller and cg_move_task_files. They are not necessarily needed, but it simplifies error handling and clearly distinguishes functionality of cgroup_delete_cgroup. Purpose of the functions should be clearly specified in the doxygen comments. Especially note that cg_delete_cgroup_controller wants already opened file, where all tasks should be moved - this is optimization, which will be used in subsequent patches. I could use cgroup_get_task_* and cgroup_attach_task, which would look definitely nicer, but it would lead to lot of fopen() and fclose() calls. Let me know what do you think about it. Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* RFC: Fix cgroup_find_parent functionJan Safranek2009-08-061-31/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | There are more issues with cgroup_find_parent function: 1. The cgroup_find_parent expects, that it's argument is group in cg_mount_table[0] controller, which is not always the case. IMHO the function should accept complete struct cgroup and find real parent. 2. when checking the st_dev of the group and it's parent to prevent "underflow" to real filesystem, actually the parent and it's parent are checked instead of group and it's parent. In addition, I enhanced the function to return real error code when something goes wrong. Open question is, if the function should return just char* as parent's name or whole struct cgroup*. The second case is more natural - we should work with groups and not group names, but in some cases just the name is needed and whole cgroup creation would be unnecessary overhead (I have prepared cgcdelete tool, which needs just parent's name). Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* removes copy_name_value_from_rules to wrapperIvana Varekova2009-08-064-56/+64
| | | | | | | | | move copy_name_value_from_rules procedure to wrapper.c file and add the header to libcgroup-internal.h Signed-off-by: Ivana Varekova <varekova@redhat.com> Acked-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Add a process name to the log of cgrulesengd daemon.Ken'ichi Ohmichi2009-07-071-5/+6
| | | | | | | | | | | | | | | Hi, Current cgrulesengd daemon changes the cgroup of each process by a rule based on uid, gid, and process name. And it is good that the log of the daemon contains a process name with uid and gid. This patch adds a process name to the log message. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Reduce "Cgroup change for PID:X, UID:X, GID:X FAILED!" messages.Ken'ichi Ohmichi2009-07-071-5/+4
| | | | | | | | | | | | | | | | | | | | | | | | Hi, Changelog since v1: =================== * Rebase the latest code. * Cleanup. The log message "Cgroup change for PID:X, UID:X, GID:X FAILED!" is output by cgrulesengd daemon, even if a process finished already and that is not a problem. This patch prevents the daemon from outputting this spam log message. * Reference [PATCH 2/2] Reduce "Cgroup change for PID:X, UID:X, GID:X FAILED!" messages. http://sourceforge.net/mailarchive/message.php?msg_name=4A10EE7E.60403%40mxs.nes.nec.co.jp Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Cleanup: find better name for CGRULE_CGRED_TEMP_FILEJan Safranek2009-07-012-5/+5
| | | | | | | | Rename CGRULE_CGRED_TEMP_FILE to CGRULE_CGRED_SOCKET_PATH to better describe the macro usage - it's not a temporary file, it's a socket. Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Fix cgroup_find_matching_rule() call.Ken'ichi Ohmichi2009-06-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Hi, If compiling the latest code (8cc1d9743201cb9ae9a5286c898b9d47e318ed46), the following warning messages are printed. The problem is due to invalid call of cgroup_find_matching_rule_uid_gid(). Instead of this function call, cgroup_find_matching_rule() should be called as "[PATCH-v6 03/11] Add the key "process name" to find a matching rule.". $ make [snip] api.c: In function 'cgroup_change_cgroup_flags': api.c:1994: warning: passing argument 3 of 'cgroup_find_matching_rule_uid_gid' from incompatible pointer type api.c: At top level: api.c:1923: warning: 'cgroup_find_matching_rule' defined but not used [snip] $ * Reference: "[PATCH-v6 03/11] Add the key "process name" to find a matching rule." http://sourceforge.net/mailarchive/message.php?msg_name=4A44617E.9060002%40mxs.nes.nec.co.jp Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Fix too many program name in the usage message of "cgset" command.Ken'ichi Ohmichi2009-06-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | Hi, If compiling the latest code (8cc1d9743201cb9ae9a5286c898b9d47e318ed46), the following warning messages are printed. $ make [snip] cgset.c: In function 'usage': cgset.c:123: warning: too many arguments for format [snip] $ This patch fixes too many program name in the usage message of "cgset" command. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* cgset: Add --copy-from option to cgsetIvana Varekova2009-06-291-5/+69
| | | | | | | Add copy-from option to cgset Signed-off-by: Ivana Varekova <varekova@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* cgset: Change the handling of options, add --helpIvana Varekova2009-06-291-6/+35
| | | | | | | | | | Change the handling of options - add the possibility to use long options - add --help option - change the type of c (see man 3 getopt_long) Signed-off-by: Ivana Varekova <varekova@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* cgset: Change the generation of cgroupIvana Varekova2009-06-291-43/+74
| | | | | | | | | | | | | | | - This patch change the system of generating cgroup to 1/ create one src cgroup 2/ for each input cgroup name cgroup_copy_cgroup the name-value data from original one This method is better because the name-values pairs should not be parsed several times. And this method will be used in new coption --copy-from too (the src group will be find in option) move the part in which src is generated to separate function Signed-off-by: Ivana Varekova <varekova@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* cgset: Add cgset_SOURCES to MakefileIvana Varekova2009-06-291-0/+2
| | | | | | | Add cgset_SOURCES to Makefile Signed-off-by: Ivana Varekova <varekova@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Cleanup: Clarify the number meanings of string length.Ken'ichi Ohmichi2009-06-291-4/+4
| | | | | | | | | | | | | | | | Hi, This patch clarifies the number meanings of string length in the function cgroup_get_uid_gid_from_procfs(). This is recreated based on Igawa-san's patch for the latest code. * Reference Igawa-san's patch http://sourceforge.net/mailarchive/message.php?msg_name=20090515.085922.109268324.igawa%40mxs.nes.nec.co.jp Signed-off-by: Masayuki Igawa <igawa@mxs.nes.nec.co.jp> Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Apply a new rule to 'cgclassify' command.Ken'ichi Ohmichi2009-06-291-13/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hi, Changelog of v6: ================ * Change the cgroup_get_procname_from_procfs() calling for the returning value's change. Changelog of v5: ================ * Add the description of a new option "--sticky". Changelog of v4: ================ * Add a new option "--sticky" so that cgrulesengd daemon does not change the children's cgroups which is classified by 'cgclassify' command. Changelog of v3: ================ * New patch. Description: ============ This patch applies a new rule to 'cgclassify' command. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Apply a new rule to 'cgexec' command.Ken'ichi Ohmichi2009-06-292-8/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hi, Changelog of v6: ================ * No change. Changelog of v5: ================ * Add the description of a new option "--sticky". Changelog of v4: ================ * Add a new option "--sticky" so that cgrulesengd daemon does not change the children's cgroups which is executed by 'cgexec' command. Changelog of v3: ================ * Set a SETUID to "cgexec" command file. * An euid is changed to the executing user from a root user. Changelog of v2: ================ * New patch. Description: ============ This patch applies a new rule to 'cgexec' command. cgroup_register_unchanged_process() is called so that cgrulesengd daemon does not change the cgroup of a process, which is executed by 'cgexec' command. And cgroup_change_cgroup_flags() is called for applying a new rule. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Add the library function cgroup_register_unchanged_process().Ken'ichi Ohmichi2009-06-292-0/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hi, Changelog of v6: ================ * No change. Changelog of v5: ================ * Rebase the patch to the latest code. Changelog of v4: ================ * No change. Changelog of v3: ================ * No change. Changelog of v2: ================ * New patch. Description: ============ This patch adds the library function cgroup_register_unchanged_process() for notifying cgrulesengd daemon of the unchanged process. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Add the handler of unchanged process to cgrulesengd daemon.Ken'ichi Ohmichi2009-06-291-5/+198
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hi, Changelog of v6: ================ * No change. Changelog of v5: ================ * No change. Changelog of v4: ================ * Add the comment "FIXME: Change the temporary file to configurable one." * Define the number of allocation. Changelog of v3: ================ * Set the value 0x1 to CGROUP_DAEMON_UNCHANGE_CHILDREN flag. Changelog of v2: ================ * New patch. Description: ============ This patch adds the handler of unchanged process to the cgrulesengd daemon. By this patch, the daemon does not change a process which is executed by 'cgexec' command, because it is possible to notify the unchanged process to the daemon by using "unix domain socket". Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Cleanup: Separate the netlink method to cgre_receive_netlink_msg().Ken'ichi Ohmichi2009-06-291-37/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hi, Changelog of v6: ================ * No change. Changelog of v5: ================ * No change. Changelog of v4: ================ * Remove unused parameter "cn_hdr" from cgre_receive_netlink_msg(). Changelog of v3: ================ * No change. Changelog of v2: ================ * New patch. Description: ============ This patch separates the netlink method for the readability, because the later patch [PATCH 6/9] adds "unix domain socket" handling method around the netlink method. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Add a exec event to the event handler of cgrulesengd daemon.Ken'ichi Ohmichi2009-06-291-9/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hi, Changelog of v6: ================ * Change the cgroup_get_procname_from_procfs() calling for the returning value's change. Changelog of v5: ================ * No change. Changelog of v4: ================ * No change. Changelog of v3: ================ * No change. Changelog of v2: ================ * No change. Description: ============ A process name is changed when execve(2), so a new rule based on process name should be applied when execve(2) happens. Then this patch adds an EXEC event to the event handler. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Add the key "process name" to find a matching rule.Ken'ichi Ohmichi2009-06-292-59/+96
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hi, Changelog of v6: ================ * No change. Changelog of v5.1: ================== * BUGFIX: Clear the flags meaning "found a matching rule" when a process name does not match. There was a problem that cgexec and cgclassify didn't work correctly if a user executes cgexec/cgclassify based on /etc/cgrules.conf. For example, if a root user executes `cgclassify $$` on the following /etc/cgrules.conf, the process ($$) should be moved to users/root on cpuset and memory subsystems. But the process was moved to users/root/cp on memory subsystem only. Example of /etc/cgrules.conf: ============================= root:cp cpuset users/root/cp % memory users/root/cp root cpuset users/root % memory users/root The cause is why the flags meaning "found a matching rule" (uid, gid, and matched) is not cleared when a process name does not match. This problem is fixed on this patch. Changelog of v5: ================ * Rebase the patch to the latest code. Changelog of v4: ================ * No change. Changelog of v3: ================ * BUGFIX: Fix the handling of '%' in /etc/cgrules.conf. Changelog of v2: ================ * Use strcmp() instead of strncmp() for checking a process name strictly. * Some cleanups. Description: ============ This patch adds the key "process name" to find a matching rule. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Add the parser of process name in /etc/cgrules.conf.Ken'ichi Ohmichi2009-06-293-7/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hi, Changelog of v6: ================ * The definations of CGROUP_RULE_MAXKEY and CGROUP_RULE_MAXLINE are moved to libcgroup-internal.h since no one from outside should be using them. Changelog of v5: ================ * Rebase the patch to the latest code. Changelog of v4: ================ * Use more safety length of a user name for the buffer "username". * Move the macros min()/max() to src/libcgroup-internal.h for using in src/api.c also. Changelog of v3: ================ * Fix unclear buffer of user by memset(). Changelog of v2: ================ * Remove unnecessary memset(). * Some cleanups. Description: ============ This patch adds the parser of process name in /etc/cgrules.conf. A new rule based on process name is as the following, and the process name is stored into the member "procname" in struct cgroup_rule. <user>:<process name> <controllers> <destination> Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Add cgroup_get_procname_from_procfs() for getting a process name.Ken'ichi Ohmichi2009-06-293-0/+190
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hi, Changelog of v6: ================ * Change the returning values of *_get_procname_from_proc*() to integer from charactor pointer. * Clarify the number meaning of string length in cg_get_procname_from_ ~proc_status() Changelog of v5: ================ * Rebase the patch to the latest code. Changelog of v4: ================ * Add the error handling for strdup()'s error. * Reduce strlen() calls. * Make the check code of a process name simple. Changelog of v3: ================ * Move cgroup_get_procname_from_procfs() to libcgroup-internal.h. * Fix unclear buffer of buf_cwd by memset(). * Get a real path of script file by realpath(). Changelog of v2: ================ * It is possible to handle a process, which name length is over than 16 characters, also. Description: ============ This patch adds a new function cgroup_get_procname_from_procfs() for getting a process name. This function allocates the memory for a process name, and writes the name to the memory, and returns the pointer of the memory. So a caller should free the memory if unusing it. The process name, which is wrotten by this function, depends on the specified process: If a command process) the full path of command. If a shell script process) the full path of shell script. If a kernel thread) the process name of kernel thread. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* libcgroup: Introduce an API to get the mount point of a specific subsystemDhaval Giani2009-06-262-0/+29
| | | | | | | | | Introduce an API which will query the mount table and return the mount point of a specific subsystem. This is needed in the case when the user knows which subsystem he wants the details of, which would make the use of the get_controller* APIs cumbersome. Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Fix some warnings.Ken'ichi Ohmichi2009-06-251-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | Hi, The latest source (commit: 5ea9a7819b717a83af03aa2ea234f105ed717589) outputs some following warnings: $ make [snip] api.c: In function 'cgroup_walk_tree_begin': api.c:2350: warning: passing argument 3 of 'cg_walk_node' makes integer from pointer without a cast api.c:2315: warning: unused variable 'fts' [snip] $ This patch fixes them. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* libcgroup: Fix a missing goto in clean cgroups APIDhaval Giani2009-06-221-0/+1
| | | | | | | Jan pointed out that there was a goto missing in the error handling paths. Fix that bug. Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* libcgroup: Introduce a unload cgroups APIDhaval Giani2009-06-224-1/+215
| | | | | | | | | | | | | | | | | | | | | | | | | | This API will unload the cgroups created in the cgroupfs and unmount and delete the filesystem mount point. The action is equivalent to what is done currently in service cgconfig stop. The reason for this API is to make sure we don't end up with a asymmetric library API subset. Today an application program can programatically through cgroup_config_load_config() load a configuration file, but has no means to cleanup (including all temporarily created groups). changes from v3 1. Address Jan's comments from http://article.gmane.org/gmane.comp.lib.libcg.devel/1105 changes from v2 1. Fix a leak as noted by Bharata 2. Address Balbir's review comments at http://article.gmane.org/gmane.comp.lib.libcg.devel/1080 changes from v1 1. Change the name of the function to cgroup_unload_cgroups 2. Change the name of the executatble to cgclear 3. Split out the funtions Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com>
* libcgroup: Introduce get_controller APIDhaval Giani2009-06-182-0/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | This set of APIs will allow the caller to query the mount table and find out what controller is mounted at what path. Test program has been included in the patch. Running the test program results in [dhaval@gondor tests]$ ../libtool --mode=execute ./get_controller Controller cpu is mounted at /cgroup Controller cpuacct is mounted at /cgroup Controller memory is mounted at /cgroup1 [dhaval@gondor tests]$ Which is the setup on this system. Changes from v2 1. Remove the incorrect comments as pointed out by Bharata Changes from v1 1. Use a new structure as mentioned by bharata to return the values. Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> Cc: Jan Safranek <jsafrane@redhat.com> Acked-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
* libcgroup: Use double pointers everywhere in the get_task APIsDhaval Giani2009-06-181-3/+3
| | | | | | | | As Jan Safranek pointed out, it is better to have double pointers everywhere in the get_task API to keep consistency. Do the same. Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com>
* libcgroup: Introduce post order walkDhaval Giani2009-06-182-4/+14
| | | | | | | | | | With the introduction of the flags, we now actually make use of them. This patch adds a post mode and modifies the test case to also do a post order walk. Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com> Acked-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
* libcgroup: Add flags to the walk_tree handleDhaval Giani2009-06-182-10/+59
| | | | | | | | | | | | | | Introduce a cgroup_tree_handle structure so that we can track flags for the walk_tree operation. In a number of cases we would prefer to walk the tree in postorder as opposed to pre-order which is the current default. This patch does the addition. Changes since V1: 1. Added checks for !handle as suggested by Bharata Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com> Acked-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
* cgconfigparser: Change mkdir in cgroup_config_mount_fs to mkdir -pDhaval Giani2009-06-183-7/+5
| | | | | | | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=502687 mentioned that the directory was not getting created when a cgconfig start was being run. This is was because we failed the mkdir. The mkdir for directories at depth was not succeeding. Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com>
* This patch adds cgset toolIvana Varekova2009-06-182-1/+179
| | | | | | | | | | | | | | | | | | | | | | | | | This patch adds cgset tool, which sets parameters of controllers for given cgroup based on input name-variable pairs - the syntax is: cgset -r <name=value> <relative path to cgroup> ------------------------------------------------- EXAMPLES: $ cgcreate -g cpuset:test1 $ cgset -r cpuset.cpus=1 test $ cat ./test/cpuset.cpus 1 $ cgcreate -g cpuset:test1 -g cpuset:test2 $ cgset -r cpuset.cpus=0 test1 test2 $ cat /mnt/cgroups/cpuset/test1/cpuset.cpus 0 $ cat /mnt/cgroups/cpuset/test2/cpuset.cpus 0 Signed-off-by: Ivana Varekova <varekova@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Prevent to add multiple versions of the same controller to mount_tableIvana Varekova2009-06-181-0/+18
| | | | | | | | | | | | This patche add a test to cgroup_init function, which prevent to add multiple records for the same controller (this is a problem eg. in cgroup_get_cgroup function - which looks to mount table and add all relevant controllers using cgroup_add_controller function and when the function calls cgroup_add_cgroup function twice on the same controller, it returns error so the result is cgroup_get_cgroup failed). Signed-off-by: Ivana Varekova <varekova@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Cleanup: Integrate similar code to cgroup_get_uid_gid_from_procfs().Ken'ichi Ohmichi2009-06-086-140/+68
| | | | | | | | | | | | | | CHANGELOG of v2.1: ================ * Rebase the patch for commit '340feae163c4797a6cb1247b3812c1ccdc52fa41'. There are some similar functions for getting process's data (uid, gid) from /proc/<pid>/status file, so this patch integrates these functions into one cgroup_get_uid_gid_from_procfs(). Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Reviewed-By: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Cleanup: Remove unnecessary 'err' value.Ken'ichi Ohmichi2009-06-081-3/+1
| | | | | | | | | | | | | | | Hi, CHANGELOG of v2: ================ * New patch. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Reviewed-By: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Cleanup: Rename "name" to "username" in struct cgroup_rule.Ken'ichi Ohmichi2009-06-082-9/+10
| | | | | | | | | | | | | | | | | | Hi, CHANGELOG of v2: ================ * No change. To add the member "procname" to struct cgroup_rule by later patch, this patch renames the member "name" to "username" for the clarification. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Reviewed-By: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Cleanup: Add cg_skip_unused_charactors_in_rule().Ken'ichi Ohmichi2009-06-081-16/+29
| | | | | | | | | | | | | | | | | | | Hi, CHANGELOG of v2: ================ * No change. The loop in cgroup_parse_rules() is a little long now, and it is not easy to read the loop. Then, This patch shortens the loop for the readability. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Reviewed-By: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Cleanup: Use sizeof() in memset().Ken'ichi Ohmichi2009-06-081-23/+5
| | | | | | | | | | | | | Changelog of v3: ================ * Remove unnecessary memset(). fgets()/sscanf() does not care what is in the buffer, and it is unnecessary to clear the buffer before. Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Reviewed-By: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>