10854c8aa7f3058391aa47f55c7f2fa3c0e0041b
[xfstests-dev.git] / tests / xfs / 030
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 030
6 #
7 # exercise xfs_repair repairing broken filesystems
8 #
9 seqfull=$0
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17
18 _cleanup()
19 {
20         cd /
21         _scratch_unmount 2>/dev/null
22         rm -f $tmp.*
23 }
24
25 trap "_cleanup; exit \$status" 0 1 2 3 15
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30 . ./common/repair
31 . ./common/quota
32
33 # nuke the superblock, AGI, AGF, AGFL; then try repair the damage
34 #
35 _check_ag()
36 {
37         for structure in 'sb 0' 'agf 0' 'agi 0' 'agfl 0'
38         do
39                 echo "Corrupting $structure - setting bits to $1"
40                 _check_repair $1 "$structure" | uniq |
41                         sed -e '/^error following ag 0 unlinked list$/d' \
42                             -e '/^bad agbno AGBNO for finobt/d' \
43                             -e '/^bad agbno AGBNO for rmapbt/d' \
44                             -e '/^bad agbno AGBNO for refcntbt/d' \
45                             -e '/^Missing reverse-mapping record.*/d' \
46                             -e '/^unknown block state, ag AGNO, block.*/d'
47         done
48 }
49
50 # real QA test starts here
51 _supported_fs xfs
52 _supported_os Linux
53
54 _require_scratch
55 _require_no_large_scratch_dev
56
57 DSIZE="-dsize=100m,agcount=6"
58
59 # first we need to ensure there are no bogus secondary
60 # superblocks between the primary and first secondary
61 # superblock (hanging around from earlier tests)...
62 #
63
64 _scratch_mkfs_xfs $DSIZE >/dev/null 2>&1
65 if [ $? -ne 0 ]         # probably don't have a big enough scratch
66 then
67         _notrun "SCRATCH_DEV too small, results would be non-deterministic"
68 else
69         _qmount_option noquota
70         _scratch_mount
71         src/feature -U $SCRATCH_DEV && \
72                 _notrun "UQuota are enabled, test needs controlled sb recovery"
73         src/feature -G $SCRATCH_DEV && \
74                 _notrun "GQuota are enabled, test needs controlled sb recovery"
75         src/feature -P $SCRATCH_DEV && \
76                 _notrun "PQuota are enabled, test needs controlled sb recovery"
77         _scratch_unmount
78 fi
79 clear=""
80 eval `xfs_db -r -c "sb 1" -c stack $SCRATCH_DEV | perl -ne '
81         if (/byte offset (\d+), length (\d+)/) {
82                 print "clear=", $1 / 512, "\n"; exit
83         }'`
84 [ -z "$clear" ] && echo "Cannot calculate length to clear"
85 src/devzero -v -1 -n "$clear" $SCRATCH_DEV >/dev/null
86
87 # now kick off the real repair test...
88 #
89 _scratch_mkfs_xfs $DSIZE | _filter_mkfs 2>$tmp.mkfs
90 . $tmp.mkfs
91 _check_ag 0
92 _check_ag -1
93
94 # success, all done
95 status=0
96 exit