@@ -294,6 +294,8 @@ _cleanup() {
done
unset RESTORE_CPUS_ONLINE
fi
+
+ _cleanup_cgroup2
}
_call_test() {
@@ -202,3 +202,51 @@ _test_dev_in_hotplug_slot() {
_filter_xfs_io_error() {
sed -e 's/^\(.*\)64\(: .*$\)/\1\2/'
}
+
+_cgroup2_base_dir()
+{
+ grep cgroup2 /proc/mounts | awk '{ print $2 }'
+}
+
+_cleanup_cgroup2()
+{
+ _dir=$(_cgroup2_base_dir)/blktests
+ [ -d "${_dir}" ] || return
+
+ for i in $(find ${_dir} -type d | tac)
+ do
+ rmdir $i
+ done
+}
+
+_have_cgroup2()
+{
+ if ! grep -q 'cgroup2' /proc/mounts; then
+ SKIP_REASON="This test requires cgroup2"
+ return 1
+ fi
+ return 0
+}
+
+_have_cgroup2_controller_file()
+{
+ _have_cgroup2 || return 1
+
+ _controller=$1
+ _file=$2
+ _dir=$(_cgroup2_base_dir)
+
+ if ! grep -q ${_controller} ${_dir}/cgroup.controllers; then
+ SKIP_REASON="No support for ${_controller} cgroup controller"
+ return 1
+ fi
+
+ mkdir ${_dir}/blktests
+ echo "+${_controller}" > ${_dir}/cgroup.subtree_control
+ if [ ! -f ${_dir}/blktests/${_file} ]; then
+ _cleanup_cgroup2
+ SKIP_REASON="Cgroup file ${_file} doesn't exist"
+ return 1
+ fi
+ return 0
+}
In order to test io.latency and other cgroup related things we need some supporting helpers to setup and tear down cgroup2. This adds support for checking that we can even configure cgroup2 things, set them up if need be, and then add the cleanup stuff to the main cleanup function so everything is always in a clean state. Signed-off-by: Josef Bacik <josef@toxicpanda.com> --- check | 2 ++ common/rc | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+)