5 # create a large fragmented file and check that xfs_fsr doesn't corrupt
6 # it or the other contents of the filesystem
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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
24 #-----------------------------------------------------------------------
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
34 status=1 # failure is the default!
41 trap "_cleanup ; exit \$status" 0 1 2 3 15
43 # get standard environment, filters and checks
47 # real QA test starts here
53 [ "$XFS_FSR_PROG" = "" ] && _notrun "xfs_fsr not found"
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
59 # - create fs with 3 minimum sized (16Mb) allocation groups
60 # - create 16x1MB contiguous files which will become large free space extents
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
74 _do_die_on_error=message_only
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"
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
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"
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"
96 _do "xfs_bmap -vp $SCRATCH_MNT/fill"
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"
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 \
114 _do "xfs_bmap -vp $SCRATCH_MNT/fill"
115 _do "sum $SCRATCH_MNT/fill >$tmp.fillsum1"
118 echo -n "Create one very large file... "
119 _do "src/fill2 -d nbytes=16000000,file=$SCRATCH_MNT/fragmented"
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*}"
126 _do "Run xfs_fsr on filesystem" "$XFS_FSR_PROG -v $SCRATCH_MNT/fragmented"
127 _do "xfs_bmap -v $SCRATCH_MNT/fragmented"
129 echo -n "Check fill file... "
130 _do "sum $SCRATCH_MNT/fill >$tmp.fillsum2"
131 if ! _do "diff $tmp.fillsum1 $tmp.fillsum2"; then
133 echo "Fill file is corrupt/missing after fsr. Test failed see $seqres.full"
139 echo -n "Check large file... "
140 _do "sum $SCRATCH_MNT/fragmented >$tmp.sum2"
141 if ! _do "diff $tmp.sum1 $tmp.sum2"; then
143 echo "File is corrupt/missing after fsr. Test failed see $seqres.full"
149 echo "xfs_fsr tests passed."