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