]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
common: refactor fail_make_request boilerplate
authorDarrick J. Wong <djwong@kernel.org>
Wed, 3 Aug 2022 04:22:15 +0000 (21:22 -0700)
committerZorro Lang <zlang@kernel.org>
Sat, 20 Aug 2022 14:10:32 +0000 (22:10 +0800)
Refactor the control functions from generic/019 into a common helper to
be used by all three tests that use fail_make_requests.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Zorro Lang <zlang@kernel.org>
common/fail_make_request [new file with mode: 0644]
common/rc
tests/btrfs/088
tests/btrfs/150
tests/generic/019

diff --git a/common/fail_make_request b/common/fail_make_request
new file mode 100644 (file)
index 0000000..581d176
--- /dev/null
@@ -0,0 +1,47 @@
+##/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# common functions for setting up and tearing down block device error injection
+
+_require_fail_make_request()
+{
+    [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
+       || _notrun "$DEBUGFS_MNT/fail_make_request \
+ not found. Seems that CONFIG_FAULT_INJECTION_DEBUG_FS kernel config option not enabled"
+}
+
+_allow_fail_make_request()
+{
+    local prob="${1:-100}"
+    local times="${2:-9999999}"
+    local verbose="${3:-0}"
+
+    echo "Allow global fail_make_request feature"
+    echo "$prob" > $DEBUGFS_MNT/fail_make_request/probability
+    echo "$times" > $DEBUGFS_MNT/fail_make_request/times
+    echo "$verbose" > $DEBUGFS_MNT/fail_make_request/verbose
+}
+
+_disallow_fail_make_request()
+{
+    echo "Disallow global fail_make_request feature"
+    echo 0 > $DEBUGFS_MNT/fail_make_request/probability
+    echo 0 > $DEBUGFS_MNT/fail_make_request/times
+    echo 0 > $DEBUGFS_MNT/fail_make_request/verbose
+}
+
+_start_fail_scratch_dev()
+{
+    local SYSFS_BDEV=`_sysfs_dev $SCRATCH_DEV`
+    echo "Force SCRATCH_DEV device failure"
+    echo " echo 1 > $SYSFS_BDEV/make-it-fail" >> $seqres.full
+    echo 1 > $SYSFS_BDEV/make-it-fail
+}
+
+_stop_fail_scratch_dev()
+{
+    local SYSFS_BDEV=`_sysfs_dev $SCRATCH_DEV`
+    echo "Make SCRATCH_DEV device operable again"
+    echo " echo 0 > $SYSFS_BDEV/make-it-fail" >> $seqres.full
+    echo 0 > $SYSFS_BDEV/make-it-fail
+}
index e20c494c70204d35534fd4c8ef6f0c71d69a6669..c4cd773ed1b9821cfd5c5766f86b2937b833f24e 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -2746,13 +2746,6 @@ _require_debugfs()
     [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
 }
 
-_require_fail_make_request()
-{
-    [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
-       || _notrun "$DEBUGFS_MNT/fail_make_request \
- not found. Seems that CONFIG_FAULT_INJECTION_DEBUG_FS kernel config option not enabled"
-}
-
 # The default behavior of SEEK_HOLE is to always return EOF.
 # Filesystems that implement non-default behavior return the offset
 # of holes with SEEK_HOLE. There is no way to query the filesystem
index d9c5528b37be83e5442378fab70837a5a09e6fdf..59972ae7a117bbe6807631eb89c67e6557c52e33 100755 (executable)
@@ -18,27 +18,23 @@ _begin_fstest auto quick metadata
 
 # Import common functions.
 . ./common/filter
+. ./common/fail_make_request
 
 # real QA test starts here
 _supported_fs btrfs
 _require_scratch
 _require_fail_make_request
 
-SYSFS_BDEV=`_sysfs_dev $SCRATCH_DEV`
-
 enable_io_failure()
 {
-       echo 100 > $DEBUGFS_MNT/fail_make_request/probability
-       echo 1000 > $DEBUGFS_MNT/fail_make_request/times
-       echo 0 > $DEBUGFS_MNT/fail_make_request/verbose
-       echo 1 > $SYSFS_BDEV/make-it-fail
+       _allow_fail_make_request 100 1000 > /dev/null
+       _start_fail_scratch_dev > /dev/null
 }
 
 disable_io_failure()
 {
-       echo 0 > $SYSFS_BDEV/make-it-fail
-       echo 0 > $DEBUGFS_MNT/fail_make_request/probability
-       echo 0 > $DEBUGFS_MNT/fail_make_request/times
+       _stop_fail_scratch_dev > /dev/null
+       _disallow_fail_make_request > /dev/null
 }
 
 # We will abort a btrfs transaction later, which always produces a warning in
index c5e9c709804fe797b79e1f16ed521d707c4ee13d..a7d7d9cc8c9df1a37233e3f4cf151b7eb4023aba 100755 (executable)
@@ -15,6 +15,7 @@ _begin_fstest auto quick dangerous read_repair
 
 # Import common functions.
 . ./common/filter
+. ./common/fail_make_request
 
 # real QA test starts here
 
@@ -25,22 +26,18 @@ _require_fail_make_request
 _require_scratch_dev_pool 2
 _scratch_dev_pool_get 2
 
-SYSFS_BDEV=`_sysfs_dev $SCRATCH_DEV`
 enable_io_failure()
 {
-       echo 100 > $DEBUGFS_MNT/fail_make_request/probability
-       echo 1000 > $DEBUGFS_MNT/fail_make_request/times
-       echo 0 > $DEBUGFS_MNT/fail_make_request/verbose
+       _allow_fail_make_request 100 1000 > /dev/null
        echo 1 > $DEBUGFS_MNT/fail_make_request/task-filter
-       echo 1 > $SYSFS_BDEV/make-it-fail
+       _start_fail_scratch_dev > /dev/null
 }
 
 disable_io_failure()
 {
-       echo 0 > $DEBUGFS_MNT/fail_make_request/probability
-       echo 0 > $DEBUGFS_MNT/fail_make_request/times
+       _disallow_fail_make_request > /dev/null
        echo 0 > $DEBUGFS_MNT/fail_make_request/task-filter
-       echo 0 > $SYSFS_BDEV/make-it-fail
+       _stop_fail_scratch_dev > /dev/null
 }
 
 _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
index 45c91624d32ac134e17d83e2d3751209af9dbaf5..b68dd90c0dd42727ef6e96db8db47205780d1b08 100755 (executable)
@@ -14,47 +14,17 @@ fio_config=$tmp.fio
 
 # Import common functions.
 . ./common/filter
+. ./common/fail_make_request
 _supported_fs generic
 _require_scratch
 _require_block_device $SCRATCH_DEV
 _require_fail_make_request
 
-SYSFS_BDEV=`_sysfs_dev $SCRATCH_DEV`
-
-allow_fail_make_request()
-{
-    echo "Allow global fail_make_request feature"
-    echo 100 > $DEBUGFS_MNT/fail_make_request/probability
-    echo 9999999 > $DEBUGFS_MNT/fail_make_request/times
-    echo 0 >  /sys/kernel/debug/fail_make_request/verbose
-}
-
-disallow_fail_make_request()
-{
-    echo "Disallow global fail_make_request feature"
-    echo 0 > $DEBUGFS_MNT/fail_make_request/probability
-    echo 0 > $DEBUGFS_MNT/fail_make_request/times
-}
-
-start_fail_scratch_dev()
-{
-    echo "Force SCRATCH_DEV device failure"
-    echo " echo 1 > $SYSFS_BDEV/make-it-fail" >> $seqres.full
-    echo 1 > $SYSFS_BDEV/make-it-fail
-}
-
-stop_fail_scratch_dev()
-{
-    echo "Make SCRATCH_DEV device operable again"
-    echo " echo 0 > $SYSFS_BDEV/make-it-fail" >> $seqres.full
-    echo 0 > $SYSFS_BDEV/make-it-fail
-}
-
 # Override the default cleanup function.
 _cleanup()
 {
        kill $fs_pid $fio_pid &> /dev/null
-       disallow_fail_make_request
+       _disallow_fail_make_request
        cd /
        rm -r -f $tmp.*
 }
@@ -129,7 +99,7 @@ _workout()
 
        # Let's it work for awhile, and force device failure
        sleep $RUN_TIME
-       start_fail_scratch_dev
+       _start_fail_scratch_dev
        # After device turns in to failed state filesystem may yet not know about
        # that so buffered write(2) may succeed, but any integrity operations
        # such as (sync, fsync, fdatasync, direct-io) should fail.
@@ -147,7 +117,7 @@ _workout()
        run_check _scratch_unmount
        # Once filesystem was umounted no one is able to write to block device
        # It is now safe to bring device back to normal state
-       stop_fail_scratch_dev
+       _stop_fail_scratch_dev
 
        # In order to check that filesystem is able to recover journal on mount(2)
        # perform mount/umount, after that all errors should be fixed
@@ -159,7 +129,7 @@ _workout()
 
 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
 _scratch_mount
-allow_fail_make_request
+_allow_fail_make_request
 _workout
 status=$?
 exit