Tom Hromatka [Thu, 24 Feb 2022 14:55:57 +0000 (07:55 -0700)]
github: Run the libcgroup Github Actions
Add jobs to run the libcgroup automated tests against the main
branch of libcgroup. Since the Github Action is being
triggered from the tests repo, the setup steps differ slightly
from libcgroup's steps. In this case we need to move the unit
and functional tests from the root to tests/, and we need to
move the library code from libcg/ to the root.
Finally, code coverage is not enabled in these runs.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Thu, 17 Feb 2022 21:17:15 +0000 (14:17 -0700)]
api.c: Allow creation of a v2 cgroup with no controllers
Commit 498530a1d744 ("cgcreate, tools: Allow cgroup creation with
no controllers attached") attempted to add support to allow the
creation of a cgroup v2 cgroup with no controllers attached. This
patch did create the requested cgroup, but it still required there
to be at least one valid controller _available_ to attach to.
Rework the aforementioned logic so that the cgroup can be created
if there's a valid cgroup v2 mount - even if there are no v2
controllers available.
Fixes: 498530a1d744 ("cgcreate, tools: Allow cgroup creation with no controllers attached") Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Wed, 23 Feb 2022 15:01:38 +0000 (08:01 -0700)]
samples: Add C samples
Move the legacy tests from libcgroup-tests [1] to the
samples/c/ directory. While these files are no longer
being run as automated tests, they provide helpful insight
into how to utilize the libcgroup C APIs.
[1] https://github.com/libcgroup/libcgroup-tests/
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Wed, 23 Feb 2022 15:00:29 +0000 (08:00 -0700)]
configure: Delete legacy test artifacts
The legacy tests (now located in the libcgroup-tests)
repository have been moved to
https://github.com/libcgroup/libcgroup-tests/tree/main/examples
and are no longer being run. Remove all references to
the tests from the configure.ac file.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Tue, 22 Feb 2022 23:08:43 +0000 (16:08 -0700)]
cgroup.py: Fix exception handling in init_cgrules()
When /etc/cgconfig.d/ exists, a UnicodeDecodeError is
thrown because the Unicode error string cannot be
properly decoded by Run.run(). Catch this error as it's
not an error in this case.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 17 Feb 2022 19:39:43 +0000 (12:39 -0700)]
python/setup.py: make it PEP8 compliant
Make setup.py PEP-8 compliant, it fixes the following two issues
reported by flake8:
- E128 continuation line under-indented for visual indent
- E251 unexpected spaces around keyword/parameter equals
also, adopt single quotes for strings.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Mon, 14 Feb 2022 15:11:56 +0000 (08:11 -0700)]
api.c: Fix TOCTOU race cgroup_get_cg_type()
Fix a TOCTOU race condition, that checks for file existence versus file
open in cgroup_get_cg_type() by opening the file and check for errno for
file existence.
Reported-by: LGTM Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Mon, 14 Feb 2022 15:11:39 +0000 (08:11 -0700)]
api.c: fix a comparison error in cgroup_delete_cgroup_ext()
Fix a comparison logic in the first_errno assignment, that would
never get executed in the case of first_errno == ECGNONEMPTY in
cgroup_delete_cgroup_ext().
Reported-by: LGTM Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Mon, 14 Feb 2022 15:11:25 +0000 (08:11 -0700)]
api: make cgroup_get_subsys_mount_point_end() more useful
Currently cgroup_get_subsys_mount_point_end(), does nothing more than
returning zero, it was caught by LGTM altering:
"This expression has no effect (because
cgroup_get_subsys_mount_point_end has no external side effects)."
make the function more useful like other *_end() functions by including
the check for cgroup_initialized and assigning NULL to the handle used
for iterating over controller mount points.
Reported-by: LGTM Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Mon, 14 Feb 2022 15:11:08 +0000 (08:11 -0700)]
wrapper: remove false checks for snprintf
LGTM, reported that the negative value checks for snprintf() will
always be false. The reason being the snprintf() are used to print
into a character buffer, hence chances of stream error or wide
characters encoding error are not valid here. Remove the negative
return value check across the file done after snprintf().
Reported-by: LGTM Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Mon, 14 Feb 2022 15:10:43 +0000 (08:10 -0700)]
tools/cgsnapshot: rename FILE *of to output_f
LGTM, complained about using FILE *of as shorthand for the output file
and recommended using something descriptive. Rename usage of with
output_f, to keep it happy.
Reported-by: LGTM Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Mon, 14 Feb 2022 14:54:19 +0000 (07:54 -0700)]
Introduce vim modeline for python sources
Introduce vim modeline to python source files. This sets up the
vim editor to PEP-8 recommend editing style. The vim modeline added:
"# vim: set et ts=4 sw=4:"
'et' converts the tabs to spaces, 'ts' set the tabs indentation/tabstop
to 4 characters and 'sw' sets the shiftwidth to 4 characters.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Thu, 10 Feb 2022 21:44:05 +0000 (14:44 -0700)]
Introduce vim modeline for python sources
Introduce vim modeline to python source files. This sets up the
vim editor to PEP-8 recommend editing style. The vim modeline added:
"# vim: set et ts=4 sw=4:"
'et' converts the tabs to spaces, 'ts' set the tabs indentation/tabstop
to 4 characters and 'sw' sets the shiftwidth to 4 characters.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 9 Feb 2022 19:27:43 +0000 (12:27 -0700)]
api.c: Refactor cgroup_create_cgroup()
Non-functional change to refactor cgroup_create_cgroup(). Move
the contents of this "for" loop to its own function:
for (k = 0; k < cgroup->index; k++)
This will be used as a building block for the next commit to allow
the creation of cgroups with no controllers attached.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Mon, 7 Feb 2022 22:03:38 +0000 (15:03 -0700)]
ftests: Add a python cgcreate test with an empty controller field
Add a functional test that exercises the Python binding's
create() method with no controller specified.
-----------------------------------------------------------------
Test Results:
Run Date: Dec 24 14:59:32
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
----------------------------------------------------------
setup 0.00
044-pybindings-cgcreate_empty_controller.py 0.04
teardown 0.00
----------------------------------------------------------
Total Run Time 0.04
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Mon, 7 Feb 2022 21:59:22 +0000 (14:59 -0700)]
ftests: Add a cgreate test with an empty controller field
Add a functional test that exercises cgcreate with no controller
specified, e.g.
cgcreate -g :foo
cgdelete -g :foo
-----------------------------------------------------------------
Test Results:
Run Date: Dec 24 10:55:56
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
-----------------------------------------------
setup 0.00
043-cgcreate-empty_controller.py 0.04
teardown 0.00
-----------------------------------------------
Total Run Time 0.04
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
In cgroup_init(), the first line/header of /proc/cgroups helps in
interpreting the values in the remaining of the file. We are interested
in the rest of the file and a temporary buffer of size FILENAME_MAX is
allocated/deallocated after reading the header. The length of the header
is only 56 characters in length, excluding the newline. This patch
reduces it to LL_MAX a.k.a 100 characters.
LL_MAX is used instead of introducing another new length macro.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 15 Dec 2021 21:27:26 +0000 (21:27 +0000)]
github: Add a code coverage action
Add a code coverage action to the Github workflow. As part
of this code coverage action, ignore the C file that is
auto-generated from the Cython code. Also ignore a couple Python
header files that were confusing lcov.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Wed, 15 Dec 2021 21:03:28 +0000 (21:03 +0000)]
github: Skip test 38 (cpuset) on VMs hosted by Github Actions
Skip test #38 - 038-cgxget-cpuset_settings.py - on servers hosted
by Github Actions. Test #38 sets/clears the cpuset exclusive bit
and this is not allowed on Github's servers.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Add several unmappable cpuset settings. As the name implies, these
settings have no equivalent in cgroup v2:
cpuset.mem_exclusive
cpuset.mem_hardwall
cpuset.memory_migrate
cpuset.memory_pressure
cpuset.mem_pressure_enabled
cpuset.memory_spread_page
cpuset.memory_spread_slab
cpuset.sched_load_balance
cpuset.sched_relax_domain_level
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Mon, 31 Jan 2022 15:21:00 +0000 (08:21 -0700)]
cgxset: Add a flag to ignore settings that can't be converted
Add a flag, "-i", to cgxset to ignore settings that can't be
converted from cgroup v1 to cgroup v2 or vice versa.
Some cgroup v1 settings, e.g. cpuset.sched_relax_domain_level,
don't have a cgroup v2 equivalent and likely never will. This
flag allows users to ignore errors from these unconvertable
settings.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Fri, 28 Jan 2022 21:22:53 +0000 (14:22 -0700)]
cgxget: Add a flag to ignore settings that can't be converted
Add a flag, "-i", to cgxget to ignore settings that can't be
converted from cgroup v1 to cgroup v2 or vice versa.
Some cgroup v1 settings, e.g. cpuset.sched_relax_domain_level,
don't have a cgroup v2 equivalent and likely never will. This
flag allows users to ignore errors from these unconvertable
settings.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Add an unmappable mapping for the cpu.stat setting. While
the filename, cpu.stat, maps perfectly from v1 <-> v2, the
contents do not. At this time, let's set this as unmappable
and revisit it when we've thought through the best way to
map the contents.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Wed, 15 Dec 2021 21:13:29 +0000 (21:13 +0000)]
abstraction: Add support for unmappable settings
Add a function to explicitly handle settings that cannot
be mapped from v1 to v2 or vice versa. This function returns
ECGNOVERSIONCONVERT which cgxget, cgxset, etc. can then
monitor and if requested by the user, ignore.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>