fstests: add _require_command check to killall
[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         $XFS_REPAIR_PROG $SCRATCH_DEV 2>&1 | tee -a $seqres.full > $tmp.repair &
60         repair_pid=$!
61
62         # monitor progress for as long as it is running
63         while [ `pgrep xfs_repair` ]; do
64                 grep "couldn't verify primary superblock" $tmp.repair \
65                         > /dev/null 2>&1
66                 if [ $? == 0 ]; then
67                         # we've started a brute force scan. kill repair and
68                         # fail the test
69                         kill -9 $repair_pid >> $seqres.full 2>&1
70                         wait >> $seqres.full 2>&1
71
72                         _fail "xfs_repair resorted to brute force scan"
73                 fi
74
75                 sleep 1
76         done
77
78         wait
79
80         cat $tmp.repair | _filter_repair
81 }
82
83 rm -f $seqres.full
84
85 # get standard environment, filters and checks
86 . ./common/rc
87 . ./common/filter
88 . ./common/repair
89
90 # real QA test starts here
91
92 # Modify as appropriate.
93 _supported_fs xfs
94 _supported_os Linux
95 _require_scratch_nocheck
96 _require_command "$KILLALL_PROG" killall
97
98 _scratch_mkfs | _filter_mkfs > /dev/null 2> $tmp.mkfs || _fail "mkfs failed"
99
100 . $tmp.mkfs # import agcount
101
102 # corrupt the last secondary sb in the fs
103 $XFS_DB_PROG -x -c "sb $((agcount - 1))" -c "type data" \
104         -c "write fill 0xff 0 512" $SCRATCH_DEV
105
106 # attempt to repair
107 _xfs_repair_noscan
108
109 # success, all done
110 status=0
111 exit