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