use _do from common.rc
[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 # xfs_fsr QA tests
6 # create a large fragmented file and check that xfs_fsr 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 # create a large contiguous file using dd
91 # use fill2fs to fill the filesystem up with 4k sized files
92 # fill any remaining space using dd
93 # delete every second 4k file - remaining free space should be fragmented
94 # use fill2 to generate a very large file - run it until it fails producing a truncated file
95 # delete the dd-generated file
96 # run xfs_fsr on the filesystem
97 # check checksums for remaining files
98 # create 3 minimum sized (16Mb) allocation groups
99 # xfs_repair is going to need three to verify the superblock
100 rm -f $seq.full
101 echo -n "Make a 48 megabyte filesystem on SCRATCH_DEV and mount... "
102 _do "mkfs -t xfs -d size=48m,agcount=3 -l internal -f $SCRATCH_DEV"
103 _do "mount -t xfs $SCRATCH_DEV $SCRATCH_MNT"
104 echo "done"
105 echo -n "Reserve 16 1Mb unfragmented regions... "
106 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
107 do
108     _do "dd if=/dev/zero of=$SCRATCH_MNT/hole$i bs=4096 count=256"
109     _do "dd if=/dev/zero of=$SCRATCH_MNT/space$i bs=4096 count=1"
110     _do "xfs_bmap $SCRATCH_MNT/hole$i"
111 done
112 echo "done" 
113 echo -n "Fill filesystem with 4k files, generate manifest... "
114 _do "src/fill2fs --verbose --dir=$SCRATCH_MNT/fill --seed=0 --filesize=4096 --stddev=0 --list=$tmp.manifest"
115 echo "done"
116 echo -n "Use up any further available space using dd... "
117 _do "dd if=/dev/zero of=$SCRATCH_MNT/pad bs=4096"
118 echo "done"
119 echo -n "Delete every second file... "
120 if ! _do "_cull_files"; then
121     echo "fail"
122     echo "Could not cull files. Test failed see $seq.full"
123     status=1; exit
124 fi
125 echo "done"
126 echo -n "Create one very large file... "
127 _do "src/fill2 -d nbytes=16000000,file=$SCRATCH_MNT/fragmented"
128 echo "done"
129 _do "xfs_bmap $SCRATCH_MNT/fragmented"
130 _do "sum $SCRATCH_MNT/fragmented >$tmp.sum1"
131 echo -n "Remove other files... "
132 _do "rm -rf $SCRATCH_MNT/{pad,hole*}"
133 echo "done"
134
135 # flush everything
136 _do "umount $SCRATCH_MNT"
137 _do "mount -t xfs $SCRATCH_DEV $SCRATCH_MNT"
138
139 echo -n "Run xfs_fsr on filesystem... "
140 _do "xfs_fsr -v $SCRATCH_DEV"
141 echo "done"
142 _do "xfs_bmap $SCRATCH_MNT/fragmented"
143
144 echo -n "Check 4k files... "
145 if ! _do "src/fill2fs_check $tmp.manifest"; then
146     echo "fail"
147     echo "4k file is corrupt/missing after fsr. Test failed see $seq.full"
148     status=1; exit
149 fi
150 echo "done"
151 echo -n "Check large file... "
152 _do "sum $SCRATCH_MNT/fragmented >$tmp.sum2"
153 if ! diff $tmp.sum1 $tmp.sum2; then
154     echo "fail"
155     echo "File is corrupt/missing after fsr. Test failed see $seq.full"
156     status=1; exit
157 fi
158 echo "done"
159
160 echo -n "Checking filesystem... "
161 _check_fs $SCRATCH_DEV
162 echo "done"
163 # success, all done
164 echo "xfs_fsr tests passed."
165 status=0 ; exit