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
33 _require_xfs_io_command "falloc"
40 echo "Create file with $nr * 2 fragments"
44 $XFS_IO_PROG -f -c "falloc $((409600*i)) 4k" \
45 $SCRATCH_MNT/test.$nr >> $seqres.full 2>&1
47 # Fill holes for half of range , as result file will contain nr*1.5 fragments
48 $XFS_IO_PROG -c "falloc 0 $((204800*nr))" \
49 $SCRATCH_MNT/test.$nr | _filter_xfs_io
50 # Data write will convert extents to initialized ones
53 patt=`printf "0x%x" $i`
54 $XFS_IO_PROG -c "pwrite -S $patt $((i*123400)) 1234" \
55 $SCRATCH_MNT/test.$nr | _filter_xfs_io
57 md5sum $SCRATCH_MNT/test.* | _filter_scratch
58 $XFS_IO_PROG -c "fiemap" -f $SCRATCH_MNT/test.* > $tmp.fiemap.before
60 echo "Perform compacting"
61 $XFS_IO_PROG -c "falloc 0 246M" -f $SCRATCH_MNT/donor | _filter_xfs_io
62 ls $SCRATCH_MNT/test.* | run_check $here/src/e4compact \
63 -v -i -f $SCRATCH_MNT/donor >> $seqres.full 2>&1
64 md5sum $SCRATCH_MNT/test.* | _filter_scratch
65 $XFS_IO_PROG -c "fiemap" -f $SCRATCH_MNT/test.* > $tmp.fiemap.pass1
66 diff $tmp.fiemap.before $tmp.fiemap.pass1 > /dev/null && \
67 _fail "Pass1: Extent's layout not changed"
69 echo "Perform compacting, second pass"
70 # Second pass should restore original layout
71 ls $SCRATCH_MNT/test.* | run_check $here/src/e4compact \
72 -v -f $SCRATCH_MNT/donor >> $seqres.full 2>&1
73 md5sum $SCRATCH_MNT/test.* | _filter_scratch
74 $XFS_IO_PROG -c "fiemap" -f $SCRATCH_MNT/test.* > $tmp.fiemap.pass2
75 diff -up $tmp.fiemap.before $tmp.fiemap.pass2 || \
76 _fail "Pass2: Extent's layout changed."
77 unlink $SCRATCH_MNT/donor
80 # Actual testing starting from here
81 _scratch_mkfs >> $seqres.full 2>&1