tools: cgconfig/cgrulesengd - skip parsing non .conf files
Currently, the list of files to be parsed is constructed by reading the
directories passed with '-L' command line option or by cgrulesend from
'/etc/cgconfig.d'. The directories might also host non-configuration
files, parsing them will result in failure.
Consider the following example:
# ls /etc/cgconfig.d
cgconfig-oradb.conf cgconfig-oradb.conf.rpmsave test .conf e
# /usr/sbin/cgconfigparser -l /etc/cgconfig.conf -L /etc/cgconfig.d -s 1664
/usr/sbin/cgconfigparser; error loading /etc/cgconfig.d/cgconfig-oradb.conf.rpmsave:
Cgroup, the requested group parameter does not exist
fix it by skipping files with non .conf extensions, while building the
list of files to be parsed for cgroup configurations.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
api: cg_move_task_files() - rearrange code to avoid extra check
Fix unused variables, reported by the Coverity tool:
CID 320878 (#1 of 1): Unused value (UNUSED_VALUE)assigned_value:
Assigning value 0 to ret here, but that stored value is overwritten
before it can be used.
Currently, in cg_move_task_files(), the ret is checked for ESRCH and set
to zero, if true, and for other error values it executes the error path
but immediately the ret is over-written without reading the set zero,
re-arrange the code to such that only the error path is executed and ret
is not set to zero.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Fix few cython-lints non-Python constructs, reported by cython-lint
tool:
- libcgroup.pyx:222:26: E711 comparison to None should be 'if cond is None:'
- libcgroup.pyx:380:82: E703 statement ends with a semicolon
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Add configuration for cython-lint, to ignore errors such as:
- Allowed length of line to be 100
- Ignore error code 'E128' continuation line under-indented for visual
indent
Cython-lint is available https://github.com/MarcoGorelli/cython-lint,
expects the file name to be pyproject.toml
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
CID 320876 (#1 of 1): Unused value (UNUSED_VALUE)assigned_value:
Assigning value 0 to ret here, but that stored value is overwritten
before it can be used.
If the mapping from v1->v2 and vice versa fail, with -i
(ignore-unmappable) set, ret is set to zero and is immediately
over-written, re-arrange the check, and adjust the commentary to avoid
clobbering ret, by taking the error path when -i is unset or else
continuing when set, skipping to set ret to zero.
Suggested-by: Tom Hromatka <tom.hromatka@oracle.com> Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
CID 320879 (#1 of 1): Unused value (UNUSED_VALUE)assigned_value:
Assigning value 0 to ret here, but that stored value is overwritten
before it can be used.
If the mapping from v1->v2 and vice versa fail, with -i
(ignore-unmappable) set, ret is set to zero and is immediately
over-written, re-arrange the check, and adjust the commentary to avoid
clobbering ret, by taking the error path when -i is unset or else
continuing when set, skipping to set ret to zero.
Suggested-by: Tom Hromatka <tom.hromatka@oracle.com> Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
api: fix missing goto in cgroup_get_current_controller_path()
Fix missing goto on error in cgroup_get_current_controller_path(), it
was reported by Coverity tool as unused value:
CID 320875 (#1 of 1): Unused value (UNUSED_VALUE)assigned_value:
Assigning value ECGOTHER to ret here, but that stored value is
overwritten before it can be used.
It turns out that, it is more than an over-written value, the strdup()
was missing goto error path statement on failure, add it.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Mon, 3 Jul 2023 19:07:41 +0000 (13:07 -0600)]
cgsnapshot: Fix possible non-null-terminated array
Coverity flagged a code path where the controllers[][] structure in
parse_controllers() may not have a '\0' string as its last entry.
This would break the logic in is_ctlr_on_list().
The function may iterate past the end of the buffer looking for
a null terminator.
In parse_controllers: A character buffer that has not been null
terminated is passed to a function expecting a null terminated
string (CWE-170)
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Mon, 3 Jul 2023 15:58:13 +0000 (09:58 -0600)]
ftests: skip test 002 on legacy, containerized test runs
Skip test 002-cgdelete-recursive_delete.py on legacy (cgroup v1),
containerized test runs. It occasionally fails in Github Actions, and
I think the failure is simply because the machine is underpowered. In
these cases, the failure is usually reported as:
002-cgdelete-recursive_delete.py - Failed to get the pid of the child process:
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Mon, 3 Jul 2023 15:51:58 +0000 (09:51 -0600)]
ftests: Retry run() command after websocket failure
LXC/LXD will sometimes throw an "Error: websocket: bad handshake" error
on underpowered machines. Wait a bit (arbitrarily chosen 5 seconds) and
retry the command.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
tools/cgclassify: fix controller overflow array range
Fix out-of-bounds write issue, reported by Coverity tool:
CID 321270 (#1 of 1): Out-of-bounds write (OVERRUN)47. overrun-local:
Overrunning array info of 16 4128-byte elements at element index 16
(byte offset 70175) using index i (which evaluates to 16).
MAX_MNT_ELEMENTS is an array that's allocated for array parsing and
populating the mount points, as per Linux Kernel, this can't be above
16 and it works fine while checking for index < MAX_MNT_ELEMENTS, but
in this case, we rely on the mount point name to be empty ('\0'), since
allowed maximum mount points are 16, increase the allocation index to
17 for the info structure, to accommodate 16 controllers, but that is
unlikely.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 24 May 2023 13:34:51 +0000 (07:34 -0600)]
ftests: Rework test 071 to use cgroup_write_systemd_default_cgroup()
cgroup_write_systemd_default_cgroup() populates libcgroup's /var/run
file with the default slice/scope. No verification is done at the time
of writing.
cgroup_set_default_systemd_cgroup() reads the /var/run file and verifies
that it points to a valid path. If so, it populates libcgroup's global
variable, systemd_default_cgroup. systemd_default_cgroup is then used
in any subsequent building of libcgroup paths.
Previously, test 071 tested cgroup_set_default_systemd_cgroup() but it
didn't exercise cgroup_write_systemd_default_cgroup(). Rework test 071
to exercise the most likely combinations of writing/setting the default
path that a user would encounter.
-----------------------------------------------------------------
Test Results:
Run Date: May 24 07:32:54
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
-----------------------------------------------------
setup 0.00
071-sudo-set_default_systemd_cgroup.py 4.67
teardown 0.00
-----------------------------------------------------
Total Run Time 4.67
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Fri, 19 May 2023 22:09:54 +0000 (16:09 -0600)]
python: Add support for NULL controllers[] in get_processes()
Add support for an empty controllers list in the Python bindings.
The python method, get_processes(), will then send in a NULL pointer
in the controllers field into the C function cgroup_get_procs().
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Wed, 24 May 2023 20:12:45 +0000 (14:12 -0600)]
python: Add cgroup v1 support to move_process()
Add support for providing a single controller to Cgroup.move_process().
move_process() invokes cgroup_change_cgroup_path() which utilizes an
array of controller strings.
This change only adds support for a single controller via the python
bindings, but a list of controllers could be supported in the future.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Thu, 25 May 2023 02:35:35 +0000 (20:35 -0600)]
python: Add method to clear the default slice/scope
Add a convenience method to clear the default slice/scope. This may be
useful in cases where the user is done with the slice/scope and wants to
resume operating at the root cgroup level.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Fri, 19 May 2023 22:05:25 +0000 (16:05 -0600)]
python: Add bindings for cgroup_write_systemd_default_cgroup()
Add python bindings for cgroup_write_systemd_default_cgroup(). As part
of this change, demote cgroup_set_default_systemd_cgroup() to an
internal function - __set_default_systemd_cgroup(). I would expect
users to invoke write_default_systemd_scope() and utilize that to set
the default slice/scope.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Kamalesh Babulal [Fri, 23 Jun 2023 09:40:00 +0000 (15:10 +0530)]
api: fix build warning
Fix a build warning:
cgcreate.c: In function ‘create_systemd_scope’:
cgcreate.c:81:17: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-truncation]
81 | strncpy(slice, cg->name, len);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cgcreate.c:80:23: note: length computed here
80 | len = strlen(cg->name) - strlen(scope);
fix it by using, length of destination in the strncpy().
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Fri, 23 Jun 2023 06:19:04 +0000 (11:49 +0530)]
api: add ret value check in cgroup_get_current_controller_path()
Fix unchecked return value, reported by the Coverity tool:
CID 320874 (#1 of 1): Unchecked return value from library
(CHECKED_RETURN)13. check_return: Calling fscanf(pid_cgroup_fd,
"%*[^\n]\n") without checking return value. This library function may
fail and return an error code.
add the missing return value check from fscanf() in
cgroup_get_current_controller_path()
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Wed, 21 Jun 2023 04:16:20 +0000 (09:46 +0530)]
cgcreate: fix null pointer dereference in create_systemd_scope()
Fix a NULL pointer dereference, reported by the Coverity tool:
CID 321267 (#1 of 1): Dereference null return value (NULL_RETURNS)6.
dereference: Dereferencing a pointer that might be NULL scope when
calling strlen.
check for the return value from strstr(), before dereferencing it.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Sun, 18 Jun 2023 07:10:33 +0000 (12:40 +0530)]
tools/cgexec: fix memory leak in find_scope_pid()
Fix a memory leak, reported by the Coverity tool.
CID 321265 (#1-2 of 2): Resource leak (RESOURCE_LEAK)37. leaked_storage:
Variable pids going out of scope leaks the storage it points to.
find_scope_pid (), calls cgroup_get_procs() to get the pids of the
tasks under cgroup name, and it's up to the caller to free the allocated
pids. Fix it by calling free(pids) after every call to
cgroup_get_procs().
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 15 Jun 2023 11:22:06 +0000 (16:52 +0530)]
ftests: add test to replace scope idle_thread using cgclassify
Add a test to replace systemd scope default idle_thread using
cgclassify '-r' flag.
-----------------------------------------------------------------
Test Results:
Run Date: Jun 15 11:20:25
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------
setup 0.00
088-sudo-cgclassify_systemd_scope.py 17.63
teardown 0.00
---------------------------------------------------
Total Run Time 17.63
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
ftests: add support to replace idle_thread of systemd scope
Allow replacing the default idle_thread during process classification
into a cgroup using cgclassify by introducing replace_id flag, that
when unset(default) has no effect on the process created into systemd
scope cgroup, when set replaces the default idle_thread with the
process being created.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Tue, 20 Jun 2023 11:44:25 +0000 (17:14 +0530)]
tools/cgclassify: add -r option for systemd scope
Provide an option for users to replace the default idle_thread created
for systemd scope. With '-r' option specified, the first pid passed as
the argument to cgclassify will replace the default idle_thread, if it
exists. Also, if it's the only task, killing it will remove the .scope
cgroup it's running in.
For non scope cgroups, it launches the task program. The algorithm in
brief is as follows:
Once the first pid of argument list migrated to the expected cgroup(s):
1. The controller, cgroups details of the pid is captured before the
migration, so incase an error occurs, it easy to roll back to the
original cgroups the pid belonged to.
2. Once the migrated is done, parse /proc/<pid>/cgroup of the first
pid and if the cgroup name ends with .scope and has a task with
/proc/<pid>/cmdline as "libcgroup_systemd_idle_thread", kill
the task. This gives the illusion of replacement.
3. If an error occurs, migrate the pid back to the original cgroups.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
ftests: add test to replace scope idle_thread using cgexec
Add a test to replace systemd scope default idle_thread using cgexec
'-r' flag.
-----------------------------------------------------------------
Test Results:
Run Date: Jun 01 07:02:45
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
-----------------------------------------------
setup 0.00
085-sudo-cgexec_systemd_scope.py 9.19
teardown 0.00
-----------------------------------------------
Total Run Time 9.19
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Wed, 24 May 2023 11:39:15 +0000 (11:39 +0000)]
ftests: add support to replace idle_thread of systemd scope
Allow replacing the default idle_thread during process creation into a
cgroup using cgexec by introducing replace_id flag, that when unset
(default) has no effect on the process created into systemd scope
cgroup, when set replaces the default idle_thread with the process
being created.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 15 Jun 2023 10:36:54 +0000 (16:06 +0530)]
tools/cgexec: add -r option for systemd scope
Provide an option for users to replace the default idle_thread created
for systemd scope. With '-r' option specified, the program passed as
the argument to cgexec will replace the default idle_thread, if it
exists. Also, if it's the only task, killing it will remove the .scope
cgroup it's running in.
For non scope cgroups, it launches the task program. The algorithm in
brief is as follows:
Once the current task, instance of cgexec is migrated to the
expected cgroup(s):
1. fork() and in the child path perform the exec to program passed in
the command line. This means, we have cgexec instance and program
executing in the desired cgroup(s).
2. In the parent, parse /proc/<pid>/cgroup of the current process
(cgexec) and if the cgroup name ends with .scope and has a task
with /proc/<pid>/cmdline as "libcgroup_systemd_idle_thread", kill
the task. This gives the illusion of replacement.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Tue, 13 Jun 2023 04:29:21 +0000 (09:59 +0530)]
ftests-999: fix random dir name generation logic
The current logic of creating a random directory under the /tmp/
the directory is incorrect because the random directory is generated
under '/tmp/999stress', making it a common parent directory and
attempting to create/delete it will fail the test instance, that
overlaps. Fix this by generating '/tmp/<random-999stress>' making
unique per run.
-----------------------------------------------------------------
Test Results:
Run Date: Jun 12 11:39:41
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
----------------------------------------
setup 0.00
999-stress-cgroup_init.py 1.55
teardown 0.00
----------------------------------------
Total Run Time 1.55
Fixes: b81915a1fbe7 ("tests-999: add a random directory to mount path") Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 17 May 2023 20:52:01 +0000 (14:52 -0600)]
ftests: Add a test for cgroup_change_cgroup_path()
Add a functional test that exercises cgroup_change_cgroup_path()
via the python bindings.
-----------------------------------------------------------------
Test Results:
Run Date: May 17 21:20:19
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
-----------------------------------------
setup 0.00
087-sudo-move_pid.py 2.06
teardown 0.00
-----------------------------------------
Total Run Time
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Wed, 17 May 2023 20:46:58 +0000 (14:46 -0600)]
api: Support NULL controllers[] in cgroup_change_cgroup_path()
cgroup_change_cgroup_path() allows the user to move a pid to a
different cgroup (via the cgroup name and not a cgroup struct).
In cgroup v1, it's imperative that the controller(s) are
provided, so that the proper path can be built up. In cgroup v2,
the list of controllers is optional, since they are not a part
of the path.
Add support for the controllers[] list to be NULL iff we are
running in unified (cgroup v2) mode.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Thu, 18 May 2023 13:14:55 +0000 (07:14 -0600)]
config: systemd: Add a return code to cgroup_set_default_systemd_cgroup()
Add a return code to cgroup_set_default_systemd_cgroup(). This is
critical for users of the libcgroup C API, as they need to be certain
that a default slice/scope is set. If they mistakenly think one is
set when it is not, then they could erroneously operate on the root
cgroup.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Kamalesh Babulal [Mon, 22 May 2023 11:27:54 +0000 (11:27 +0000)]
tests-999: add a random directory to mount path
Currently, the mount path is static/hard coded and sometimes there might
be corners cases where the mount path directories are not deleted
completely, or there might be two instances of CI running at the same
time. Let's introduce an additional directory to the mount path, that's
generated randomly, so that every run is unique and doesn't interfere
with each other.
-----------------------------------------------------------------
Test Results:
Run Date: May 22 11:27:45
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
----------------------------------------
setup 0.00
999-stress-cgroup_init.py 1.36
teardown 0.00
----------------------------------------
Total Run Time 1.36
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Thu, 11 May 2023 22:56:13 +0000 (16:56 -0600)]
ftests: Add a test for samples/cmdline/systemd-with-idle-process.md
Add a test that performs the steps outlined in the sample command
line document systemd-with-idle-process.md.
-----------------------------------------------------------------
Test Results:
Run Date: May 11 16:55:43
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
--------------------------------------------------
setup 0.00
086-sudo-systemd_cmdline_example.py 6.19
teardown 0.00
--------------------------------------------------
Total Run Time 6.19
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Thu, 11 May 2023 19:53:18 +0000 (13:53 -0600)]
api: Delete the cgroup if cgroup_create_cgroup() fails
cgroup_create_cgroup() loops through the controllers in struct cgroup
and creates the requested cgroups. Some controllers could succeed
before a controller fails. This results in a case where the cgroup
directory has been created and remains in /sys/fs/cgroup even after a
failure.
Invoke cgroup_delete_cgroup() after we fail to create a cgroup under a
controller. This will delete the cgroup directory if it had been
created and put the system (nearly) back to its original state. (It's
possible that the parent cgroup's subtree_control file was modified and
not restored, but that's best fixed in another patch.)
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
api: cgroup_get_current_controller_path: fix a segfault
cgroup_get_current_controller_path(pid, controller, current_path), the
third argument isn't currently validated and will cause segfault if the
user passes NULL, in place of expect char **. Introduce a check to
validate current_path argument too.
Tom Hromatka [Thu, 27 Apr 2023 13:02:40 +0000 (13:02 +0000)]
man: cgcreate: document -p option
Add documentation about the -p option. It helps users to specify the
task they want to use in place of the default idle process created by
libcgroup, during systemd scope.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
ftests: add test to pass pid to systemd scope create via cgcreate
Add a test to pass task pid to systemd scope during creation using the
cgcreate tool.
-----------------------------------------------------------------
Test Results:
Run Date: Apr 27 12:54:10
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
-----------------------------------------------------
setup 0.00
084-sudo-cgcreate_systemd_scope_pid.py 2.16
teardown 0.00
-----------------------------------------------------
Total Run Time 2.16
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
TJH: Added one more call to Cgroup.get_pids_in_cgroup()
ftests: cgroup: add support to pass pid for systemd scope
Add support to pass a task pid, while creating systemd slice/scope, this
helps the users to specify the task they wish to run instead of the
default idle_thread in the transient scope.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
tools/cgcreate: add -p <pid> support for systemd scope
Currently, an idle_thread is created for the transient systemd scope by
default, it works fine, when the slice/scope creation is treated in par
to create of traditional cgroup, but the user may wish to create a
slice/scope, with a process of their choice, instead of a default idle
thread. Add support to pass task pid via '-p/--pid' option, while
creating a systemd slice/scope.
ftests: Add cgroup_get_current_controller_path() (v2) test
Add a test cases to stress pybindings of get_current_controller_path(),
that calls cgroup_get_current_controller_path() on unified mode.
-----------------------------------------------------------------
Test Results:
Run Date: Apr 27 11:21:33
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
-----------------------------------------------------------
setup 0.00
082-pybindings-cgrp_get_curr_ctrl_path-v2.py 2.18
teardown 0.00
-----------------------------------------------------------
Total Run Time 2.18
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
ftests: Add cgroup_get_current_controller_path() (v1) test
Add a test cases to stress pybindings of get_current_controller_path(),
that calls cgroup_get_current_controller_path() on legacy/hybrid mode.
-----------------------------------------------------------------
Test Results:
Run Date: Apr 27 11:10:22
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
-----------------------------------------------------------
setup 0.00
081-pybindings-cgrp_get_curr_ctrl_path-v1.py 2.34
teardown 0.00
-----------------------------------------------------------
Total Run Time 2.34
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
api.c: add cgroup v2 support to cgroup_get_current_controller_path()
Add support to read/parse cgroup v2 format /proc/<pid>/cgroup to
cgroup_get_current_controller_path(). The format of /proc/<pid>/cgroup
remains the same:
hierarchy-ID:controller-list:cgroup-path
the difference is that in cgroup v2 mode:
- hierarchy-ID is always 0 (one hierarchy allowed)
- controller-list is empty
there can also be a mix of both legacy and unified controllers for a
given task if the cgroup mode is hybrid mode. This patch, add support
for the mixed cgroup setup mode too.
ftests: add test case to excerise cgroup_setup_mode helpers
Add tests to excerise the cgroup_setup_mode() helpers pybindings
is_cgroup_mode_{legacy,hybrid,unified}
-----------------------------------------------------------------
Test Results:
Run Date: Apr 25 12:46:29
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
----------------------------------------------------
setup 0.00
083-pybindings-helpers_cgroup_mode.py 0.00
teardown 0.00
----------------------------------------------------
Total Run Time 0.00
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
export cgroup_setup_mode(), the function will be helpful for the
developers to take decisions/actions based on the cgroup setup mode the
system is booted with.
Suggested-by: Tom Hromatka <tom.hromatka@oracle.com> Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
CID 313909 (#1 of 1): Uninitialized scalar variable (UNINIT)8.
uninit_use_in_call: Using uninitialized value *info.name as argument to
%s when calling fprintf.
In cgroup_add_all_controllers(), fix the wrong variable name in the
error message, while parsing the controller name.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Mon, 17 Apr 2023 14:58:15 +0000 (14:58 +0000)]
ftests: Add a domain invalid test
-----------------------------------------------------------------
Test Results:
Run Date: Apr 13 19:23:11
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
-------------------------------------------
setup 0.00
080-kernel-domain_invalid.py 4.22
teardown 0.00
-------------------------------------------
Total Run Time 4.22
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Mon, 17 Apr 2023 14:57:15 +0000 (14:57 +0000)]
ftests: Add a test to create a default systemd scope via cgcreate
Add a test to create a systemd scope via the cgcreate command
line tool. The scope is set as the default and used to create
a child cgroup.
-----------------------------------------------------------------
Test Results:
Run Date: Apr 10 21:39:10
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Test Time (sec)
--------------------------------------------------------
setup 0.00
079-sudo-cgcreate_default_systemd_scope.py 5.06
teardown 0.00
--------------------------------------------------------
Total Run Time 5.06
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Tue, 4 Apr 2023 22:32:12 +0000 (22:32 +0000)]
ftests: Add a test to create a systemd scope via cgcreate
Add a test to create a systemd scope via the cgcreate command
line tool.
-----------------------------------------------------------------
Test Results:
Run Date: Apr 05 01:35:43
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
------------------------------------------------
setup 0.00
078-sudo-cgcreate_systemd_scope.py 5.03
teardown 0.00
------------------------------------------------
Total Run Time 5.03
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Thu, 6 Apr 2023 19:36:57 +0000 (13:36 -0600)]
man: document cgcreate's -c and -S options
Add documentation about the -c (create scope) option and the -S
(set as default) option in the cgcreate man page. -c instructs
cgcreate to invoke cgroup_create_scope2() and create a systemd
scope. -S (used in conjunction with -c) will set the provided
scope as the default for subsequent libcgroup operations.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Wed, 5 Apr 2023 15:38:55 +0000 (15:38 +0000)]
src: ftests: Better management of libcgroup idle thread
Add the libcgroup_systemd_idle_thread to the EXTRA_DIST list. This
makes it available during `make distcheck`.
Modifying the PATH environment variable when running sudo is not
allowed on some systems. Copy the libcgroup_systemd_idle_thread
to /bin to overcome this.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Tue, 4 Apr 2023 22:31:51 +0000 (22:31 +0000)]
ftests: Add cgcreate systemd scope support
Add support for creating systemd scopes via the cgcreate command
line tool.
Python's subprocess.Popen.communicate() will not return until the
spawned process and all of its children finish running. This will
cause a cgcreate of a scope to hang because libcgroup creates an
idle process in the newly-created scope. Add a timeout to the run()
method so that it can complete even when a child process remains.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Mon, 3 Apr 2023 15:39:31 +0000 (09:39 -0600)]
cgcreate: Add support to create a systemd scope
Add support to create a systemd scope. A user can create a delegated
systemd scope using the following format:
$ cgcreate -c -g <controllers>:<slicename>/<scopename>
e.g.
$ cgcreate -c -g cpu,memory:libcgroup.slice/database.scope
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Tue, 4 Apr 2023 21:31:12 +0000 (21:31 +0000)]
systemd: Cleanup return codes in cgroup_create_scope()
cgroup_create_scope() used a single variable, ret, to handle return
codes from systemd/dbus, system calls, and internal libcgroup functions.
Use a separate return variable for each of these three cases to clearly
delineate errors.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Add '-c' option to cgget, that prints the controllers and their
versions,
this is useful for the user, who wants to list the available controllers
and/or their version too.
cgxget tool crashes, when passing basic operations such as multiple
cgroups as arguments or invalid parameters, it turns out the address of
struct cgroup passed for cgroup_free() has been invalid.
$ sudo ./src/tools/cgxget -1 -r cpu.shares a b
Segmentation fault (core dumped)
$ sudo ./src/tools/cgxget -1 cpu.shares a b
Segmentation fault (core dumped)
this patch fixes it by passing the right address of the struct cgroup[]
to cgroup_free().
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
'-m' is logically an independent option and should not be mixed and
matched with other options and also when used with '-h', help always
takes precedence over other options. Fix both cases of usage with
a bool flag, that gets set when parsing the command line option but
executes only it meets the rules of not mixing with other options.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Fri, 17 Mar 2023 15:25:49 +0000 (09:25 -0600)]
ftests: Add test for cgroup_get_procs()
Add a functional test for cgroup_get_procs()
-----------------------------------------------------------------
Test Results:
Run Date: Mar 17 16:11:34
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
-------------------------------------------------
setup 0.00
077-pybindings-cgroup_get_procs.py 40.31
teardown 0.00
-------------------------------------------------
Total Run Time 40.31
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
ftests-070: avoid enabling controller on leaf cgroup node
cgroup v2, has no internal process constraint, where the process runs
only on the leaf node of the cgroup hierarchy and no controllers should
be enabled on the leaf cgroup node too. Let's not enable cpu controller
on the leaf cgroup node.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
ftests-068: avoid enabling controller on leaf cgroup node
cgroup v2, has no internal process constraint, where the process runs
only on the leaf node of the cgroup hierarchy and no controllers should
be enabled on the leaf cgroup node too. Let's not enable cpu controller
on the leaf cgroup node.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
ftests-066: avoid enabling controller on leaf cgroup node
cgroup v2, has no internal process constraint, where the process runs
only on the leaf node of the cgroup hierarchy and no controllers should
be enabled on the leaf cgroup node too. Let's not enable cpu controller
on the leaf cgroup node. Also, fix the expected stderr, accordingly
while migrating the tasks using cgclassify.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>