xfstests: introduce a common directory
[xfstests-dev.git] / tests / xfs / 149
1 #! /bin/bash
2 # FS QA Test No. 149
3 #
4 # Exercise xfs_prepair - ensure repeated use doesn't corrupt
5 # This is a clone of test 031 using xfs_prepair instead of xfs_repair
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #
23 #-----------------------------------------------------------------------
24 #
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 seqres=$RESULT_DIR/$seq
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=1        # failure is the default!
35 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
36 rm -f $seqres.full
37
38 # get standard environment, filters and checks
39 . ./common/rc
40 . ./common/repair
41 . ./common/filter
42
43 [ -z "$XFS_PARALLEL_REPAIR_PROG" ] && _notrun "parallel repair binary xfs_prepair is not installed"
44
45 # force use of parallel repair
46 export XFS_REPAIR_PROG=$XFS_PARALLEL_REPAIR_PROG
47
48 _check_repair()
49 {
50         echo "Repairing, round 0" >> $seqres.full
51         _scratch_xfs_repair 2>&1 | _filter_repair | tee -a $seqres.full >$tmp.0
52         for i in 1 2 3 4
53         do
54                 echo "Repairing, iteration $i" | tee -a $seqres.full
55                 _scratch_xfs_repair 2>&1 | _filter_repair >$tmp.$i
56                 diff $tmp.0 $tmp.$i >> $seqres.full
57                 if [ $? -ne 0 ]; then
58                         echo "ERROR: repair round $i differs to round 0 (see $seqres.full)" | tee -a $seqres.full
59                         break
60                 fi
61                 # echo all interesting stuff...
62                 perl -ne '
63                         s/(rebuilding directory inode) (\d+)/\1 INO/g;
64                         s/internal log/<TYPEOF> log/g;
65                         s/external log on \S+/<TYPEOF> log/g;
66                         /^\S+/ && print;
67                 ' $tmp.$i
68         done
69         echo
70 }
71
72 # prototype file to create various directory forms
73 _create_proto()
74 {
75         total=$1
76         count=0
77
78         # take inode size into account for non-shortform directories...
79         [ $total -gt 0 ] && total=`expr $total \* $isize / 512`
80
81         cat >$tmp.proto <<EOF
82 DUMMY1
83 0 0
84 : root directory
85 d--777 3 1
86 lost+found d--755 3 1
87 $
88 EOF
89
90         while [ $count -lt $total ]
91         do
92                 let count=$count+1
93                 cat >>$tmp.proto <<EOF
94 ${count}_of_${total}_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ---755 3 1 /bin/true
95 EOF
96         done
97         echo '$' >>$tmp.proto
98 }
99
100 # real QA test starts here
101 _supported_fs xfs
102 _supported_os IRIX Linux
103
104 _require_scratch
105 _require_no_large_scratch_dev
106
107 # sanity test - default + one root directory entry
108 # Note: must do this proto/mkfs now for later inode size calcs
109 _create_proto 0
110 echo "=== one entry (shortform)"
111 _scratch_mkfs_xfs -p $tmp.proto >$tmp.mkfs0 2>&1
112 _filter_mkfs <$tmp.mkfs0 >/dev/null 2>$tmp.mkfs
113 . $tmp.mkfs
114 _check_repair
115
116 # block-form root directory & repeat
117 _create_proto 20
118 echo "=== twenty entries (block form)"
119 _scratch_mkfs_xfs -p $tmp.proto | _filter_mkfs >/dev/null 2>&1
120 _check_repair
121
122 # leaf-form root directory & repeat
123 _create_proto 1000
124 echo "=== thousand entries (leaf form)"
125 _scratch_mkfs_xfs -p $tmp.proto | _filter_mkfs >/dev/null 2>&1
126 _check_repair
127
128 # success, all done
129 status=0
130 exit