xfs/029: filter out "extended-header: cycle: 1" from output
[xfstests-dev.git] / tests / xfs / 070
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Red Hat, Inc. All Rights Reserved.
4 #
5 # FS QA Test No. 070
6 #
7 # As part of superblock verification, xfs_repair checks the primary sb and
8 # verifies all secondary sb's against the primary. In the event of geometry
9 # inconsistency, repair uses a heuristic that tracks the most frequently
10 # occurring settings across the set of N (agcount) superblocks.
11 #
12 # xfs_repair was subject to a bug that disregards this heuristic in the event
13 # that the last secondary superblock in the fs is corrupt. The side effect is an
14 # unnecessary and potentially time consuming brute force superblock scan.
15 #
16 # This is a regression test for the aforementioned xfs_repair bug. We
17 # intentionally corrupt the last superblock in the fs, run xfs_repair and
18 # verify it repairs the fs correctly. We explicitly detect a brute force scan
19 # and abort the repair to save time in the failure case.
20 #
21 seq=`basename $0`
22 seqres=$RESULT_DIR/$seq
23 echo "QA output created by $seq"
24
25 here=`pwd`
26 tmp=/tmp/$$
27 status=1        # failure is the default!
28 trap "_cleanup; exit \$status" 0 1 2 3 15
29
30 _cleanup()
31 {
32         cd /
33         rm -f $tmp.*
34         $KILLALL_PROG -9 $XFS_REPAIR_PROG > /dev/null 2>&1
35         wait > /dev/null 2>&1
36 }
37
38 # Start and monitor an xfs_repair of the scratch device. This test can induce a
39 # time consuming brute force superblock scan. Since a brute force scan means
40 # test failure, detect it and end the repair.
41 _xfs_repair_noscan()
42 {
43         # invoke repair directly so we can kill the process if need be
44         [ "$USE_EXTERNAL" = yes ] && [ -n "$SCRATCH_RTDEV" ] && \
45                 rt_repair_opts="-r $SCRATCH_RTDEV"
46         $XFS_REPAIR_PROG $rt_repair_opts $SCRATCH_DEV 2>&1 |
47                 tee -a $seqres.full > $tmp.repair &
48         repair_pid=$!
49
50         # monitor progress for as long as it is running
51         while [ `pgrep xfs_repair` ]; do
52                 grep "couldn't verify primary superblock" $tmp.repair \
53                         > /dev/null 2>&1
54                 if [ $? == 0 ]; then
55                         # we've started a brute force scan. kill repair and
56                         # fail the test
57                         kill -9 $repair_pid >> $seqres.full 2>&1
58                         wait >> $seqres.full 2>&1
59
60                         _fail "xfs_repair resorted to brute force scan"
61                 fi
62
63                 sleep 1
64         done
65
66         wait
67
68         cat $tmp.repair | _filter_repair
69 }
70
71 rm -f $seqres.full
72
73 # get standard environment, filters and checks
74 . ./common/rc
75 . ./common/filter
76 . ./common/repair
77
78 # real QA test starts here
79
80 # Modify as appropriate.
81 _supported_fs xfs
82 _supported_os Linux
83 _require_scratch_nocheck
84 _require_command "$KILLALL_PROG" killall
85
86 _scratch_mkfs | _filter_mkfs > /dev/null 2> $tmp.mkfs || _fail "mkfs failed"
87
88 . $tmp.mkfs # import agcount
89
90 # corrupt the last secondary sb in the fs
91 _scratch_xfs_db -x -c "sb $((agcount - 1))" -c "type data" \
92         -c "write fill 0xff 0 512"
93
94 # attempt to repair
95 _xfs_repair_noscan
96
97 # success, all done
98 status=0
99 exit