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 _begin_fstest auto quick
25 # Import common functions.
29 # real QA test starts here
31 # Modify as appropriate.
33 _require_scratch_dev_pool 2
34 _require_dm_target dust
36 _require_btrfs_command inspect-internal dump-tree
37 _require_command "$FILEFRAG_PROG" filefrag
39 _scratch_dev_pool_get 2
40 # step 1, create a raid1 btrfs which contains one 128k file.
41 echo "step 1......mkfs.btrfs" >>$seqres.full
43 mkfs_opts="-d raid1 -b 1G"
44 _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
46 # -o nospace_cache makes sure data is written to the start position of the data
48 _scratch_mount -o nospace_cache,nodatasum
50 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
53 # step 2, corrupt the first 64k of stripe #1
54 echo "step 2......corrupt file extent" >>$seqres.full
56 ${FILEFRAG_PROG} -v $SCRATCH_MNT/foobar >> $seqres.full
57 logical_in_btrfs=`${FILEFRAG_PROG} -v $SCRATCH_MNT/foobar | _filter_filefrag | cut -d '#' -f 1`
58 echo "Logical offset is $logical_in_btrfs" >>$seqres.full
61 read -r stripe physical < <(
62 $BTRFS_UTIL_PROG inspect-internal dump-tree -t 3 "$SCRATCH_DEV" |
63 grep "$logical_in_btrfs" -A 6 |
64 $AWK_PROG '$1 == "stripe" && $3 == "devid" && $4 == 1 { print $2 " " $6; exit }')
65 echo "Physical offset of stripe $stripe is $physical on devid 1" >> $seqres.full
67 $XFS_IO_PROG -d -c "pwrite -S 0xbb -b 64K $physical 64K" "$SCRATCH_DEV" > /dev/null
72 # step 3, 128k buffered read (this read can repair bad copy)
73 echo "step 3......repair the bad copy" >>$seqres.full
75 $DMSETUP_PROG message dust-test 0 addbadblock $((physical / 512))
76 $DMSETUP_PROG message dust-test 0 enable
77 while [[ -z $( (( BASHPID % 2 == stripe )) &&
78 exec $XFS_IO_PROG -c "pread -b 128K 0 128K" "$SCRATCH_MNT/foobar") ]]; do
84 # check if the repair works
85 $XFS_IO_PROG -c "pread -v -b 512 $physical 512" "$SCRATCH_DEV" |