add a couple of dmapi headers to the set we cross check for consistency.
[xfstests-dev.git] / 042
1 #! /bin/sh
2 # XFS QA Test No. 042
3 # $Id: 042,v 1.2 2000/09/27 00:24:22 ajag Exp ajag $
4 #
5 # fsr.xfs QA tests
6 # create a large fragmented file and check that fsr.xfs doesn't corrupt
7 # it or the other contents of the filesystem
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
11
12 # This program is free software; you can redistribute it and/or modify it
13 # under the terms of version 2 of the GNU General Public License as
14 # published by the Free Software Foundation.
15
16 # This program is distributed in the hope that it would be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19
20 # Further, this software is distributed without any warranty that it is
21 # free of the rightful claim of any third person regarding infringement
22 # or the like.  Any license provided herein, whether implied or
23 # otherwise, applies only to this software file.  Patent licenses, if
24 # any, provided herein do not apply to combinations of this program with
25 # other software, or any other product whatsoever.
26
27 # You should have received a copy of the GNU General Public License along
28 # with this program; if not, write the Free Software Foundation, Inc., 59
29 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
30
31 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
32 # Mountain View, CA  94043, or:
33
34 # http://www.sgi.com 
35
36 # For further information regarding this notice, see: 
37
38 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
39 #-----------------------------------------------------------------------
40 #
41 set +x
42 # creator
43 owner=ajag@melbourne.sgi.com
44
45 seq=`basename $0`
46 echo "QA output created by $seq"
47
48 here=`pwd`
49 tmp=/tmp/$$
50 status=1        # failure is the default!
51
52 _cleanup()
53 {
54     umount $SCRATCH_MNT
55     rm -f $tmp.*
56 }
57 trap "_cleanup ; exit \$status" 0 1 2 3 15
58
59 # get standard environment, filters and checks
60 . ./common.rc
61 . ./common.filter
62
63 # real QA test starts here
64
65 _require_scratch
66
67 _cull_files()
68 {
69     perl -e "\$manifest=\"$tmp.manifest\";" -e '
70         open MANIFEST, $manifest;
71         @in = <MANIFEST>;
72         close MANIFEST;
73         open MANIFEST, ">$manifest";
74         for ($i = 0; $i < @in; $i++) {
75             if (($i+1) % 2 == 0) {
76                 # remove every second file
77                 chomp($s = $in[$i]);
78                 if (unlink($s) != 1) {
79                     print "_cull_files: could not delete \"$s\"\n";
80                     exit(1);
81                 }
82             }
83             else {
84                 print MANIFEST $in[$i];
85             }
86         }
87         close MANIFEST;'
88 }
89
90 _do()
91 {
92     if [ $# -ne 1 ]; then echo "Usage: _do \"cmd\"" 1>&2 ; exit 1; fi
93     echo "*** $1" >>$seq.full
94     eval "$1 >>$seq.full 2>&1"
95 }
96
97
98 # create a large contiguous file using dd
99 # use fill2fs to fill the filesystem up with 4k sized files
100 # fill any remaining space using dd
101 # delete every second 4k file - remaining free space should be fragmented
102 # use fill2 to generate a very large file - run it until it fails producing a truncated file
103 # delete the dd-generated file
104 # run fsr.xfs on the filesystem
105 # check checksums for remaining files
106
107 # create 3 minimum sized (16Mb) allocation groups
108 # xfs_repair is going to need three to verify the superblock
109 rm -f $seq.full
110 echo -n "Make a 48 megabyte filesystem on SCRATCH_DEV and mount... "
111 _do "mkfs -t xfs -d size=48m,agcount=3 -l internal -f $SCRATCH_DEV"
112 _do "mount -t xfs $SCRATCH_DEV $SCRATCH_MNT"
113 echo "done"
114 echo -n "Reserve 16 1Mb unfragmented regions... "
115 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
116 do
117     _do "dd if=/dev/zero of=$SCRATCH_MNT/hole$i bs=4096 count=256"
118     _do "dd if=/dev/zero of=$SCRATCH_MNT/space$i bs=4096 count=1"
119     _do "xfs_bmap $SCRATCH_MNT/hole$i"
120 done
121 echo "done" 
122 echo -n "Fill filesystem with 4k files, generate manifest... "
123 _do "(src/fill2fs --verbose --dir=$SCRATCH_MNT/fill --seed=0 --filesize=4096 --stddev=0 --list=$tmp.manifest)"
124 echo "done"
125 echo -n "Use up any further available space using dd... "
126 _do "dd if=/dev/zero of=$SCRATCH_MNT/pad bs=4096"
127 echo "done"
128 echo -n "Delete every second file... "
129 if ! _do "_cull_files"; then
130     echo "fail"
131     echo "Could not cull files. Test failed see $seq.full"
132     status=1; exit
133 fi
134 echo "done"
135 echo -n "Create one very large file... "
136 _do "src/fill2 -d nbytes=16000000,file=$SCRATCH_MNT/fragmented"
137 echo "done"
138 _do "xfs_bmap $SCRATCH_MNT/fragmented"
139 _do "(sum $SCRATCH_MNT/fragmented >$tmp.sum1)"
140 echo -n "Remove other files... "
141 _do "rm -rf $SCRATCH_MNT/{pad,hole*}"
142 echo "done"
143
144 # flush everything
145 _do "umount $SCRATCH_MNT"
146 _do "mount -t xfs $SCRATCH_DEV $SCRATCH_MNT"
147
148 echo -n "Run fsr.xfs on filesystem... "
149 _do "fsr.xfs -v $SCRATCH_DEV"
150 echo "done"
151 _do "xfs_bmap $SCRATCH_MNT/fragmented"
152
153 echo -n "Check 4k files... "
154 if ! _do "src/fill2fs_check $tmp.manifest"; then
155     echo "fail"
156     echo "4k file is corrupt/missing after fsr. Test failed see $seq.full"
157     status=1; exit
158 fi
159 echo "done"
160 echo -n "Check large file... "
161 _do "(sum $SCRATCH_MNT/fragmented >$tmp.sum2)"
162 if ! diff $tmp.sum1 $tmp.sum2; then
163     echo "fail"
164     echo "File is corrupt/missing after fsr. Test failed see $seq.full"
165     status=1; exit
166 fi
167 echo "done"
168
169 echo -n "Checking filesystem... "
170 _check_fs $SCRATCH_DEV
171 echo "done"
172 # success, all done
173 echo "fsr.xfs tests passed."
174 status=0 ; exit