5e642dcbd8b88dffd0b9894051839e41b8e31768
[xfstests-dev.git] / tests / generic / 324
1 #! /bin/bash
2 # FS QA Test No. generic/324
3 #
4 # Sanity check for defrag utility.
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2013 Red Hat, Inc.  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 seq=`basename $0`
24 seqres=$RESULT_DIR/$seq
25 echo "QA output created by $seq"
26
27 PIDS=""
28 tmp=/tmp/$$
29 status=1        # failure is the default!
30 trap "_cleanup; exit \$status" 0 1 2 3 15
31
32 _cleanup()
33 {
34         rm -f $tmp.*
35 }
36
37 # get standard environment, filters and checks
38 . ./common/rc
39 . ./common/filter
40 . ./common/defrag
41
42 # real QA test starts here
43 _supported_os Linux
44 _need_to_be_root
45 _require_scratch
46 _require_defrag
47 _require_xfs_io_command "falloc"
48
49 rm -f $seqres.full
50
51 _workout()
52 {
53         nr=$1
54         echo "Defragment file with $nr * 2 fragments"
55         # Create sparse file
56         for ((i=0;i<nr;i++))
57         do
58                 $XFS_IO_PROG -f -c "falloc $((409600*i)) 4k"  \
59                         $SCRATCH_MNT/test.$nr >> $seqres.full 2>&1
60         done
61         # Fill holes for half of range , as result file will contain nr*1.5 fragments
62         $XFS_IO_PROG -c "falloc 0 $((204800*nr))"  \
63             $SCRATCH_MNT/test.$nr | _filter_xfs_io
64         # Data wrilte will convert extetns to inialized ones
65         for ((i=0;i<nr;i++))
66         do
67                 patt=`printf "0x%x" $i`
68                 $XFS_IO_PROG -c "pwrite -S $patt $((i*123400)) 1234" \
69                         $SCRATCH_MNT/test.$nr | _filter_xfs_io
70         done
71         _defrag --min_before $nr --max_before $((nr*4)) \
72                 --min_after 1 $SCRATCH_MNT/test.$nr
73 }
74
75
76 # Actual testing starting from here
77 _scratch_mkfs  >> $seqres.full 2>&1
78 _scratch_mount
79 _workout 10
80 _workout 250
81 _workout 1000
82 status=0