Message ID | 20220520164743.4023665-2-hch@lst.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [1/2] btrfs: test repair with sectors corrupted in multiple mirrors | expand |
On Fri, May 20, 2022 at 06:47:42PM +0200, Christoph Hellwig wrote: > Test that repair handles the case where it needs to read from more than > a single mirror on the raid1c3 profile. > > Signed-off-by: Christoph Hellwig <hch@lst.de> > --- > tests/btrfs/265 | 127 ++++++++++++++++++++++++++++++++++++++++++++ > tests/btrfs/265.out | 75 ++++++++++++++++++++++++++ > 2 files changed, 202 insertions(+) > create mode 100755 tests/btrfs/265 > create mode 100644 tests/btrfs/265.out > > diff --git a/tests/btrfs/265 b/tests/btrfs/265 > new file mode 100755 > index 00000000..96f37989 > --- /dev/null > +++ b/tests/btrfs/265 > @@ -0,0 +1,127 @@ > +#! /bin/bash > +# SPDX-License-Identifier: GPL-2.0 > +# Copyright (c) 2017 Liu Bo. All Rights Reserved. > +# Copyright (c) 2022 Christoph Hellwig. > +# > +# FS QA Test 265 > +# > +# Test that btrfs raid repair on a raid1c3 profile can repair corruption on two > +# mirrors for the same logical offset. > +# > +. ./common/preamble > +_begin_fstest auto quick read_repair > + > +# Import common functions. > +. ./common/filter > + > +# real QA test starts here > + > +_supported_fs btrfs > +_require_scratch_dev_pool 3 > + > +BTRFS_MAP_LOGICAL_PROG=$(type -P btrfs-map-logical) Hi Christoph, Thanks for the new test cases. I'm not an btrfs expert, so I'll only give this patchset some review points from fstests side. Btrfs forks please feel free to review this patchset :) If btrfs-map-logical is a general command from btffs-progs, I think we can move above line into common/config. > + > +_require_command "$BTRFS_MAP_LOGICAL_PROG" btrfs-map-logical > +_require_command "$FILEFRAG_PROG" filefrag > +_require_odirect > +# Overwriting data is forbidden on a zoned block device > +_require_non_zoned_device "${SCRATCH_DEV}" > + > +get_physical() > +{ > + local logical=$1 > + local stripe=$2 > + > + $BTRFS_MAP_LOGICAL_PROG -l $logical $SCRATCH_DEV >> $seqres.full 2>&1 > + $BTRFS_MAP_LOGICAL_PROG -l $logical $SCRATCH_DEV | \ > + $AWK_PROG "(\$1 ~ /mirror/ && \$2 ~ /$stripe/) { print \$6 }" > +} > + > +get_device_path() > +{ > + local logical=$1 > + local stripe=$2 > + > + $BTRFS_MAP_LOGICAL_PROG -l $logical $SCRATCH_DEV | \ > + $AWK_PROG "(\$1 ~ /mirror/ && \$2 ~ /$stripe/) { print \$8 }" > +} > + > +_scratch_dev_pool_get 3 > +# step 1, create a raid1 btrfs which contains one 128k file. > +echo "step 1......mkfs.btrfs" > + > +mkfs_opts="-d raid1c3 -b 1G" > +_scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1 > + > +# make sure data is written to the start position of the data chunk > +_scratch_mount $(_btrfs_no_v1_cache_opt) > + > +$XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" \ > + "$SCRATCH_MNT/foobar" | \ > + _filter_xfs_io_offset > + > +# ensure btrfs-map-logical sees the tree updates > +sync > + > +# step 2, corrupt the first 64k of one copy (on SCRATCH_DEV which is the first > +# one in $SCRATCH_DEV_POOL > +echo "step 2......corrupt file extent" > + > +${FILEFRAG_PROG} -v $SCRATCH_MNT/foobar >> $seqres.full > +logical_in_btrfs=`${FILEFRAG_PROG} -v $SCRATCH_MNT/foobar | _filter_filefrag | cut -d '#' -f 1` > + > +physical1=$(get_physical ${logical_in_btrfs} 1) > +devpath1=$(get_device_path ${logical_in_btrfs} 1) > + > +physical2=$(get_physical ${logical_in_btrfs} 2) > +devpath2=$(get_device_path ${logical_in_btrfs} 2) I saw you do the same steps from "${FILEFRAG_PROG} -v $SCRATCH_MNT/foobar" to this line in 2 patches, so I'm wondering are the FILEFRAG_PROG lines and get_physical() and get_device_path() worth moving to common/btrfs (might need to change name), to make them get "device_path" or "physical" from a filename (e.g. $SCRATCH_MNT/foobar) argument? Thanks, Zorro > + > +_scratch_unmount > + > +echo " corrupt stripe #1, devpath $devpath1 physical $physical1" \ > + >> $seqres.full > +$XFS_IO_PROG -d -c "pwrite -S 0xbf -b 64K $physical1 64K" $devpath1 \ > + > /dev/null > + > +echo " corrupt stripe #2, devpath $devpath2 physical $physical2" \ > + >> $seqres.full > +$XFS_IO_PROG -d -c "pwrite -S 0xbf -b 64K $physical2 64K" $devpath2 \ > + > /dev/null > + > +_scratch_mount > + > +# step 3, 128k dio read (this read can repair bad copy) > +echo "step 3......repair the bad copy" > + > +# since raid1c3 consists of three copies, and the bad copy was put on stripe #1 > +# while the good copy lies the other stripes, the bad copy only gets accessed > +# when the reader's pid % 3 is 1 > +while true; do > + $XFS_IO_PROG -d -c "pread -b 128K 0 128K" "$SCRATCH_MNT/foobar" > /dev/null & > + pid=$! > + wait > + if [ $((pid % 3)) == 1 ]; then > + break > + fi > +done > +while true; do > + $XFS_IO_PROG -d -c "pread -b 128K 0 128K" "$SCRATCH_MNT/foobar" > /dev/null & > + pid=$! > + wait > + if [ $((pid % 3)) == 2 ]; then > + break > + fi > +done > + > +_scratch_unmount > + > +echo "step 4......check if the repair works" > +$XFS_IO_PROG -d -c "pread -v -b 512 $physical1 512" $devpath1 |\ > + _filter_xfs_io_offset > +$XFS_IO_PROG -d -c "pread -v -b 512 $physical2 512" $devpath2 |\ > + _filter_xfs_io_offset > + > +_scratch_dev_pool_put > +# success, all done > +status=0 > +exit > diff --git a/tests/btrfs/265.out b/tests/btrfs/265.out > new file mode 100644 > index 00000000..4d3e7f80 > --- /dev/null > +++ b/tests/btrfs/265.out > @@ -0,0 +1,75 @@ > +QA output created by 265 > +step 1......mkfs.btrfs > +wrote 131072/131072 bytes > +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) > +step 2......corrupt file extent > +step 3......repair the bad copy > +step 4......check if the repair works > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +read 512/512 bytes > +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +read 512/512 bytes > +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) > -- > 2.30.2 >
On 5/20/22 22:17, Christoph Hellwig wrote: > Test that repair handles the case where it needs to read from more than > a single mirror on the raid1c3 profile. > > Signed-off-by: Christoph Hellwig <hch@lst.de> Looks good. A few nits below. > --- > tests/btrfs/265 | 127 ++++++++++++++++++++++++++++++++++++++++++++ > tests/btrfs/265.out | 75 ++++++++++++++++++++++++++ > 2 files changed, 202 insertions(+) > create mode 100755 tests/btrfs/265 > create mode 100644 tests/btrfs/265.out > > diff --git a/tests/btrfs/265 b/tests/btrfs/265 > new file mode 100755 > index 00000000..96f37989 > --- /dev/null > +++ b/tests/btrfs/265 > @@ -0,0 +1,127 @@ > +#! /bin/bash > +# SPDX-License-Identifier: GPL-2.0 > +# Copyright (c) 2017 Liu Bo. All Rights Reserved. > +# Copyright (c) 2022 Christoph Hellwig. > +# > +# FS QA Test 265 > +# > +# Test that btrfs raid repair on a raid1c3 profile can repair corruption on two > +# mirrors for the same logical offset. > +# > +. ./common/preamble > +_begin_fstest auto quick read_repair > + > +# Import common functions. > +. ./common/filter > + > +# real QA test starts here > + > +_supported_fs btrfs > +_require_scratch_dev_pool 3 > + > +BTRFS_MAP_LOGICAL_PROG=$(type -P btrfs-map-logical) > + > +_require_command "$BTRFS_MAP_LOGICAL_PROG" btrfs-map-logical > +_require_command "$FILEFRAG_PROG" filefrag > +_require_odirect > +# Overwriting data is forbidden on a zoned block device > +_require_non_zoned_device "${SCRATCH_DEV}" > + > +get_physical() > +{ > + local logical=$1 > + local stripe=$2 > + > + $BTRFS_MAP_LOGICAL_PROG -l $logical $SCRATCH_DEV >> $seqres.full 2>&1 > + $BTRFS_MAP_LOGICAL_PROG -l $logical $SCRATCH_DEV | \ > + $AWK_PROG "(\$1 ~ /mirror/ && \$2 ~ /$stripe/) { print \$6 }" > +} > + > +get_device_path() > +{ > + local logical=$1 > + local stripe=$2 > + > + $BTRFS_MAP_LOGICAL_PROG -l $logical $SCRATCH_DEV | \ > + $AWK_PROG "(\$1 ~ /mirror/ && \$2 ~ /$stripe/) { print \$8 }" > +} > + 4-5 more test cases use these functions. Why not bring them to common/btrfs. > +_scratch_dev_pool_get 3 > +# step 1, create a raid1 btrfs which contains one 128k file. > +echo "step 1......mkfs.btrfs" > + > +mkfs_opts="-d raid1c3 -b 1G" > +_scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1 > + > +# make sure data is written to the start position of the data chunk > +_scratch_mount $(_btrfs_no_v1_cache_opt) > + > +$XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" \ > + "$SCRATCH_MNT/foobar" | \ > + _filter_xfs_io_offset > + > +# ensure btrfs-map-logical sees the tree updates > +sync > + > +# step 2, corrupt the first 64k of one copy (on SCRATCH_DEV which is the first > +# one in $SCRATCH_DEV_POOL > +echo "step 2......corrupt file extent" > + > +${FILEFRAG_PROG} -v $SCRATCH_MNT/foobar >> $seqres.full > +logical_in_btrfs=`${FILEFRAG_PROG} -v $SCRATCH_MNT/foobar | _filter_filefrag | cut -d '#' -f 1` > + > +physical1=$(get_physical ${logical_in_btrfs} 1) > +devpath1=$(get_device_path ${logical_in_btrfs} 1) > + > +physical2=$(get_physical ${logical_in_btrfs} 2) > +devpath2=$(get_device_path ${logical_in_btrfs} 2) > + > +_scratch_unmount > + > +echo " corrupt stripe #1, devpath $devpath1 physical $physical1" \ > + >> $seqres.full > +$XFS_IO_PROG -d -c "pwrite -S 0xbf -b 64K $physical1 64K" $devpath1 \ > + > /dev/null > + > +echo " corrupt stripe #2, devpath $devpath2 physical $physical2" \ > + >> $seqres.full > +$XFS_IO_PROG -d -c "pwrite -S 0xbf -b 64K $physical2 64K" $devpath2 \ > + > /dev/null > + > +_scratch_mount > + > +# step 3, 128k dio read (this read can repair bad copy) > +echo "step 3......repair the bad copy" > + > +# since raid1c3 consists of three copies, and the bad copy was put on stripe #1 > +# while the good copy lies the other stripes, the bad copy only gets accessed > +# when the reader's pid % 3 is 1 > +while true; do > + $XFS_IO_PROG -d -c "pread -b 128K 0 128K" "$SCRATCH_MNT/foobar" > /dev/null & > + pid=$! > + wait > + if [ $((pid % 3)) == 1 ]; then > + break > + fi > +done > +while true; do > + $XFS_IO_PROG -d -c "pread -b 128K 0 128K" "$SCRATCH_MNT/foobar" > /dev/null & > + pid=$! > + wait > + if [ $((pid % 3)) == 2 ]; then > + break > + fi > +done More test cases use the same logic. They can wrap into a helper. Thanks, Anand > + > +_scratch_unmount > + > +echo "step 4......check if the repair works" > +$XFS_IO_PROG -d -c "pread -v -b 512 $physical1 512" $devpath1 |\ > + _filter_xfs_io_offset > +$XFS_IO_PROG -d -c "pread -v -b 512 $physical2 512" $devpath2 |\ > + _filter_xfs_io_offset > + > +_scratch_dev_pool_put > +# success, all done > +status=0 > +exit > diff --git a/tests/btrfs/265.out b/tests/btrfs/265.out > new file mode 100644 > index 00000000..4d3e7f80 > --- /dev/null > +++ b/tests/btrfs/265.out > @@ -0,0 +1,75 @@ > +QA output created by 265 > +step 1......mkfs.btrfs > +wrote 131072/131072 bytes > +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) > +step 2......corrupt file extent > +step 3......repair the bad copy > +step 4......check if the repair works > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +read 512/512 bytes > +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ > +read 512/512 bytes > +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
diff --git a/tests/btrfs/265 b/tests/btrfs/265 new file mode 100755 index 00000000..96f37989 --- /dev/null +++ b/tests/btrfs/265 @@ -0,0 +1,127 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2017 Liu Bo. All Rights Reserved. +# Copyright (c) 2022 Christoph Hellwig. +# +# FS QA Test 265 +# +# Test that btrfs raid repair on a raid1c3 profile can repair corruption on two +# mirrors for the same logical offset. +# +. ./common/preamble +_begin_fstest auto quick read_repair + +# Import common functions. +. ./common/filter + +# real QA test starts here + +_supported_fs btrfs +_require_scratch_dev_pool 3 + +BTRFS_MAP_LOGICAL_PROG=$(type -P btrfs-map-logical) + +_require_command "$BTRFS_MAP_LOGICAL_PROG" btrfs-map-logical +_require_command "$FILEFRAG_PROG" filefrag +_require_odirect +# Overwriting data is forbidden on a zoned block device +_require_non_zoned_device "${SCRATCH_DEV}" + +get_physical() +{ + local logical=$1 + local stripe=$2 + + $BTRFS_MAP_LOGICAL_PROG -l $logical $SCRATCH_DEV >> $seqres.full 2>&1 + $BTRFS_MAP_LOGICAL_PROG -l $logical $SCRATCH_DEV | \ + $AWK_PROG "(\$1 ~ /mirror/ && \$2 ~ /$stripe/) { print \$6 }" +} + +get_device_path() +{ + local logical=$1 + local stripe=$2 + + $BTRFS_MAP_LOGICAL_PROG -l $logical $SCRATCH_DEV | \ + $AWK_PROG "(\$1 ~ /mirror/ && \$2 ~ /$stripe/) { print \$8 }" +} + +_scratch_dev_pool_get 3 +# step 1, create a raid1 btrfs which contains one 128k file. +echo "step 1......mkfs.btrfs" + +mkfs_opts="-d raid1c3 -b 1G" +_scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1 + +# make sure data is written to the start position of the data chunk +_scratch_mount $(_btrfs_no_v1_cache_opt) + +$XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" \ + "$SCRATCH_MNT/foobar" | \ + _filter_xfs_io_offset + +# ensure btrfs-map-logical sees the tree updates +sync + +# step 2, corrupt the first 64k of one copy (on SCRATCH_DEV which is the first +# one in $SCRATCH_DEV_POOL +echo "step 2......corrupt file extent" + +${FILEFRAG_PROG} -v $SCRATCH_MNT/foobar >> $seqres.full +logical_in_btrfs=`${FILEFRAG_PROG} -v $SCRATCH_MNT/foobar | _filter_filefrag | cut -d '#' -f 1` + +physical1=$(get_physical ${logical_in_btrfs} 1) +devpath1=$(get_device_path ${logical_in_btrfs} 1) + +physical2=$(get_physical ${logical_in_btrfs} 2) +devpath2=$(get_device_path ${logical_in_btrfs} 2) + +_scratch_unmount + +echo " corrupt stripe #1, devpath $devpath1 physical $physical1" \ + >> $seqres.full +$XFS_IO_PROG -d -c "pwrite -S 0xbf -b 64K $physical1 64K" $devpath1 \ + > /dev/null + +echo " corrupt stripe #2, devpath $devpath2 physical $physical2" \ + >> $seqres.full +$XFS_IO_PROG -d -c "pwrite -S 0xbf -b 64K $physical2 64K" $devpath2 \ + > /dev/null + +_scratch_mount + +# step 3, 128k dio read (this read can repair bad copy) +echo "step 3......repair the bad copy" + +# since raid1c3 consists of three copies, and the bad copy was put on stripe #1 +# while the good copy lies the other stripes, the bad copy only gets accessed +# when the reader's pid % 3 is 1 +while true; do + $XFS_IO_PROG -d -c "pread -b 128K 0 128K" "$SCRATCH_MNT/foobar" > /dev/null & + pid=$! + wait + if [ $((pid % 3)) == 1 ]; then + break + fi +done +while true; do + $XFS_IO_PROG -d -c "pread -b 128K 0 128K" "$SCRATCH_MNT/foobar" > /dev/null & + pid=$! + wait + if [ $((pid % 3)) == 2 ]; then + break + fi +done + +_scratch_unmount + +echo "step 4......check if the repair works" +$XFS_IO_PROG -d -c "pread -v -b 512 $physical1 512" $devpath1 |\ + _filter_xfs_io_offset +$XFS_IO_PROG -d -c "pread -v -b 512 $physical2 512" $devpath2 |\ + _filter_xfs_io_offset + +_scratch_dev_pool_put +# success, all done +status=0 +exit diff --git a/tests/btrfs/265.out b/tests/btrfs/265.out new file mode 100644 index 00000000..4d3e7f80 --- /dev/null +++ b/tests/btrfs/265.out @@ -0,0 +1,75 @@ +QA output created by 265 +step 1......mkfs.btrfs +wrote 131072/131072 bytes +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +step 2......corrupt file extent +step 3......repair the bad copy +step 4......check if the repair works +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +read 512/512 bytes +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................ +read 512/512 bytes +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
Test that repair handles the case where it needs to read from more than a single mirror on the raid1c3 profile. Signed-off-by: Christoph Hellwig <hch@lst.de> --- tests/btrfs/265 | 127 ++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/265.out | 75 ++++++++++++++++++++++++++ 2 files changed, 202 insertions(+) create mode 100755 tests/btrfs/265 create mode 100644 tests/btrfs/265.out