2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
7 # Ensure that fallocate steps around reflinked ranges:
8 # - Reflink parts of two files together
9 # - Fallocate all the other sparse space.
10 # - Check that the reflinked areas are still there.
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
18 status=1 # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
24 rm -rf $tmp.* $testdir
27 # get standard environment, filters and checks
32 # real QA test starts here
35 _require_xfs_io_command "falloc"
36 _require_xfs_io_command "truncate"
40 testdir=$TEST_DIR/test-$seq
44 echo "Create the original files"
46 _pwrite_byte 0x61 0 $((blksz * 5 + 37)) $testdir/file1 >> $seqres.full
48 _reflink_range $testdir/file1 $blksz $testdir/file2 $blksz \
49 $((blksz * 4 + 37)) >> $seqres.full
51 $XFS_IO_PROG -f -c "truncate $((blksz * 5 + 37))" $testdir/file3 >> $seqres.full
52 _reflink_range $testdir/file1 0 $testdir/file3 0 $blksz >> $seqres.full
54 $XFS_IO_PROG -f -c "truncate $((blksz * 5 + 37))" $testdir/file4 >> $seqres.full
55 _reflink_range $testdir/file1 $blksz $testdir/file4 $blksz $blksz >> $seqres.full
56 _reflink_range $testdir/file1 $((blksz * 3)) $testdir/file4 $((blksz * 3)) \
57 $blksz >> $seqres.full
59 _cp_reflink $testdir/file1 $testdir/file5
62 echo "Compare sections"
63 md5sum $testdir/file1 | _filter_test_dir
64 md5sum $testdir/file2 | _filter_test_dir
65 md5sum $testdir/file3 | _filter_test_dir
66 md5sum $testdir/file4 | _filter_test_dir
67 md5sum $testdir/file5 | _filter_test_dir
69 _compare_range $testdir/file1 $blksz $testdir/file2 $blksz \
71 || echo "shared parts of files 1-2 changed"
73 _compare_range $testdir/file1 0 $testdir/file3 0 $blksz \
74 || echo "shared parts of files 1-3 changed"
76 _compare_range $testdir/file1 $blksz $testdir/file4 $blksz $blksz \
77 || echo "shared parts of files 1-4 changed"
79 _compare_range $testdir/file1 0 $testdir/file5 0 $((blksz * 5 + 37)) \
80 || echo "shared parts of files 1-5 changed"
83 c1=$(_md5_checksum $testdir/file1)
84 c2=$(_md5_checksum $testdir/file2)
85 c3=$(_md5_checksum $testdir/file3)
86 c4=$(_md5_checksum $testdir/file4)
87 c5=$(_md5_checksum $testdir/file5)
89 test ${c1} != ${c2} || echo "file1 and file2 should not match"
90 test ${c1} != ${c3} || echo "file1 and file3 should not match"
91 test ${c1} != ${c4} || echo "file1 and file4 should not match"
92 test ${c1} = ${c5} || echo "file1 and file5 should match"
93 test ${c2} != ${c3} || echo "file2 and file3 should not match"
94 test ${c2} != ${c4} || echo "file2 and file4 should not match"
95 test ${c2} != ${c5} || echo "file2 and file5 should not match"
96 test ${c3} != ${c4} || echo "file3 and file4 should not match"
97 test ${c3} != ${c5} || echo "file3 and file5 should not match"
98 test ${c4} != ${c5} || echo "file4 and file5 should not match"
100 echo "falloc everything"
101 $XFS_IO_PROG -f -c "falloc 0 $((blksz * 5))" $testdir/file2 >> $seqres.full
102 $XFS_IO_PROG -f -c "falloc 0 $((blksz * 5))" $testdir/file3 >> $seqres.full
103 $XFS_IO_PROG -f -c "falloc 0 $((blksz * 5))" $testdir/file4 >> $seqres.full
107 md5sum $testdir/file1 | _filter_test_dir
108 md5sum $testdir/file2 | _filter_test_dir
109 md5sum $testdir/file3 | _filter_test_dir
110 md5sum $testdir/file4 | _filter_test_dir
111 md5sum $testdir/file5 | _filter_test_dir
113 d1=$(_md5_checksum $testdir/file1)
114 d2=$(_md5_checksum $testdir/file2)
115 d3=$(_md5_checksum $testdir/file3)
116 d4=$(_md5_checksum $testdir/file4)
117 d5=$(_md5_checksum $testdir/file5)
119 test ${c1} = ${d1} || echo "file1 should not change"
120 test ${c2} = ${d2} || echo "file2 should not change"
121 test ${c3} = ${d3} || echo "file3 should not change"
122 test ${c4} = ${d4} || echo "file4 should not change"
123 test ${c5} = ${d5} || echo "file2 should not change"