2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Red Hat, Inc. All Rights Reserved.
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.
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.
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.
22 seqres=$RESULT_DIR/$seq
23 echo "QA output created by $seq"
27 status=1 # failure is the default!
28 trap "_cleanup; exit \$status" 0 1 2 3 15
34 $KILLALL_PROG -9 $XFS_REPAIR_PROG > /dev/null 2>&1
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.
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 &
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 \
57 # we've started a brute force scan. kill repair and
59 kill -9 $repair_pid >> $seqres.full 2>&1
60 wait >> $seqres.full 2>&1
62 _fail "xfs_repair resorted to brute force scan"
70 cat $tmp.repair | _filter_repair
75 # get standard environment, filters and checks
80 # real QA test starts here
82 # Modify as appropriate.
84 _require_scratch_nocheck
85 _require_command "$KILLALL_PROG" killall
87 _scratch_mkfs | _filter_mkfs > /dev/null 2> $tmp.mkfs || _fail "mkfs failed"
89 . $tmp.mkfs # import agcount
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"