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