[LTP] [PATCH 3/4] controllers/cgroup_fj: Update cgroup_fj_common to work under cgroup2
Luke Nowakowski-Krijger
luke.nowakowskikrijger@canonical.com
Sat Nov 27 01:04:24 CET 2021
Check under which hierachy a controller is mounted on and set
the appropriate paths and variables to be able to access it.
Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
---
.../controllers/cgroup_fj/cgroup_fj_common.sh | 73 +++++++++++++------
1 file changed, 50 insertions(+), 23 deletions(-)
diff --git a/testcases/kernel/controllers/cgroup_fj/cgroup_fj_common.sh b/testcases/kernel/controllers/cgroup_fj/cgroup_fj_common.sh
index 53ab637e8..6c7cb1fa5 100755
--- a/testcases/kernel/controllers/cgroup_fj/cgroup_fj_common.sh
+++ b/testcases/kernel/controllers/cgroup_fj/cgroup_fj_common.sh
@@ -48,11 +48,11 @@ attach_and_check()
tst_resm TINFO "Attaching task $pid to $path"
- ROD echo "$pid" \> "$path/tasks"
+ ROD echo "$pid" \> "$path/$task_list"
- for task in $(cat "$path/tasks"); do
+ for task in $(cat "$path/$task_list"); do
if [ "$task" -ne "$pid" ]; then
- tst_resm TINFO "Unexpected pid $task in $path/tasks, expected $pid"
+ tst_resm TINFO "Unexpected pid $task in $path/$task_list, expected $pid"
return 1
fi
done
@@ -68,7 +68,9 @@ create_subgroup()
# cpuset.cpus and cpuset.mems must be initialized with suitable value
# before any pids are attached
- if [ "$subsystem" = "cpuset" ]; then
+ # Only needs to be done for cgroup v1 as sets are inherited from parents
+ # by default in cgroup v2
+ if [ "$cgroup_v" = "v1" ] && [ "$subsystem" = "cpuset" ]; then
if [ -e "$mount_point/cpus" ]; then
ROD cat "$mount_point/cpus" \> "$path/cpus"
ROD cat "$mount_point/mems" \> "$path/mems"
@@ -79,6 +81,39 @@ create_subgroup()
fi
}
+setup_cgroupv2()
+{
+ mount_point=$(grep -w cgroup2 /proc/mounts | cut -f 2 | cut -d " " -f2)
+ if ! grep -q "$subsystem" "$mount_point"/cgroup.controllers; then
+ tst_resm TINFO "$subsystem controller not supported on cgroup v2."
+ return
+ fi
+
+ task_list="cgroup.procs"
+ cgroup_v="v2"
+}
+
+setup_cgroupv1()
+{
+ exist=$(grep -w "$subsystem" /proc/cgroups | cut -f1);
+ if [ "$exist" = "" ]; then
+ tst_brk TCONF NULL "$subsystem controller not supported"
+ fi
+
+ mount_point=$(grep -w "$subsystem" /proc/mounts | cut -f 2 | cut -d " " -f2)
+ if [ "$mount_point" = "" ]; then
+ cgroup_mounted=0
+ mount_point="/dev/cgroup"
+ fi
+
+ if [ "$cgroup_mounted" -eq "0" ]; then
+ ROD mkdir -p $mount_point
+ ROD mount -t cgroup -o "$subsystem" none $mount_point
+ fi
+
+ task_list="tasks"
+ cgroup_v="v1"
+}
setup()
{
@@ -94,18 +129,17 @@ setup()
tst_tmpdir
TST_CLEANUP=cleanup
- mount_point=`grep -w $subsystem /proc/mounts | grep -w "cgroup" | \
- cut -f 2 | cut -d " " -f2`
-
- if [ -z "$mount_point" ]; then
- try_umount=1
- mount_point="/dev/cgroup"
- tst_resm TINFO "Subsystem $subsystem is not mounted, mounting it at $mount_point"
- ROD mkdir $mount_point
- ROD mount -t cgroup -o "$subsystem" "ltp_cgroup" "$mount_point"
- else
- tst_resm TINFO "Subsystem $subsystem is mounted at $mount_point"
+ cgroup_mounted=1
+
+ if grep -q cgroup2 /proc/mounts; then
+ setup_cgroupv2
+ fi
+
+ if [ -z "$cgroup_v" ]; then
+ setup_cgroupv1
fi
+
+ tst_resm TINFO "test starts with cgroup $cgroup_v"
}
cleanup()
@@ -118,15 +152,8 @@ cleanup()
find "$mount_point/ltp/" -depth -type d -exec rmdir '{}' \;
- if [ -z "$try_umount" ]; then
- return
- fi
-
- if grep -q "$mount_point" /proc/mounts; then
+ if [ "$cgroup_mounted" -eq "0" ]; then
EXPECT_PASS umount "$mount_point"
- fi
-
- if [ -e "$mount_point" ]; then
EXPECT_PASS rmdir "$mount_point"
fi
}
--
2.32.0
More information about the ltp
mailing list