xfs: fix old fuzz test invocations of xfs_repair
[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 -a ! -z "$SCRATCH_LOGDEV" ] && \
45                 log_repair_opts="-l $SCRATCH_LOGDEV"
46         [ "$USE_EXTERNAL" = yes ] && [ -n "$SCRATCH_RTDEV" ] && \
47                 rt_repair_opts="-r $SCRATCH_RTDEV"
48         $XFS_REPAIR_PROG $log_repair_opts $rt_repair_opts $SCRATCH_DEV 2>&1 |
49                 tee -a $seqres.full > $tmp.repair &
50         repair_pid=$!
51
52         # monitor progress for as long as it is running
53         while [ `pgrep xfs_repair` ]; do
54                 grep "couldn't verify primary superblock" $tmp.repair \
55                         > /dev/null 2>&1
56                 if [ $? == 0 ]; then
57                         # we've started a brute force scan. kill repair and
58                         # fail the test
59                         kill -9 $repair_pid >> $seqres.full 2>&1
60                         wait >> $seqres.full 2>&1
61
62                         _fail "xfs_repair resorted to brute force scan"
63                 fi
64
65                 sleep 1
66         done
67
68         wait
69
70         cat $tmp.repair | _filter_repair
71 }
72
73 rm -f $seqres.full
74
75 # get standard environment, filters and checks
76 . ./common/rc
77 . ./common/filter
78 . ./common/repair
79
80 # real QA test starts here
81
82 # Modify as appropriate.
83 _supported_fs xfs
84 _require_scratch_nocheck
85 _require_command "$KILLALL_PROG" killall
86
87 _scratch_mkfs | _filter_mkfs > /dev/null 2> $tmp.mkfs || _fail "mkfs failed"
88
89 . $tmp.mkfs # import agcount
90
91 # corrupt the last secondary sb in the fs
92 _scratch_xfs_db -x -c "sb $((agcount - 1))" -c "type data" \
93         -c "write fill 0xff 0 512"
94
95 # attempt to repair
96 _xfs_repair_noscan
97
98 # success, all done
99 status=0
100 exit