xfstests: automatically add -F to xfs_io on non-xfs
[xfstests-dev.git] / tests / shared / 218
1 #! /bin/bash
2 # FS QA Test No. 218
3 #
4 # Basic defragmentation sanity tests
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2009 Eric Sandeen.  All Rights Reserved.
8 #
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.
12 #
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.
17 #
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 #-----------------------------------------------------------------------
22 #
23
24 seq=`basename $0`
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
27
28 here=`pwd`
29 tmp=tmp/$$
30 status=1        # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
32
33 _cleanup()
34 {
35     cd /
36     rm -f $tmp.*
37     _cleanup_testdir
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/filter
43 . ./common/defrag
44
45 # real QA test starts here
46 _supported_fs xfs ext4 btrfs
47 _supported_os Linux
48
49 _setup_testdir
50 # We require scratch so that we'll have free contiguous space
51 _require_scratch
52 _scratch_mkfs >/dev/null 2>&1
53 _scratch_mount
54
55 _require_defrag
56
57 fragfile=$SCRATCH_MNT/fragfile.$$
58
59 rm -f $fragfile
60
61 # Craft some fragmented files, defrag them, check the result.
62
63 echo "zero-length file:" | tee -a $seqres.full
64 touch $fragfile
65 _defrag $fragfile
66
67 echo "Sparse file (no blocks):" | tee -a $seqres.full
68 $XFS_IO_PROG -f -c "truncate 1m" $fragfile
69 _defrag $fragfile
70
71 echo "Contiguous file:" | tee -a $seqres.full
72 dd if=/dev/zero of=$fragfile bs=4k count=4 &>/dev/null
73 _defrag $fragfile
74
75 echo "Write backwards sync, but contiguous - should defrag to 1 extent" | tee -a $seqres.full
76 for I in `seq 9 -1 0`; do
77         dd if=/dev/zero of=$fragfile bs=4k count=1 conv=notrunc seek=$I oflag=sync &>/dev/null
78 done
79 _defrag $fragfile
80
81 echo "Write backwards sync leaving holes - defrag should do nothing" | tee -a $seqres.full
82 for I in `seq 31 -2 0`; do
83         dd if=/dev/zero of=$fragfile bs=4k count=1 conv=notrunc seek=$I oflag=sync &>/dev/null
84 done
85 _defrag $fragfile
86
87 echo "Write forwards sync leaving holes - defrag should do nothing" | tee -a $seqres.full
88 for I in `seq 0 2 31`; do
89         dd if=/dev/zero of=$fragfile bs=4k count=1 conv=notrunc seek=$I oflag=sync &>/dev/null
90 done
91 _defrag $fragfile
92
93 rm -f $seqres.full
94 status=0
95 exit