xfs/realtime: Fix direct invocations of xfs_repair
[xfstests-dev.git] / tests / xfs / 070
1 #! /bin/bash
2 # FS QA Test No. 070
3 #
4 # As part of superblock verification, xfs_repair checks the primary sb and
5 # verifies all secondary sb's against the primary. In the event of geometry
6 # inconsistency, repair uses a heuristic that tracks the most frequently
7 # occurring settings across the set of N (agcount) superblocks.
8 #
9 # xfs_repair was subject to a bug that disregards this heuristic in the event
10 # that the last secondary superblock in the fs is corrupt. The side effect is an
11 # unnecessary and potentially time consuming brute force superblock scan.
12 #
13 # This is a regression test for the aforementioned xfs_repair bug. We
14 # intentionally corrupt the last superblock in the fs, run xfs_repair and
15 # verify it repairs the fs correctly. We explicitly detect a brute force scan
16 # and abort the repair to save time in the failure case.
17 #
18 #-----------------------------------------------------------------------
19 # Copyright (c) 2015 Red Hat, Inc. All Rights Reserved.
20 #
21 # This program is free software; you can redistribute it and/or
22 # modify it under the terms of the GNU General Public License as
23 # published by the Free Software Foundation.
24 #
25 # This program is distributed in the hope that it would be useful,
26 # but WITHOUT ANY WARRANTY; without even the implied warranty of
27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28 # GNU General Public License for more details.
29 #
30 # You should have received a copy of the GNU General Public License
31 # along with this program; if not, write the Free Software Foundation,
32 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
33 #-----------------------------------------------------------------------
34 #
35
36 seq=`basename $0`
37 seqres=$RESULT_DIR/$seq
38 echo "QA output created by $seq"
39
40 here=`pwd`
41 tmp=/tmp/$$
42 status=1        # failure is the default!
43 trap "_cleanup; exit \$status" 0 1 2 3 15
44
45 _cleanup()
46 {
47         cd /
48         rm -f $tmp.*
49         $KILLALL_PROG -9 $XFS_REPAIR_PROG > /dev/null 2>&1
50         wait > /dev/null 2>&1
51 }
52
53 # Start and monitor an xfs_repair of the scratch device. This test can induce a
54 # time consuming brute force superblock scan. Since a brute force scan means
55 # test failure, detect it and end the repair.
56 _xfs_repair_noscan()
57 {
58         # invoke repair directly so we can kill the process if need be
59         [ "$USE_EXTERNAL" = yes ] && [ -n "$SCRATCH_RTDEV" ] && \
60                 rt_repair_opts="-r $SCRATCH_RTDEV"
61         $XFS_REPAIR_PROG $rt_repair_opts $SCRATCH_DEV 2>&1 |
62                 tee -a $seqres.full > $tmp.repair &
63         repair_pid=$!
64
65         # monitor progress for as long as it is running
66         while [ `pgrep xfs_repair` ]; do
67                 grep "couldn't verify primary superblock" $tmp.repair \
68                         > /dev/null 2>&1
69                 if [ $? == 0 ]; then
70                         # we've started a brute force scan. kill repair and
71                         # fail the test
72                         kill -9 $repair_pid >> $seqres.full 2>&1
73                         wait >> $seqres.full 2>&1
74
75                         _fail "xfs_repair resorted to brute force scan"
76                 fi
77
78                 sleep 1
79         done
80
81         wait
82
83         cat $tmp.repair | _filter_repair
84 }
85
86 rm -f $seqres.full
87
88 # get standard environment, filters and checks
89 . ./common/rc
90 . ./common/filter
91 . ./common/repair
92
93 # real QA test starts here
94
95 # Modify as appropriate.
96 _supported_fs xfs
97 _supported_os Linux
98 _require_scratch_nocheck
99 _require_command "$KILLALL_PROG" killall
100
101 _scratch_mkfs | _filter_mkfs > /dev/null 2> $tmp.mkfs || _fail "mkfs failed"
102
103 . $tmp.mkfs # import agcount
104
105 # corrupt the last secondary sb in the fs
106 _scratch_xfs_db -x -c "sb $((agcount - 1))" -c "type data" \
107         -c "write fill 0xff 0 512"
108
109 # attempt to repair
110 _xfs_repair_noscan
111
112 # success, all done
113 status=0
114 exit