]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
blktests: add cgroup2 infrastructure
authorJosef Bacik <josef@toxicpanda.com>
Wed, 5 Dec 2018 15:34:03 +0000 (10:34 -0500)
committerOmar Sandoval <osandov@fb.com>
Fri, 7 Dec 2018 19:49:57 +0000 (11:49 -0800)
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>
[Omar: split into separate file, fix shellcheck errors, rework
 cleanup/exit]
Signed-off-by: Omar Sandoval <osandov@fb.com>
check
common/cgroup [new file with mode: 0644]
common/shellcheck

diff --git a/check b/check
index ebd87c097e2567e74612b858215f1d0feef4d4fa..6c6d9f56a9259f1ef0842316e91483822fc3fc8b 100755 (executable)
--- a/check
+++ b/check
@@ -294,6 +294,8 @@ _cleanup() {
                done
                unset RESTORE_CPUS_ONLINE
        fi
+
+       _exit_cgroup2
 }
 
 _call_test() {
diff --git a/common/cgroup b/common/cgroup
new file mode 100644 (file)
index 0000000..d445093
--- /dev/null
@@ -0,0 +1,63 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+#
+# cgroup helper functions.
+
+. common/shellcheck
+
+_cgroup2_base_dir()
+{
+       findmnt -ft cgroup2 -no TARGET
+}
+
+_init_cgroup2()
+{
+       CGROUP2_DIR="$(_cgroup2_base_dir)/blktests"
+       if ! mkdir "$CGROUP2_DIR"; then
+               unset CGROUP2_DIR
+               return 1
+       fi
+       return 0
+}
+
+_exit_cgroup2()
+{
+       if [[ -n $CGROUP2_DIR ]]; then
+               find "$CGROUP2_DIR" -type d -delete
+               unset CGROUP2_DIR
+       fi
+}
+
+_have_cgroup2()
+{
+       if [[ -z $(_cgroup2_base_dir) ]]; then
+               SKIP_REASON="cgroup2 is not mounted"
+               return 1
+       fi
+       return 0
+}
+
+_have_cgroup2_controller_file()
+{
+       _have_cgroup2 || return 1
+
+       local controller="$1"
+       local file="$2"
+       local dir
+
+       dir="$(_cgroup2_base_dir)"
+       if ! grep -q "$controller" "$dir/cgroup.controllers"; then
+               SKIP_REASON="no support for $controller cgroup controller; if it is enabled, you may need to boot with cgroup_no_v1=$controller"
+               return 1
+       fi
+
+       mkdir "$dir/blktests"
+       echo "+$controller" > "$dir/cgroup.subtree_control"
+       if [[ ! -f $dir/blktests/$file ]]; then
+               rmdir "$dir/blktests"
+               SKIP_REASON="cgroup file $file doesn't exist"
+               return 1
+       fi
+       rmdir "$dir/blktests"
+       return 0
+}
index 41976966e18735bd956acc48cb5d2b2936e4a50c..5f46c008d37a9bdfc36721bb054e0d9f8b2e9540 100644 (file)
@@ -6,5 +6,5 @@
 
 # Suppress unused global variable warnings.
 _silence_sc2034() {
-       echo "$CHECK_DMESG $DESCRIPTION $DMESG_FILTER $FIO_PERF_FIELDS $FIO_PERF_PREFIX $QUICK $SKIP_REASON ${TEST_RUN[*]} $TIMED" > /dev/null
+       echo "$CGROUP2_DIR $CHECK_DMESG $DESCRIPTION $DMESG_FILTER $FIO_PERF_FIELDS $FIO_PERF_PREFIX $QUICK $SKIP_REASON ${TEST_RUN[*]} $TIMED" > /dev/null
 }