Kamalesh Babulal [Wed, 16 Mar 2022 16:24:34 +0000 (21:54 +0530)]
lssubsys.c: fix checkpatch.pl warnings
Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl,
except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO and NEW_TYPEDEFS types. It
also introduces reverse xmas tree local variable declarations and header
file reordering.
In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 0 errors, 16 warnings, 295 lines checked
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Wed, 16 Mar 2022 15:45:33 +0000 (21:15 +0530)]
lscgroup.c: fix checkpatch.pl warnings
Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl,
except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO and NEW_TYPEDEFS types. It
also introduces reverse xmas tree local variable declarations and header
file reordering.
In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 0 errors, 9 warnings, 328 lines checked
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Wed, 16 Mar 2022 15:45:01 +0000 (21:15 +0530)]
cgxset.c: fix checkpatch.pl warnings
Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl,
except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO and NEW_TYPEDEFS types. It
also introduces reverse xmas tree local variable declarations and header
file reordering.
In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 1 errors, 20 warnings, 385 lines checked
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Wed, 16 Mar 2022 15:42:43 +0000 (21:12 +0530)]
cgxget.c: fix checkpatch.pl warnings
Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl,
except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO and NEW_TYPEDEFS types. It
also introduces reverse xmas tree local variable declarations and header
file reordering.
In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 2 errors, 17 warnings, 921 lines checked
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Wed, 16 Mar 2022 15:37:43 +0000 (21:07 +0530)]
cgsnapshot.c: fix checkpatch.pl warnings
Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl,
except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO and NEW_TYPEDEFS types. It
also introduces reverse xmas tree local variable declarations and header
file reordering.
In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 1 errors, 39 warnings, 847 lines checked
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Wed, 16 Mar 2022 15:36:34 +0000 (21:06 +0530)]
cgset.c: fix checkpatch.pl warnings
Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl,
except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO and NEW_TYPEDEFS types. It
also introduces reverse xmas tree local variable declarations and header
file reordering.
In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 1 errors, 16 warnings, 284 lines checked
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Wed, 16 Mar 2022 15:32:16 +0000 (21:02 +0530)]
cgget.c: fix checkpatch.pl warnings
Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl,
except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO and NEW_TYPEDEFS types. It
also introduces reverse xmas tree local variable declarations and header
file reordering.
In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 2 errors, 13 warnings, 772 lines checked
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Wed, 16 Mar 2022 15:25:09 +0000 (20:55 +0530)]
cgexec.c: fix checkpatch.pl warnings
Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl,
except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO and NEW_TYPEDEFS types. It
also introduces reverse xmas tree local variable declarations and header
file reordering.
In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 2 errors, 8 warnings, 178 lines checked
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Wed, 16 Mar 2022 15:24:30 +0000 (20:54 +0530)]
cgdelete.c: fix checkpatch.pl warnings
Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl,
except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO and NEW_TYPEDEFS types. It
also introduces reverse xmas tree local variable declarations and header
file reordering.
In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 1 errors, 6 warnings, 303 lines checked
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Wed, 16 Mar 2022 15:23:50 +0000 (20:53 +0530)]
cgcreate.c: fix checkpatch.pl warnings
Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl,
except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO and NEW_TYPEDEFS types. It
also introduces reverse xmas tree local variable declarations and header
file reordering.
In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 0 errors, 10 warnings, 247 lines checked
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Wed, 16 Mar 2022 15:22:59 +0000 (20:52 +0530)]
cgconfig.c: fix checkpatch.pl warnings
Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl,
except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO and NEW_TYPEDEFS types. It
also introduces reverse xmas tree local variable declarations and header
file reordering.
In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 0 errors, 11 warnings, 213 lines checked
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Wed, 16 Mar 2022 15:22:23 +0000 (20:52 +0530)]
cgclassify.c: fix checkpatch.pl warnings
Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl,
except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO and NEW_TYPEDEFS types. It
also introduces reverse xmas tree local variable declarations and header
file reordering.
In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 2 errors, 10 warnings, 203 lines checked
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Mon, 14 Mar 2022 10:35:06 +0000 (16:05 +0530)]
.checkpatch.conf: add NEW_TYPEDEFS to ignore-list
There are tools/files, that introduce new typdefs and checkpatch.pl is
unhappy about it. It takes some re-work on removing and for now let's
teach checkpatch to ignore it.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Mon, 14 Mar 2022 04:38:44 +0000 (10:08 +0530)]
Adopt SPDX License tag for files missing license information
Adopt SPDX license tag for all the source files, those missing License
information. All the files in the project fall under project license,
hence explicitly adding LGPL-2.1-only identifier to them. The SPDX
license identifier is added for the files, reported by checkpatch.pl.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Mon, 14 Mar 2022 04:35:01 +0000 (10:05 +0530)]
Adopt SPDX License tag
Adopt SPDX license tag for all the source files, those already have
LGPL 2.1 bolierplate in them. Adopting SPDX license helps the
compliance tools to determine the license and also helps in reducing the
repetitive license boilerplate across source files.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Fri, 11 Mar 2022 14:54:43 +0000 (07:54 -0700)]
samples/c: drop the test suites
samples/c contains test cases, those do serve as good examples on how to
use some APIs, but there are also very elaborate test cases, which are
test suites in themselves. Let's drop these examples and allow users to
look at gunit/ftests for how to contribute to test cases. This patch
also modifies the Makefile to help users to build the examples, in case
they want to give it a quick try.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Fri, 11 Mar 2022 14:51:09 +0000 (07:51 -0700)]
log: add log level string prefix to logging functions
Usage of cgroup_{err, warn, info} functions, expects the log level to be
prefixed to the message like: cgroup_warn("Warning: ..."). This patch
removes this need to prefix and automatically adds the desired prefix to
the logger function, so the usage becomes cgroup_warn("..."). This
helps in readability and avoiding typos in setting the right log level
string to the message.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/abstraction-map.c: re-arrange the header files
Re-arrange the headers files, in the following order:
1. Header files that declare the functions, are defined in this file.
2. Other header files from the libcgroup.
3. Standard header file.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/abstraction-cpuset.c: re-arrange the header files
Re-arrange the headers files, in the following order:
1. Header files that declare the functions, are defined in this file.
2. Other header files from the libcgroup.
3. Standard header file.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/abstraction-cpu.c: re-arrange the header files
Re-arrange the headers files, in the following order:
1. Header files that declare the functions, are defined in this file.
2. Other header files from the libcgroup.
3. Standard header file.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl,
except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO types. It also introduces
reverse xmas tree local variable declarations and header file
reordering.
In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 26 errors, 204 warnings, 5855 lines checked
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl,
except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO types. It also introduces
reverse xmas tree local variable declarations and header file
reordering.
In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 0 errors, 55 warnings, 743 lines checked
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl,
except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO types. It also introduces
reverse xmas tree local variable declarations and header file
reordering.
In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 0 errors, 3 warnings, 96 lines checked
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Fix most of the warnings/errors reported by Linux Kernel's
checkpatch.pl, except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO types.
It also introduces reverse xmas tree local variable declarations
and header file reordering.
In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 4 errors, 36 warnings, 1899 lines checked
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl,
except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO types. It also introduces
reverse xmas tree local variable declarations and header file
reordering.
In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 5 errors, 2 warnings, 438 lines checked
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl,
except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO types. It also introduces
reverse xmas tree local variable declarations and header file
reordering.
In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 0 errors, 4 warnings, 150 lines checked
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl,
except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO types. It also introduces
reverse xmas tree local variable declarations and header file
reordering.
In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 0 errors, 7 warnings, 320 lines checked
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Mon, 28 Feb 2022 14:11:43 +0000 (19:41 +0530)]
tools/lssubsys: fix strncpy() warning
GCC complains about string truncations in
print_all_controllers_in_hierarchy:
In function 'print_all_controllers_in_hierarchy',
inlined from 'cgroup_list_all_controllers' at lssubsys.c:226:9,
inlined from 'main' at lssubsys.c:294:8:
lssubsys.c:127:25: warning: 'strncpy' output may be truncated copying 4095 bytes from a string of length 4095 [-Wstringop-truncation]
127 | strncpy(cont_name, info.name, FILENAME_MAX-1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lssubsys.c:131:25: warning: 'strncpy' output may be truncated copying 4095 bytes from a string of length 4095 [-Wstringop-truncation]
131 | strncpy(cont_names, info.name, FILENAME_MAX-1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
this warning seems to be a little odd when the current code is already
explicitly truncating the string. Digging deeper, it looks like the
memset(), followed by strncpy() with -O >= 2 triggers this warning on
GCC 11. A simple and safe fix would be removing the memset(). As per
the standard's strncpy() will fill the destination string with '\0', if
the source string length is lesser than that of the destination. This
fix, take this approach.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@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>
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>
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>
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>
Add custom functions to map cpu.cfs_quota_us <-> cpu.max and
cpu.cfs_period_us <-> cpu.max. These mappings can be 1->N or
N->1 and utilize custom values for limits, "-1" in cgroup v1
and "max" in cgroup v2.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Wed, 15 Dec 2021 20:39:52 +0000 (20:39 +0000)]
wrapper: Add function to remove name/value pair from a controller
Add a function to remove a name/value settings pair from
a cgroup_controller instance. As part of this change, I did a small
refactor on cgroup_free_controllers() to make the code more reusable
throughout libcgroup.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Wed, 15 Dec 2021 20:39:22 +0000 (20:39 +0000)]
api.c: Add const qualifier to parameters in cgroup_read_value_begin()
Make two string parameters passed into cgroup_read_value_begin()
fully constant, i.e. const char * const. These parameters,
controller and name, are only used as read-only variables
within cgroup_read_value_begin() and are not intended to be
modified.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Wed, 15 Dec 2021 20:37:37 +0000 (20:37 +0000)]
api.c/wrapper/abstraction: Save previous setting name in control_value
When there's an N->1 mapping, the abstraction layer needs
to know which "1" setting to map back to. Add a field to
struct control_value that saves off the original setting,
so that the abstraction layer can know how to map back from
an N->1 setting.
A good example of this is cpu.max/cpu.cfs_quota_us. The
abstraction layer will map cpu.cfs_quota_us to cpu.max.
During the return conversion, the abstraction layer needs
to know whether to map cpu.max to cfs_quota_us or
cfs_period_us.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Wed, 15 Dec 2021 21:11:28 +0000 (21:11 +0000)]
abstraction: Add name conversion function
Add a function to the abstraction layer that can convert from
one cgroup setting name to another setting name. The values are
not adjusted by this function. For example, this can be used for
conversions like cpuset.effective_cpus to cpuset.cpus.effective.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Fri, 28 Jan 2022 17:22:49 +0000 (10:22 -0700)]
cgxset: Introduce cgxset
Add a new libcgroup tool - cgxset. cgxset is based upon cgset,
but it supports converting from cgroup version to another.
For example, a request like the following will work on a system
running the cgroup v1 cpu controller or the cgroup v2 cpu
controller.
$ cgxset -2 -r cpu.weight=42 MyCgroup
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Fri, 28 Jan 2022 17:22:11 +0000 (10:22 -0700)]
cgxget: Introduce cgxget
Add a new libcgroup tool - cgxget. cgxget is based upon cgget,
but it supports converting from cgroup version to another.
For example, a request like the following will work on a system
running the cgroup v1 cpu controller or the cgroup v2 cpu controller.
$ cgxget -2 -r cpu.weight MyCgroup
The return value to the user will match the cgroup version requested.
If the user requests a v1 setting, the return value will be a cgroup
v1 setting. If the user requests a v2 setting, the return value will
be a cgroup v2 setting.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Wed, 15 Dec 2021 20:18:54 +0000 (20:18 +0000)]
abstraction: Add function to convert from one cgroup version to another
Add a function - cgroup_convert_cgroup() - that can convert from
one cgroup version to another. This function will be the building
block for the libcgroup abstraction layer.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Wed, 15 Dec 2021 20:14:11 +0000 (20:14 +0000)]
abstraction: Add integer conversion function
Add a function to the abstraction layer that can convert from
one integer setting to another. For example, this can be used
for simple conversions like cpu.shares to cpu.weight and vice
versa.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Wed, 15 Dec 2021 19:37:36 +0000 (19:37 +0000)]
api.c: Remove static from cgroup_copy_controller_values()
Remove static from cgroup_copy_controller_values() in api.c
so that other files within libcgroup can invoke it. It will
be used by the abstraction layer code in a subsequent commit.
Also, declare *dst as a const pointer and *src as a const *
const pointer. Subsequent abstraction layer checkins make
heavy use of const and without these changes, warnings (which
continuous integration converts to errors) are thrown.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Wed, 15 Dec 2021 19:30:30 +0000 (19:30 +0000)]
wrapper.c: Store the version in struct cgroup_controller
Store the cgroup version in struct cgroup_controller. Each
controller can be mounted separately, and thus the cgroup
version is applicable at the controller level.
Note that this commit requires cgroup_init() to be called by
cgconfigparser. Storing the version in the cgroup_controller
struct requires the cg_mount_table[] to be populated.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Kamalesh Babulal [Thu, 27 Jan 2022 19:33:52 +0000 (12:33 -0700)]
api.c: add support for cgroup.threads
cgroup_build_tasks_procs_path(), that builds the proc path for moving
the tid, doesn't check for the cgroup type and appends cgroup.procs for
both cgroup v1/v2. With cgroup v2, this results in building a wrong
proc path if the cgroup type is threaded. This patch adds support to
check for the cgroup v2 type and build the proc path according to the
below table:
cgroup.type | proc file | Description |
----------------+----------------+------------------------------------+
domain | cgroup.procs | regular cgroup, all threads gets |
| | moved to the cgroup. |
domain threaded | cgroup.procs | root of threaded subtree, all |
| | threads gets moved to the cgroup. |
threaded | cgroup.threads | cgroup under threaded subtree, |
| | single threads with matching tid, |
| | gets moved to the cgroup. |
domain invalid | N/A | invalid state of a cgroup under the|
| | threaded subtree. |
Closes: https://github.com/libcgroup/libcgroup/issues/64 Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Tue, 18 Jan 2022 15:22:13 +0000 (08:22 -0700)]
api.c: cache cgrules with CGFLAG_USECACHE flag
pam_cgroup.so plugin uses /etc/cgrules.conf to assign processes
to the requested cgroup. This works well with active
cgrulesengd but in the instances where cgrulesengd is disabled,
the rules are not read and cached by default. Fix this is by
reloading and caching the rules when called with CGFLAG_USECACHE
flag.
Fixes: https://github.com/libcgroup/libcgroup/issues/84 Reported-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
TJH: Minor commit comment changes