2 # SPDX-License-Identifier: GPL-2.0
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.
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
17 status=1 # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
25 # get standard environment, filters and checks
30 # real QA test starts here
34 _require_xfs_io_command "falloc"
41 echo "Create file with $nr * 2 fragments"
45 $XFS_IO_PROG -f -c "falloc $((409600*i)) 4k" \
46 $SCRATCH_MNT/test.$nr >> $seqres.full 2>&1
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 write will convert extents to initialized ones
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
58 md5sum $SCRATCH_MNT/test.* | _filter_scratch
59 $XFS_IO_PROG -c "fiemap" -f $SCRATCH_MNT/test.* > $tmp.fiemap.before
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"
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
81 # Actual testing starting from here
82 _scratch_mkfs >> $seqres.full 2>&1