xfstests: randholes: encapsulate direct I/O setup code
[xfstests-dev.git] / 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 # creator
26 owner=ddiss@sgi.com
27
28 seq=`basename $0`
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
35 rm -f $seq.full
36
37 # get standard environment, filters and checks
38 . ./common.rc
39 . ./common.repair
40 . ./common.filter
41
42 [ -z "$XFS_PARALLEL_REPAIR_PROG" ] && _notrun "parallel repair binary xfs_prepair is not installed"
43
44 # force use of parallel repair
45 export XFS_REPAIR_PROG=$XFS_PARALLEL_REPAIR_PROG
46
47 _check_repair()
48 {
49         echo "Repairing, round 0" >> $seq.full
50         _scratch_xfs_repair 2>&1 | _filter_repair | tee -a $seq.full >$tmp.0
51         for i in 1 2 3 4
52         do
53                 echo "Repairing, iteration $i" | tee -a $seq.full
54                 _scratch_xfs_repair 2>&1 | _filter_repair >$tmp.$i
55                 diff $tmp.0 $tmp.$i >> $seq.full
56                 if [ $? -ne 0 ]; then
57                         echo "ERROR: repair round $i differs to round 0 (see $seq.full)" | tee -a $seq.full
58                         break
59                 fi
60                 # echo all interesting stuff...
61                 perl -ne '
62                         s/(rebuilding directory inode) (\d+)/\1 INO/g;
63                         s/internal log/<TYPEOF> log/g;
64                         s/external log on \S+/<TYPEOF> log/g;
65                         /^\S+/ && print;
66                 ' $tmp.$i
67         done
68         echo
69 }
70
71 # prototype file to create various directory forms
72 _create_proto()
73 {
74         total=$1
75         count=0
76
77         # take inode size into account for non-shortform directories...
78         [ $total -gt 0 ] && total=`expr $total \* $isize / 512`
79
80         cat >$tmp.proto <<EOF
81 DUMMY1
82 0 0
83 : root directory
84 d--777 3 1
85 lost+found d--755 3 1
86 $
87 EOF
88
89         while [ $count -lt $total ]
90         do
91                 let count=$count+1
92                 cat >>$tmp.proto <<EOF
93 ${count}_of_${total}_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ---755 3 1 /bin/true
94 EOF
95         done
96         echo '$' >>$tmp.proto
97 }
98
99 # real QA test starts here
100 _supported_fs xfs
101 _supported_os IRIX Linux
102
103 _require_nobigloopfs
104 _require_scratch
105
106 # sanity test - default + one root directory entry
107 # Note: must do this proto/mkfs now for later inode size calcs
108 _create_proto 0
109 echo "=== one entry (shortform)"
110 _scratch_mkfs_xfs -p $tmp.proto >$tmp.mkfs0 2>&1
111 _filter_mkfs <$tmp.mkfs0 >/dev/null 2>$tmp.mkfs
112 . $tmp.mkfs
113 _check_repair
114
115 # block-form root directory & repeat
116 _create_proto 20
117 echo "=== twenty entries (block form)"
118 _scratch_mkfs_xfs -p $tmp.proto | _filter_mkfs >/dev/null 2>&1
119 _check_repair
120
121 # leaf-form root directory & repeat
122 _create_proto 1000
123 echo "=== thousand entries (leaf form)"
124 _scratch_mkfs_xfs -p $tmp.proto | _filter_mkfs >/dev/null 2>&1
125 _check_repair
126
127 # success, all done
128 status=0
129 exit