common: provide generic block error injection helper
PATCH 1/2 common: provide generic block error injection helper
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.
--- common/inject | 33 +++++++++++++++++++++++++++++++++ tests/btrfs/088 | 24 +++++------------------- tests/btrfs/150 | 27 +++++---------------------- tests/generic/019 | 44 +++++++++----------------------------------- 4 files changed, 52 insertions(+), 76 deletions(-)
common/inject +33 -0
@@ -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 +}
tests/btrfs/088 +5 -19
@@ -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"
tests/btrfs/150 +5 -22
@@ -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
tests/generic/019 +9 -35
77 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH 2/2 btrfs: test raid1 write error handling
Test that a write with a single bad mirror works fine but reports errors in the error counters, and that a write with two bad mirrors fails.
--- tests/btrfs/271 | 78 +++++++ tests/btrfs/271.out | 521 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 599 insertions(+) create mode 100755 tests/btrfs/271 create mode 100644 tests/btrfs/271.out
tests/btrfs/271 new file +78 -0
@@ -0,0 +1,78 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Christoph Hellwig. +# +# FS QA Test btrfs/271 +# +# Test btrfs write error propagation and reporting on the raid1 profile. +# +. ./common/preamble +_begin_fstest auto quick raid + +. ./common/filter + +_supported_fs btrfs +_require_scratch +_require_fail_make_request +_require_scratch_dev_pool 2 +_scratch_dev_pool_get 2 + +enable_io_failure() +{ + local sysfs_bdev=`_sysfs_dev $1` + + echo 1 > $sysfs_bdev/make-it-fail +} + +disable_io_failure() +{ + local sysfs_bdev=`_sysfs_dev $1` + + 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 + +_scratch_mount + +dev2=`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}'` + +pagesize=$(get_page_size) +blocksize=$(_get_block_size $SCRATCH_MNT) +sectors_per_page=$(($pagesize / $blocksize)) + +# enable block I/O error injection +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 "Step 1: writing with one failing mirror:" +enable_io_failure $SCRATCH_DEV +$XFS_IO_PROG -f -c "pwrite -W -S 0xaa 0 8K" $SCRATCH_MNT/foobar | _filter_xfs_io +disable_io_failure $SCRATCH_DEV + +errs=$($BTRFS_UTIL_PROG device stats $SCRATCH_DEV | \ + $AWK_PROG '/write_io_errs/ { print $2 }') +if [ $errs -ne $((4 * $sectors_per_page)) ]; then + _fail "Errors: $errs expected: 4" +fi + +echo "Step 2: verify that the data reads back fine:" +$XFS_IO_PROG -c "pread -v 0 8K" $SCRATCH_MNT/foobar | _filter_xfs_io_offset + +echo "Step 3: writing with two failing mirrors (should fail):" +enable_io_failure $SCRATCH_DEV +enable_io_failure $dev2 +$XFS_IO_PROG -f -c "pwrite -W -S 0xbb 0 8K" $SCRATCH_MNT/foobar | _filter_xfs_io +disable_io_failure $dev2 +disable_io_failure $SCRATCH_DEV + +# disable block I/O error injection +echo 0 > $DEBUGFS_MNT/fail_make_request/probability +echo 0 > $DEBUGFS_MNT/fail_make_request/times + +_scratch_dev_pool_put +# success, all done +status=0 +exit
tests/btrfs/271.out new file +521 -0
521 lines not on this page · raw message
Signature · 1 line
2.30.2
Quoted 10 lines · Christoph Hellwig
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.
Hm. more below.
Quoted 14 lines
Signed-off-by Christoph Hellwig <[email protected]>--- common/inject | 33 +++++++++++++++++++++++++++++++++ tests/btrfs/088 | 24 +++++------------------- tests/btrfs/150 | 27 +++++---------------------- tests/generic/019 | 44 +++++++++----------------------------------- 4 files changed, 52 insertions(+), 76 deletions(-)common/inject +0
-0
common/inject _scratch_inject_error() · line 119
Quoted 10 lines
common/inject +6
-0@@ -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
Instead, can we do
printf %#x -1 > $DEBUGFS_MNT/fail_make_request/times
(as in the documentation).
<snip>
common/inject _require_fail_make_request · line 36
Quoted 13 lines
common/inject +0
-7@@ -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
Only extra line in btrfs/150 is the above line (or did I miss any)? Which is deleted in this patch.
Per 'task-filter' documentation
--------------
- /sys/kernel/debug/fail*/task-filter:
Format: { 'Y' | 'N' }
A value of 'N' disables filtering by process (default). Any positive value limits failures to only processes indicated by /proc/<pid>/make-it-fail==1.
--------------
<snip>
common/inject _require_fail_make_request
Quoted 8 lines
common/inject +2
-2- 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
So this won't work now.
Thanks, Anand
Quoted 3 lines · Anand Jain
tests/btrfs/150 _require_fail_make_request · line 34
Quoted 1 line
tests/btrfs/150 +0
-1- echo 1 > $DEBUGFS_MNT/fail_make_request/task-filterOnly extra line in btrfs/150 is the above line (or did I miss any)? Which is deleted in this patch.
Yes.
Quoted 10 lines
tests/btrfs/150 while [[ -z $result ]]; do
Quoted 8 lines
tests/btrfs/150 +2
-2- enable_io_failure - + _enable_fail_make_request + _start_fail_dev $SCRATCH_DEV result=$(bash -c " if [ \$((\$\$ % 2)) == 1 ]; then echo 1 > /proc/\$\$/make-it-failSo this won't work now.
Yes.