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