xfstests: convert tests to use new results directory
[xfstests-dev.git] / tests / xfs / 042
1 #! /bin/bash
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
12 # modify it under the terms 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,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 #
24 #-----------------------------------------------------------------------
25 #
26 set +x
27
28 seq=`basename $0`
29 seqres=$RESULT_DIR/$seq
30 seqres=$RESULT_DIR/$seq
31 seqres=$RESULT_DIR/$seq
32 echo "QA output created by $seq"
33
34 here=`pwd`
35 tmp=/tmp/$$
36 status=1        # failure is the default!
37
38 _cleanup()
39 {
40     umount $SCRATCH_MNT
41     rm -f $tmp.*
42 }
43 trap "_cleanup ; exit \$status" 0 1 2 3 15
44
45 # get standard environment, filters and checks
46 . ./common.rc
47 . ./common.filter
48
49 # real QA test starts here
50 _supported_fs xfs
51 _supported_os IRIX Linux
52
53 _require_scratch
54
55 [ "$XFS_FSR_PROG" = "" ] && _notrun "xfs_fsr not found"
56
57 _cull_files()
58 {
59     perl -e "\$manifest=\"$tmp.manifest\";" -e '
60         open MANIFEST, $manifest;
61         @in = <MANIFEST>;
62         close MANIFEST;
63         open MANIFEST, ">$manifest";
64         for ($i = 0; $i < @in; $i++) {
65             if (($i+1) % 2 == 0) {
66                 # remove every second file
67                 chomp($s = $in[$i]);
68                 if (unlink($s) != 1) {
69                     print "_cull_files: could not delete \"$s\"\n";
70                     exit(1);
71                 }
72             }
73             else {
74                 print MANIFEST $in[$i];
75             }
76         }
77         close MANIFEST;
78         exit(0);'
79 }
80
81 # create a large contiguous file using dd
82 # use fill2fs to fill the filesystem up with 4k sized files
83 # fill any remaining space using dd
84 # delete every second 4k file - remaining free space should be fragmented
85 # use fill2 to generate a very large file - run it until it fails producing a truncated file
86 # delete the dd-generated file
87 # run xfs_fsr on the filesystem
88 # check checksums for remaining files
89 # create 3 minimum sized (16Mb) allocation groups
90 # xfs_repair is going to need three to verify the superblock
91
92 rm -f $seqres.full
93 _do_die_on_error=message_only
94
95 echo -n "Make a 48 megabyte filesystem on SCRATCH_DEV and mount... "
96 _scratch_mkfs_xfs -dsize=48m,agcount=3 2>&1 >/dev/null || _fail "mkfs failed"
97 _scratch_mount || _fail "mount failed" 
98
99 echo "done"
100
101 echo -n "Reserve 16 1Mb unfragmented regions... "
102 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
103 do
104         _do "$XFS_IO_PROG -f -c \"resvsp 0 1m\" $SCRATCH_MNT/hole$i"
105         _do "$XFS_IO_PROG -f -c \"resvsp 0 4k\" $SCRATCH_MNT/space$i"
106         _do "$XFS_IO_PROG -f -c \"resvsp 0 1m\" $SCRATCH_MNT/hole$i"
107         _do "xfs_bmap -vp $SCRATCH_MNT/hole$i"
108 done
109 echo "done" 
110
111 # set up filesystem
112 echo -n "Fill filesystem with fill file... "
113 for i in `seq 0 1 31`; do
114         _do "$XFS_IO_PROG -fs -c \"pwrite -S$i ${i}m 1m\" $SCRATCH_MNT/fill"
115 done
116 _do "xfs_bmap -vp $SCRATCH_MNT/fill"
117 echo "done"
118 # flush the filesystem - make sure there is no space "lost" to pre-allocation
119 _do "umount $SCRATCH_MNT"
120 _do "_scratch_mount"
121 echo -n "Use up any further available space using dd... "
122 _do "dd if=/dev/zero of=$SCRATCH_MNT/pad bs=4096"
123 echo "done"
124
125 # create fragmented file
126 #_do "Delete every second file" "_cull_files"
127 echo -n "Punch every second 4k block... "
128 for i in `seq 0 8 32768`; do
129         # This generates excessive output that significantly slows down the
130         # test. It's not necessary for debug, so just bin it.
131         $XFS_IO_PROG -f -c "unresvsp ${i}k 4k" $SCRATCH_MNT/fill \
132                                                                 > /dev/null 2>&1
133 done
134 _do "xfs_bmap -vp $SCRATCH_MNT/fill"
135 _do "sum $SCRATCH_MNT/fill >$tmp.fillsum1"
136 echo "done"
137
138 echo -n "Create one very large file... "
139 _do "src/fill2 -d nbytes=16000000,file=$SCRATCH_MNT/fragmented"
140 echo "done"
141 _do "xfs_bmap -v $SCRATCH_MNT/fragmented"
142 _do "sum $SCRATCH_MNT/fragmented >$tmp.sum1"
143 _do "Remove other files" "rm -rf $SCRATCH_MNT/{pad,hole*}"
144
145 # defragment
146 _do "Run xfs_fsr on filesystem" "$XFS_FSR_PROG -v $SCRATCH_MNT/fragmented"
147 _do "xfs_bmap -v $SCRATCH_MNT/fragmented"
148
149 echo -n "Check fill file... "
150 _do "sum $SCRATCH_MNT/fill >$tmp.fillsum2"
151 if ! _do "diff $tmp.fillsum1 $tmp.fillsum2"; then
152     echo "fail"
153     echo "Fill file is corrupt/missing after fsr. Test failed see $seqres.full"
154     status=1; exit
155 fi
156 echo "done"
157
158 # check
159 echo -n "Check large file... "
160 _do "sum $SCRATCH_MNT/fragmented >$tmp.sum2"
161 if ! _do "diff $tmp.sum1 $tmp.sum2"; then
162     echo "fail"
163     echo "File is corrupt/missing after fsr. Test failed see $seqres.full"
164     status=1; exit
165 fi
166 echo "done"
167 _do "Checking filesystem" "_check_scratch_fs"
168
169 # success, all done
170 echo "xfs_fsr tests passed."
171 status=0 ; exit