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