74bfc1ba79b9a070aef11e2bf31ffaa6a0d1a6c5
[xfstests-dev.git] / tests / ext4 / 308
1 #! /bin/bash
2 # FSQA Test No. 308
3 #
4 # Check data integrity and layout stability during defrag compacting
5 # EXT4_IOC_MOVE_EXT simply swap extents between target and donor inode.
6 # So if ioctl was performed twice then inode's layout should not change.
7 #
8 #-----------------------------------------------------------------------
9 # (c) 2014 Dmitry Monakhov
10 #
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.
14 #
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.
19 #
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
23 #-----------------------------------------------------------------------
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 PIDS=""
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         rm -f $tmp.*
37 }
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42 . ./common/defrag
43
44 # real QA test starts here
45 _supported_os Linux
46 _require_scratch
47 _require_defrag
48 _require_xfs_io_command "falloc"
49
50 rm -f $seqres.full
51
52 _workout()
53 {
54         nr=$1
55         echo "Create file with $nr * 2 fragments"
56         # Create sparse file
57         for ((i=0;i<nr;i++))
58         do
59                 $XFS_IO_PROG -f -c "falloc $((409600*i)) 4k"  \
60                         $SCRATCH_MNT/test.$nr >> $seqres.full 2>&1
61         done
62         # Fill holes for half of range , as result file will contain nr*1.5 fragments
63         $XFS_IO_PROG -c "falloc 0 $((204800*nr))"  \
64             $SCRATCH_MNT/test.$nr | _filter_xfs_io
65         # Data wrilte will convert extetns to inialized ones
66         for ((i=0;i<nr;i++))
67         do
68                 patt=`printf "0x%x" $i`
69                 $XFS_IO_PROG -c "pwrite -S $patt $((i*123400)) 1234" \
70                         $SCRATCH_MNT/test.$nr | _filter_xfs_io
71         done
72         md5sum $SCRATCH_MNT/test.* | _filter_scratch
73         $XFS_IO_PROG -c "fiemap" -f $SCRATCH_MNT/test.* > $tmp.fiemap.before
74
75         echo "Perform compacting"
76         $XFS_IO_PROG -c "falloc 0 246M" -f $SCRATCH_MNT/donor | _filter_xfs_io
77         ls $SCRATCH_MNT/test.* | run_check $here/src/e4compact \
78                  -v -i -f $SCRATCH_MNT/donor  >> $seqres.full 2>&1
79         md5sum $SCRATCH_MNT/test.* | _filter_scratch
80         $XFS_IO_PROG -c "fiemap" -f $SCRATCH_MNT/test.* > $tmp.fiemap.pass1
81         diff $tmp.fiemap.before $tmp.fiemap.pass1 > /dev/null && \
82             _fail "Pass1: Extent's layout not changed"
83
84         echo "Perform compacting, second pass"
85         # Second pass should restore original layout
86         ls $SCRATCH_MNT/test.* | run_check $here/src/e4compact \
87                  -v -f $SCRATCH_MNT/donor  >> $seqres.full 2>&1
88         md5sum $SCRATCH_MNT/test.* | _filter_scratch
89         $XFS_IO_PROG -c "fiemap" -f $SCRATCH_MNT/test.* > $tmp.fiemap.pass2
90         diff -up $tmp.fiemap.before $tmp.fiemap.pass2 || \
91             _fail "Pass2: Extent's layout changed."
92         unlink $SCRATCH_MNT/donor
93 }
94
95 # Actual testing starting from here
96 _scratch_mkfs  >> $seqres.full 2>&1
97 _scratch_mount
98 _workout 10
99 _workout 20
100 _workout 40
101 _workout 80
102 _workout 160
103 status=0