2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Oracle, Inc. All Rights Reserved.
7 # Check that reflinking adjacent blocks in a file produces a single
8 # block mapping extent.
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 7 15
26 # get standard environment, filters and checks
31 # real QA test starts here
33 _require_scratch_reflink
34 _require_xfs_io_command "falloc"
35 _require_xfs_io_command "fiemap"
37 echo "Format and mount"
38 _scratch_mkfs > $seqres.full 2>&1
39 _scratch_mount >> $seqres.full 2>&1
41 testdir=$SCRATCH_MNT/test-$seq
46 sz=$((blocks * blksz))
48 echo "Create the original files"
49 $XFS_IO_PROG -f -c "falloc 0 $sz" $testdir/file1 >> $seqres.full
50 _pwrite_byte 0x61 0 $sz $testdir/file1 >> $seqres.full
51 seq 0 $blksz $((sz - blksz)) | while read offset; do
52 _reflink_range $testdir/file1 $offset $testdir/file2 $offset $blksz >> $seqres.full
56 md5sum $testdir/file1 | _filter_scratch
57 md5sum $testdir/file2 | _filter_scratch
59 echo "Check extent counts"
60 f1=$(_count_extents $testdir/file1)
61 f2=$(_count_extents $testdir/file2)
62 s1=$($XFS_IO_PROG -c 'fiemap -v' $testdir/file1 | awk '{print $5}' | grep -c '0x.*[2367aAbBfF]...$')
63 s2=$($XFS_IO_PROG -c 'fiemap -v' $testdir/file2 | awk '{print $5}' | grep -c '0x.*[2367aAbBfF]...$')
65 # Did the fs combine the extent mappings when we made f2?
66 test $f1 -eq $f2 || echo "f1 ($f1) != f2 ($f2)"
67 test $s1 -eq $s2 || echo "s1 ($s1) != s2 ($s2)"
68 test $f1 -eq $s1 || echo "f1 ($f1) != s1 ($f1)"
69 test $f2 -eq $s2 || echo "f2 ($f2) != s2 ($f2)"
73 echo "Compare files after remounting"
74 md5sum $testdir/file1 | _filter_scratch
75 md5sum $testdir/file2 | _filter_scratch
77 echo "Check extent counts"
78 f1=$(_count_extents $testdir/file1)
79 f2=$(_count_extents $testdir/file2)
80 s1=$($XFS_IO_PROG -c 'fiemap -v' $testdir/file1 | awk '{print $5}' | grep -c '0x.*[2367aAbBfF]...$')
81 s2=$($XFS_IO_PROG -c 'fiemap -v' $testdir/file2 | awk '{print $5}' | grep -c '0x.*[2367aAbBfF]...$')
83 # Are the mappings still combined?
84 test $f1 -eq $f2 || echo "f1 ($f1) != f2 ($f2)"
85 test $s1 -eq $s2 || echo "s1 ($s1) != s2 ($s2)"
86 test $f1 -eq $s1 || echo "f1 ($f1) != s1 ($f1)"
87 test $f2 -eq $s2 || echo "f2 ($f2) != s2 ($f2)"