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