From: Josef Bacik Date: Wed, 5 Dec 2018 15:34:03 +0000 (-0500) Subject: blktests: add cgroup2 infrastructure X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=ae7daae7e35adccd07e73873b384235be6460327;p=users%2Fsagi%2Fblktests.git blktests: add cgroup2 infrastructure 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 [Omar: split into separate file, fix shellcheck errors, rework cleanup/exit] Signed-off-by: Omar Sandoval --- diff --git a/check b/check index ebd87c0..6c6d9f5 100755 --- 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 index 0000000..d445093 --- /dev/null +++ b/common/cgroup @@ -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 +} diff --git a/common/rc b/common/rc index 723b5b0..153a323 100644 --- a/common/rc +++ b/common/rc @@ -9,6 +9,7 @@ shopt -s extglob . common/shellcheck # Include fio helpers by default. . common/fio +. common/cgroup # If a test runs multiple "subtests", then each subtest should typically run # for TIMEOUT / number of subtests. diff --git a/common/shellcheck b/common/shellcheck index 4197696..5f46c00 100644 --- a/common/shellcheck +++ b/common/shellcheck @@ -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 }