2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Liu Bo. All Rights Reserved.
7 # Regression test for btrfs buffered read's repair during read without checksum.
9 # This is to test whether buffered read retry-repair code is able to work in
10 # raid1 case as expected.
12 # Please note that without checksum, btrfs doesn't know if the data used to
13 # repair is correct, so repair is more of resync which makes sure that both
14 # of the copy has the same content.
16 # Commit 20a7db8ab3f2 ("btrfs: add dummy callback for readpage_io_failed and drop
17 # checks") introduced the regression.
20 # commit 9d0d1c8b1c9d ("Btrfs: bring back repair during read")
23 seqres=$RESULT_DIR/$seq
24 echo "QA output created by $seq"
28 status=1 # failure is the default!
29 trap "_cleanup; exit \$status" 0 1 2 3 15
37 # get standard environment, filters and checks
42 # remove previous $seqres.full before test
45 # real QA test starts here
47 # Modify as appropriate.
49 _require_scratch_dev_pool 2
50 _require_dm_target dust
52 _require_btrfs_command inspect-internal dump-tree
53 _require_command "$FILEFRAG_PROG" filefrag
55 _scratch_dev_pool_get 2
56 # step 1, create a raid1 btrfs which contains one 128k file.
57 echo "step 1......mkfs.btrfs" >>$seqres.full
59 mkfs_opts="-d raid1 -b 1G"
60 _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
62 # -o nospace_cache makes sure data is written to the start position of the data
64 _scratch_mount -o nospace_cache,nodatasum
66 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
69 # step 2, corrupt the first 64k of stripe #1
70 echo "step 2......corrupt file extent" >>$seqres.full
72 ${FILEFRAG_PROG} -v $SCRATCH_MNT/foobar >> $seqres.full
73 logical_in_btrfs=`${FILEFRAG_PROG} -v $SCRATCH_MNT/foobar | _filter_filefrag | cut -d '#' -f 1`
74 echo "Logical offset is $logical_in_btrfs" >>$seqres.full
77 read -r stripe physical < <(
78 $BTRFS_UTIL_PROG inspect-internal dump-tree -t 3 "$SCRATCH_DEV" |
79 grep "$logical_in_btrfs" -A 6 |
80 $AWK_PROG '$1 == "stripe" && $3 == "devid" && $4 == 1 { print $2 " " $6; exit }')
81 echo "Physical offset of stripe $stripe is $physical on devid 1" >> $seqres.full
83 $XFS_IO_PROG -d -c "pwrite -S 0xbb -b 64K $physical 64K" "$SCRATCH_DEV" > /dev/null
88 # step 3, 128k buffered read (this read can repair bad copy)
89 echo "step 3......repair the bad copy" >>$seqres.full
91 $DMSETUP_PROG message dust-test 0 addbadblock $((physical / 512))
92 $DMSETUP_PROG message dust-test 0 enable
93 while [[ -z $( (( BASHPID % 2 == stripe )) &&
94 exec $XFS_IO_PROG -c "pread -b 128K 0 128K" "$SCRATCH_MNT/foobar") ]]; do
100 # check if the repair works
101 $XFS_IO_PROG -c "pread -v -b 512 $physical 512" "$SCRATCH_DEV" |
102 _filter_xfs_io_offset
104 _scratch_dev_pool_put