2 # FS QA Test No. generic/018
4 # Basic defragmentation sanity tests
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2009 Eric Sandeen. All Rights Reserved.
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #-----------------------------------------------------------------------
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
30 status=1 # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
39 # get standard environment, filters and checks
44 # real QA test starts here
48 # We require scratch so that we'll have free contiguous space
50 _scratch_mkfs >/dev/null 2>&1
55 fragfile=$SCRATCH_MNT/fragfile.$$
59 # Craft some fragmented files, defrag them, check the result.
61 echo "zero-length file:" | tee -a $seqres.full
63 _defrag --before 0 --after 0 $fragfile
65 echo "Sparse file (no blocks):" | tee -a $seqres.full
66 $XFS_IO_PROG -f -c "truncate 1m" $fragfile
67 _defrag --before 0 --after 0 $fragfile
69 echo "Contiguous file:" | tee -a $seqres.full
70 dd if=/dev/zero of=$fragfile bs=4k count=4 &>/dev/null
71 _defrag --before 1 --after 1 $fragfile
73 echo "Write backwards sync, but contiguous - should defrag to 1 extent" | tee -a $seqres.full
74 for I in `seq 9 -1 0`; do
75 dd if=/dev/zero of=$fragfile bs=4k count=1 conv=notrunc seek=$I oflag=sync &>/dev/null
77 _defrag --before 10 --after 1 $fragfile
79 echo "Write backwards sync leaving holes - defrag should do nothing" | tee -a $seqres.full
80 for I in `seq 31 -2 0`; do
81 dd if=/dev/zero of=$fragfile bs=4k count=1 conv=notrunc seek=$I oflag=sync &>/dev/null
83 _defrag --before 16 --after 16 $fragfile
85 echo "Write forwards sync leaving holes - defrag should do nothing" | tee -a $seqres.full
86 for I in `seq 0 2 31`; do
87 dd if=/dev/zero of=$fragfile bs=4k count=1 conv=notrunc seek=$I oflag=sync &>/dev/null
89 _defrag --before 16 --after 16 $fragfile