From: Christoph Hellwig <hch@lst.de>
To: fstests@vger.kernel.org, linux-btrfs@vger.kernel.org
Subject: [PATCH 1/2] common: provide generic block error injection helper
Date: Mon, 4 Jul 2022 11:03:45 +0200 [thread overview]
Message-ID: <20220704090346.108134-1-hch@lst.de> (raw)
Various tests have more or less copy and pasted code to enable and
disable block layer "fail make request" error injection. Move that
to a set of common helpers and use those in the drivers.
btrfs/150 differened from the other two in a few ways, like selecting
a not quite as big number to fail all requests in the small critical
section and clearing a bunch of never set attributes in the failure
injection configuration, but none of those matter for the test
execution.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
common/inject | 33 +++++++++++++++++++++++++++++++++
tests/btrfs/088 | 24 +++++-------------------
tests/btrfs/150 | 27 +++++----------------------
tests/generic/019 | 44 +++++++++-----------------------------------
4 files changed, 52 insertions(+), 76 deletions(-)
diff --git a/common/inject b/common/inject
index 6b590804..137ff5fd 100644
--- a/common/inject
+++ b/common/inject
@@ -111,3 +111,36 @@ _scratch_inject_error()
_fail "Cannot inject error ${type} value ${value}."
fi
}
+
+# enable block error injection globally
+_enable_fail_make_request()
+{
+ 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
+}
+
+# disable block error injection globally
+_disable_fail_make_request()
+{
+ echo 0 > $DEBUGFS_MNT/fail_make_request/probability
+ echo 0 > $DEBUGFS_MNT/fail_make_request/times
+}
+
+# make a device always fail
+_start_fail_dev()
+{
+ local sysfs_bdev=`_sysfs_dev $1`
+
+ echo " echo 1 > $sysfs_bdev/make-it-fail" >> $seqres.full
+ echo 1 > $sysfs_bdev/make-it-fail
+}
+
+# stop a device from failing
+_stop_fail_dev()
+{
+ local sysfs_bdev=`_sysfs_dev $1`
+
+ echo " echo 0 > $sysfs_bdev/make-it-fail" >> $seqres.full
+ echo 0 > $sysfs_bdev/make-it-fail
+}
diff --git a/tests/btrfs/088 b/tests/btrfs/088
index d9c5528b..bd02401a 100755
--- a/tests/btrfs/088
+++ b/tests/btrfs/088
@@ -18,29 +18,13 @@ _begin_fstest auto quick metadata
# Import common functions.
. ./common/filter
+. ./common/inject
# 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
-}
-
-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
-}
-
# We will abort a btrfs transaction later, which always produces a warning in
# dmesg. We do not want the test to fail because of this.
_disable_dmesg_check
@@ -72,12 +56,14 @@ $XFS_IO_PROG -c "pwrite -S 0xbb 512K 1M" $SCRATCH_MNT/foo | _filter_xfs_io
# perform a discard operation against the pinned exents. This made the fs
# unmountable because the btree roots that the superblock points at were written
# in place (by the discard operations).
-enable_io_failure
+_enable_fail_make_request
+_start_fail_dev $SCRATCH_DEV
# This sync will trigger a commit of the current transaction, which will be
# aborted because IO will fail for metadata extents (btree nodes/leafs).
sync
-disable_io_failure
+_stop_fail_dev $SCRATCH_DEV
+_disable_fail_make_request
touch $SCRATCH_MNT/abc >>$seqres.full 2>&1 && \
echo "Transaction was not aborted, filesystem is not in readonly mode"
diff --git a/tests/btrfs/150 b/tests/btrfs/150
index c5e9c709..cc80cb41 100755
--- a/tests/btrfs/150
+++ b/tests/btrfs/150
@@ -15,6 +15,7 @@ _begin_fstest auto quick dangerous read_repair
# Import common functions.
. ./common/filter
+. ./common/inject
# real QA test starts here
@@ -25,24 +26,6 @@ _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
- echo 1 > $DEBUGFS_MNT/fail_make_request/task-filter
- echo 1 > $SYSFS_BDEV/make-it-fail
-}
-
-disable_io_failure()
-{
- echo 0 > $DEBUGFS_MNT/fail_make_request/probability
- echo 0 > $DEBUGFS_MNT/fail_make_request/times
- echo 0 > $DEBUGFS_MNT/fail_make_request/task-filter
- echo 0 > $SYSFS_BDEV/make-it-fail
-}
-
_check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
_scratch_pool_mkfs "-d raid1 -b 1G" >> $seqres.full 2>&1
@@ -59,15 +42,15 @@ while [[ -z $result ]]; do
# invalidate the page cache
$XFS_IO_PROG -f -c "fadvise -d 0 8K" $SCRATCH_MNT/foobar
- enable_io_failure
-
+ _enable_fail_make_request
+ _start_fail_dev $SCRATCH_DEV
result=$(bash -c "
if [ \$((\$\$ % 2)) == 1 ]; then
echo 1 > /proc/\$\$/make-it-fail
exec $XFS_IO_PROG -c \"pread 0 8K\" \$SCRATCH_MNT/foobar
fi")
-
- disable_io_failure
+ _stop_fail_dev $SCRATCH_DEV
+ _disable_fail_make_request
done
_scratch_dev_pool_put
diff --git a/tests/generic/019 b/tests/generic/019
index 45c91624..3cfcb7c5 100755
--- a/tests/generic/019
+++ b/tests/generic/019
@@ -14,47 +14,18 @@ fio_config=$tmp.fio
# Import common functions.
. ./common/filter
+. ./common/inject
_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
+ echo "Disallow global fail_make_request feature"
+ _disable_fail_make_request
cd /
rm -r -f $tmp.*
}
@@ -129,7 +100,8 @@ _workout()
# Let's it work for awhile, and force device failure
sleep $RUN_TIME
- start_fail_scratch_dev
+ echo "Force SCRATCH_DEV device failure"
+ _start_fail_dev $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 +119,8 @@ _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
+ echo "Make SCRATCH_DEV device operable again"
+ _stop_fail_dev $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 +132,8 @@ _workout()
_scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
_scratch_mount
-allow_fail_make_request
+echo "Allow global fail_make_request feature"
+_enable_fail_make_request
_workout
status=$?
exit
--
2.30.2
next reply other threads:[~2022-07-04 9:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-04 9:03 Christoph Hellwig [this message]
2022-07-04 9:03 ` [PATCH 2/2] btrfs: test raid1 write error handling Christoph Hellwig
2022-07-04 15:00 ` [PATCH 1/2] common: provide generic block error injection helper Anand Jain
2022-07-05 7:43 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220704090346.108134-1-hch@lst.de \
--to=hch@lst.de \
--cc=fstests@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.