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.
9 # Commit 20a7db8ab3f2 ("btrfs: add dummy callback for readpage_io_failed
10 # and drop checks") introduced the regression.
13 # Commit 9d0d1c8b1c9d ("Btrfs: bring back repair during read")
16 _begin_fstest auto quick read_repair
18 # Import common functions.
21 # real QA test starts here
23 # Modify as appropriate.
25 _require_scratch_dev_pool 2
27 _require_btrfs_command inspect-internal dump-tree
33 $BTRFS_UTIL_PROG inspect-internal dump-tree -t 3 $SCRATCH_DEV | \
34 grep $logical -A 6 | \
35 $AWK_PROG "(\$1 ~ /stripe/ && \$3 ~ /devid/ && \$2 ~ /$stripe/) { print \$6 }"
42 $BTRFS_UTIL_PROG inspect-internal dump-tree -t 3 $SCRATCH_DEV | \
43 grep $logical -A 6 | \
44 $AWK_PROG "(\$1 ~ /stripe/ && \$3 ~ /devid/ && \$2 ~ /$stripe/) { print \$4 }"
50 echo "$SCRATCH_DEV_POOL" | $AWK_PROG "{print \$$devid}"
53 _scratch_dev_pool_get 2
54 # step 1, create a raid1 btrfs which contains one 128k file.
55 echo "step 1......mkfs.btrfs" >>$seqres.full
57 _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
58 mkfs_opts="-d raid1 -b 1G"
59 _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
61 # make sure data is written to the start position of the data chunk
62 _scratch_mount $(_btrfs_no_v1_cache_opt)
64 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
67 # step 2, corrupt the first 64k of one copy (on SCRATCH_DEV which is the first
68 # one in $SCRATCH_DEV_POOL
69 echo "step 2......corrupt file extent" >>$seqres.full
71 logical_in_btrfs=$(_btrfs_get_first_logical $SCRATCH_MNT/foobar)
72 physical=$(get_physical ${logical_in_btrfs} 1)
73 devid=$(get_devid ${logical_in_btrfs} 1)
74 devpath=$(get_device_path ${devid})
77 echo " corrupt stripe #1, devid $devid devpath $devpath physical $physical" \
79 $XFS_IO_PROG -d -c "pwrite -S 0xbb -b 64K $physical 64K" $devpath > /dev/null
83 # step 3, 128k buffered read (this read can repair bad copy)
84 echo "step 3......repair the bad copy" >>$seqres.full
86 _btrfs_buffered_read_on_mirror 1 2 "$SCRATCH_MNT/foobar" 0 128K
90 # check if the repair works
91 $XFS_IO_PROG -c "pread -v -b 512 $physical 512" $devpath |\