fstests: move test group info to test files
[xfstests-dev.git] / tests / btrfs / 143
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Liu Bo.  All Rights Reserved.
4 #
5 # FS QA Test 143
6 #
7 # Regression test for btrfs buffered read's repair during read without checksum.
8 #
9 # This is to test whether buffered read retry-repair code is able to work in
10 # raid1 case as expected.
11 #
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.
15 #
16 # Commit 20a7db8ab3f2 ("btrfs: add dummy callback for readpage_io_failed and drop
17 # checks") introduced the regression.
18 #
19 # The upstream fix is
20 #       commit 9d0d1c8b1c9d ("Btrfs: bring back repair during read")
21 #
22 . ./common/preamble
23 _begin_fstest auto quick
24
25 # Import common functions.
26 . ./common/filter
27 . ./common/dmdust
28
29 # real QA test starts here
30
31 # Modify as appropriate.
32 _supported_fs btrfs
33 _require_scratch_dev_pool 2
34 _require_dm_target dust
35
36 _require_btrfs_command inspect-internal dump-tree
37 _require_command "$FILEFRAG_PROG" filefrag
38
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
42
43 mkfs_opts="-d raid1 -b 1G"
44 _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
45
46 # -o nospace_cache makes sure data is written to the start position of the data
47 # chunk
48 _scratch_mount -o nospace_cache,nodatasum
49
50 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
51         _filter_xfs_io_offset
52
53 # step 2, corrupt the first 64k of stripe #1
54 echo "step 2......corrupt file extent" >>$seqres.full
55
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
59 _scratch_unmount
60
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
66
67 $XFS_IO_PROG -d -c "pwrite -S 0xbb -b 64K $physical 64K" "$SCRATCH_DEV" > /dev/null
68
69 _init_dust
70 _mount_dust
71
72 # step 3, 128k buffered read (this read can repair bad copy)
73 echo "step 3......repair the bad copy" >>$seqres.full
74
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
79         :
80 done
81
82 _cleanup_dust
83
84 # check if the repair works
85 $XFS_IO_PROG -c "pread -v -b 512 $physical 512" "$SCRATCH_DEV" |
86         _filter_xfs_io_offset
87
88 _scratch_dev_pool_put
89 # success, all done
90 status=0
91 exit