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.
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.
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.
18 #-----------------------------------------------------------------------
19 # Copyright (c) 2015 Red Hat, Inc. All Rights Reserved.
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.
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.
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 #-----------------------------------------------------------------------
37 seqres=$RESULT_DIR/$seq
38 echo "QA output created by $seq"
42 status=1 # failure is the default!
43 trap "_cleanup; exit \$status" 0 1 2 3 15
49 $KILLALL_PROG -9 $XFS_REPAIR_PROG > /dev/null 2>&1
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.
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 &
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 \
67 # we've started a brute force scan. kill repair and
69 kill -9 $repair_pid >> $seqres.full 2>&1
70 wait >> $seqres.full 2>&1
72 _fail "xfs_repair resorted to brute force scan"
80 cat $tmp.repair | _filter_repair
85 # get standard environment, filters and checks
90 # real QA test starts here
92 # Modify as appropriate.
95 _require_scratch_nocheck
96 _require_command "$KILLALL_PROG" killall
98 _scratch_mkfs | _filter_mkfs > /dev/null 2> $tmp.mkfs || _fail "mkfs failed"
100 . $tmp.mkfs # import agcount
102 # corrupt the last secondary sb in the fs
103 _scratch_xfs_db -x -c "sb $((agcount - 1))" -c "type data" \
104 -c "write fill 0xff 0 512"