btrfs/079: fix failure to umount scratch fs due to running filefrag process
[xfstests-dev.git] / tests / btrfs / 157
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test 157
6 #
7 # The test case is to reproduce a bug in raid6 reconstruction process that
8 # would end up with read failure if there is data corruption on two disks in
9 # the same horizontal stripe, e.g.  due to bitrot.
10 #
11 # The bug happens when
12 # a) all disks are good to read,
13 # b) there is corrupted data on two disks in the same horizontal stripe due to
14 # something like bitrot,
15 # c) when rebuilding data after crc fails, btrfs is not able to tell whether
16 # other copies are good or corrupted because btrfs doesn't have crc for
17 # unallocated blocks.
18 #
19 # The kernel fixes are
20 # Btrfs: do not merge rbios if their fail stripe index are not identical
21 # Btrfs: make raid6 rebuild retry more
22 #
23 seq=`basename $0`
24 seqres=$RESULT_DIR/$seq
25 echo "QA output created by $seq"
26
27 here=`pwd`
28 tmp=/tmp/$$
29 status=1        # failure is the default!
30 trap "_cleanup; exit \$status" 0 1 2 3 15
31
32 _cleanup()
33 {
34         cd /
35         rm -f $tmp.*
36 }
37
38 # get standard environment, filters and checks
39 . ./common/rc
40 . ./common/filter
41
42 # remove previous $seqres.full before test
43 rm -f $seqres.full
44
45 # real QA test starts here
46
47 # Modify as appropriate.
48 _supported_fs btrfs
49 _supported_os Linux
50 _require_scratch_dev_pool 4
51 _require_btrfs_command inspect-internal dump-tree
52 _require_btrfs_fs_feature raid56
53
54 get_physical_stripe0()
55 {
56         $BTRFS_UTIL_PROG inspect-internal dump-tree -t 3 $SCRATCH_DEV | \
57         grep " DATA\|RAID6" -A 10 | \
58         $AWK_PROG '($1 ~ /stripe/ && $3 ~ /devid/ && $2 ~ /0/) { print $6 }'
59 }
60
61 get_physical_stripe1()
62 {
63         $BTRFS_UTIL_PROG inspect-internal dump-tree -t 3 $SCRATCH_DEV | \
64         grep " DATA\|RAID6" -A 10 | \
65         $AWK_PROG '($1 ~ /stripe/ && $3 ~ /devid/ && $2 ~ /1/) { print $6 }'
66 }
67
68 _scratch_dev_pool_get 4
69 # step 1: create a raid6 btrfs and create a 4K file
70 echo "step 1......mkfs.btrfs" >>$seqres.full
71
72 mkfs_opts="-d raid6 -b 1G"
73 _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
74
75 # -o nospace_cache makes sure data is written to the start position of the data
76 # chunk
77 _scratch_mount -o nospace_cache
78
79 # [0,64K) is written to stripe 0 and [64K, 128K) is written to stripe 1
80 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa 0 128K" -c "fsync" \
81         "$SCRATCH_MNT/foobar" | _filter_xfs_io
82
83 _scratch_unmount
84
85 stripe_0=`get_physical_stripe0`
86 stripe_1=`get_physical_stripe1`
87 dev4=`echo $SCRATCH_DEV_POOL | awk '{print $4}'`
88 dev3=`echo $SCRATCH_DEV_POOL | awk '{print $3}'`
89
90 # step 2: corrupt the 1st and 2nd stripe (stripe 0 and 1)
91 echo "step 2......simulate bitrot at offset $stripe_0 of device_4($dev4) and offset $stripe_1 of device_3($dev3)" >>$seqres.full
92
93 $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $stripe_0 64K" $dev4 | _filter_xfs_io
94 $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $stripe_1 64K" $dev3 | _filter_xfs_io
95
96 # step 3: read foobar to repair the bitrot
97 echo "step 3......repair the bitrot" >> $seqres.full
98 _scratch_mount -o nospace_cache
99
100 # read the 2nd stripe, i.e. [64K, 128K), to trigger repair
101 od -x -j 64K $SCRATCH_MNT/foobar
102
103 _scratch_dev_pool_put
104
105 # success, all done
106 status=0
107 exit