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
36 _require_xfs_io_command "falloc"
37 _require_xfs_io_command "truncate"
41 testdir=$TEST_DIR/test-$seq
45 echo "Create the original files"
47 _pwrite_byte 0x61 0 $((blksz * 5 + 37)) $testdir/file1 >> $seqres.full
49 _reflink_range $testdir/file1 $blksz $testdir/file2 $blksz \
50 $((blksz * 4 + 37)) >> $seqres.full
52 $XFS_IO_PROG -f -c "truncate $((blksz * 5 + 37))" $testdir/file3 >> $seqres.full
53 _reflink_range $testdir/file1 0 $testdir/file3 0 $blksz >> $seqres.full
55 $XFS_IO_PROG -f -c "truncate $((blksz * 5 + 37))" $testdir/file4 >> $seqres.full
56 _reflink_range $testdir/file1 $blksz $testdir/file4 $blksz $blksz >> $seqres.full
57 _reflink_range $testdir/file1 $((blksz * 3)) $testdir/file4 $((blksz * 3)) \
58 $blksz >> $seqres.full
60 _cp_reflink $testdir/file1 $testdir/file5
63 echo "Compare sections"
64 md5sum $testdir/file1 | _filter_test_dir
65 md5sum $testdir/file2 | _filter_test_dir
66 md5sum $testdir/file3 | _filter_test_dir
67 md5sum $testdir/file4 | _filter_test_dir
68 md5sum $testdir/file5 | _filter_test_dir
70 _compare_range $testdir/file1 $blksz $testdir/file2 $blksz \
72 || echo "shared parts of files 1-2 changed"
74 _compare_range $testdir/file1 0 $testdir/file3 0 $blksz \
75 || echo "shared parts of files 1-3 changed"
77 _compare_range $testdir/file1 $blksz $testdir/file4 $blksz $blksz \
78 || echo "shared parts of files 1-4 changed"
80 _compare_range $testdir/file1 0 $testdir/file5 0 $((blksz * 5 + 37)) \
81 || echo "shared parts of files 1-5 changed"
84 c1=$(_md5_checksum $testdir/file1)
85 c2=$(_md5_checksum $testdir/file2)
86 c3=$(_md5_checksum $testdir/file3)
87 c4=$(_md5_checksum $testdir/file4)
88 c5=$(_md5_checksum $testdir/file5)
90 test ${c1} != ${c2} || echo "file1 and file2 should not match"
91 test ${c1} != ${c3} || echo "file1 and file3 should not match"
92 test ${c1} != ${c4} || echo "file1 and file4 should not match"
93 test ${c1} = ${c5} || echo "file1 and file5 should match"
94 test ${c2} != ${c3} || echo "file2 and file3 should not match"
95 test ${c2} != ${c4} || echo "file2 and file4 should not match"
96 test ${c2} != ${c5} || echo "file2 and file5 should not match"
97 test ${c3} != ${c4} || echo "file3 and file4 should not match"
98 test ${c3} != ${c5} || echo "file3 and file5 should not match"
99 test ${c4} != ${c5} || echo "file4 and file5 should not match"
101 echo "falloc everything"
102 $XFS_IO_PROG -f -c "falloc 0 $((blksz * 5))" $testdir/file2 >> $seqres.full
103 $XFS_IO_PROG -f -c "falloc 0 $((blksz * 5))" $testdir/file3 >> $seqres.full
104 $XFS_IO_PROG -f -c "falloc 0 $((blksz * 5))" $testdir/file4 >> $seqres.full
108 md5sum $testdir/file1 | _filter_test_dir
109 md5sum $testdir/file2 | _filter_test_dir
110 md5sum $testdir/file3 | _filter_test_dir
111 md5sum $testdir/file4 | _filter_test_dir
112 md5sum $testdir/file5 | _filter_test_dir
114 d1=$(_md5_checksum $testdir/file1)
115 d2=$(_md5_checksum $testdir/file2)
116 d3=$(_md5_checksum $testdir/file3)
117 d4=$(_md5_checksum $testdir/file4)
118 d5=$(_md5_checksum $testdir/file5)
120 test ${c1} = ${d1} || echo "file1 should not change"
121 test ${c2} = ${d2} || echo "file2 should not change"
122 test ${c3} = ${d3} || echo "file3 should not change"
123 test ${c4} = ${d4} || echo "file4 should not change"
124 test ${c5} = ${d5} || echo "file2 should not change"