fstests: _fail test by default when _scratch_mount fails
[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     _scratch_unmount
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 Linux
50
51 _require_scratch
52
53 [ "$XFS_FSR_PROG" = "" ] && _notrun "xfs_fsr not found"
54
55 # Test performs several operations to produce a badly fragmented file, then
56 # create enough contiguous free space for xfs_fsr to defragment the fragmented
57 # file:
58 #
59 # - create fs with 3 minimum sized (16Mb) allocation groups
60 # - create 16x1MB contiguous files which will become large free space extents
61 #   when deleted
62 # - put a small "space" between each of the 16 contiuguous files to ensure we
63 #   have separated free space extents
64 # - fill the remaining free space with a "fill file"
65 # - mount/unmount/fill remaining free space with a pad file
66 # - punch alternate single block holes in the the "fill file" to create
67 #   fragmented free space.
68 # - use fill2 to generate a very large fragmented file
69 # - delete the 16 large contiguous files created initially
70 # - run xfs_fsr on the filesystem
71 # - check checksums for remaining files
72
73 rm -f $seqres.full
74 _do_die_on_error=message_only
75
76 echo -n "Make a 48 megabyte filesystem on SCRATCH_DEV and mount... "
77 _scratch_mkfs_xfs -dsize=48m,agcount=3 2>&1 >/dev/null || _fail "mkfs failed"
78 _scratch_mount
79
80 echo "done"
81
82 echo -n "Reserve 16 1Mb unfragmented regions... "
83 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
84 do
85         _do "$XFS_IO_PROG -f -c \"resvsp 0 1m\" $SCRATCH_MNT/hole$i"
86         _do "$XFS_IO_PROG -f -c \"resvsp 0 4k\" $SCRATCH_MNT/space$i"
87         _do "xfs_bmap -vp $SCRATCH_MNT/hole$i"
88 done
89 echo "done" 
90
91 # set up filesystem
92 echo -n "Fill filesystem with fill file... "
93 for i in `seq 0 1 31`; do
94         _do "$XFS_IO_PROG -f -c \"falloc ${i}m 1m\" $SCRATCH_MNT/fill"
95 done
96 _do "xfs_bmap -vp $SCRATCH_MNT/fill"
97 echo "done"
98 # flush the filesystem - make sure there is no space "lost" to pre-allocation
99 _do "_scratch_unmount"
100 _do "_try_scratch_mount"
101 echo -n "Use up any further available space... "
102 _do "$XFS_IO_PROG -f -c \"falloc 0 1m\" $SCRATCH_MNT/pad"
103 echo "done"
104
105 # create fragmented file
106 #_do "Delete every second file" "_cull_files"
107 echo -n "Punch every second 4k block... "
108 for i in `seq 0 8 32768`; do
109         # This generates excessive output that significantly slows down the
110         # test. It's not necessary for debug, so just bin it.
111         $XFS_IO_PROG -f -c "unresvsp ${i}k 4k" $SCRATCH_MNT/fill \
112                                                                 > /dev/null 2>&1
113 done
114 _do "xfs_bmap -vp $SCRATCH_MNT/fill"
115 _do "sum $SCRATCH_MNT/fill >$tmp.fillsum1"
116 echo "done"
117
118 echo -n "Create one very large file... "
119 _do "src/fill2 -d nbytes=16000000,file=$SCRATCH_MNT/fragmented"
120 echo "done"
121 _do "xfs_bmap -v $SCRATCH_MNT/fragmented"
122 _do "sum $SCRATCH_MNT/fragmented >$tmp.sum1"
123 _do "Remove other files" "rm -rf $SCRATCH_MNT/{pad,hole*}"
124
125 # defragment
126 _do "Run xfs_fsr on filesystem" "$XFS_FSR_PROG -v $SCRATCH_MNT/fragmented"
127 _do "xfs_bmap -v $SCRATCH_MNT/fragmented"
128
129 echo -n "Check fill file... "
130 _do "sum $SCRATCH_MNT/fill >$tmp.fillsum2"
131 if ! _do "diff $tmp.fillsum1 $tmp.fillsum2"; then
132     echo "fail"
133     echo "Fill file is corrupt/missing after fsr. Test failed see $seqres.full"
134     status=1; exit
135 fi
136 echo "done"
137
138 # check
139 echo -n "Check large file... "
140 _do "sum $SCRATCH_MNT/fragmented >$tmp.sum2"
141 if ! _do "diff $tmp.sum1 $tmp.sum2"; then
142     echo "fail"
143     echo "File is corrupt/missing after fsr. Test failed see $seqres.full"
144     status=1; exit
145 fi
146 echo "done"
147
148 # success, all done
149 echo "xfs_fsr tests passed."
150 status=0 ; exit