Skip to contentSkip to conversation

btrfs: test raid1 write error handling

PATCH In review Christoph Hellwig 2 participants 2 messages Jul 2, 2022 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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
new file mode 100755
index 00000000..c21858d1
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Christoph Hellwig

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.

Thanks for the test case.

A nit is below.

Quoted 51 lines
---
  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 +37 -0
new file mode 100755
index 00000000..c21858d1
@@ -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

tests/btrfs/271 line 46

Quoted 10 lines
tests/btrfs/271 new file +9 -0
+
+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

Probability 100%, so fail all IO.

Quoted 1 line

+echo 1000 > $DEBUGFS_MNT/fail_make_request/times

For 1000 commands.

I hope I got it correct. You may consider adding a comment.

Quoted 32 lines
tests/btrfs/271 new file +31 -0
+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