2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
7 # Ensuring that copy on write through the page cache works:
8 # - Reflink two files together
9 # - Write to the beginning, middle, and end
10 # - Check that the files are now different where we say they're different.
13 _begin_fstest auto quick clone
15 # Override the default cleanup function.
19 rm -rf $tmp.* $testdir
22 # Import common functions.
26 # real QA test starts here
30 testdir=$TEST_DIR/test-$seq
34 echo "Create the original files"
36 _pwrite_byte 0x61 0 $((blksz * 48 - 3)) $testdir/file1 >> $seqres.full
37 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
38 _pwrite_byte 0x61 0 $((blksz * 48 - 3)) $testdir/file3 >> $seqres.full
42 md5sum $testdir/file1 | _filter_test_dir
43 md5sum $testdir/file2 | _filter_test_dir
44 md5sum $testdir/file3 | _filter_test_dir
46 cmp -s $testdir/file1 $testdir/file2 || echo "Files 1-2 do not match"
47 cmp -s $testdir/file1 $testdir/file3 || echo "Files 1-3 do not match"
48 cmp -s $testdir/file2 $testdir/file3 || echo "Files 2-3 do not match"
50 echo "pagecache CoW the second file"
51 _pwrite_byte 0x62 0 17 $testdir/file2 >> $seqres.full
52 _pwrite_byte 0x62 0 17 $testdir/file3 >> $seqres.full
54 _pwrite_byte 0x62 $((blksz * 16 - 34)) 17 $testdir/file2 >> $seqres.full
55 _pwrite_byte 0x62 $((blksz * 16 - 34)) 17 $testdir/file3 >> $seqres.full
57 _pwrite_byte 0x62 $((blksz * 48 - 8)) 17 $testdir/file2 >> $seqres.full
58 _pwrite_byte 0x62 $((blksz * 48 - 8)) 17 $testdir/file3 >> $seqres.full
62 md5sum $testdir/file1 | _filter_test_dir
63 md5sum $testdir/file2 | _filter_test_dir
64 md5sum $testdir/file3 | _filter_test_dir
66 cmp -s $testdir/file1 $testdir/file2 || echo "Files 1-2 do not match (intentional)"
67 cmp -s $testdir/file1 $testdir/file3 || echo "Files 1-3 do not match (intentional)"
68 cmp -s $testdir/file2 $testdir/file3 || echo "Files 2-3 do not match"
70 echo "Compare the CoW'd section to the before file"
71 _compare_range $testdir/file1 0 $testdir/file2 0 17 \
72 || echo "Start sections do not match (intentional)"
74 _compare_range $testdir/file1 $((blksz * 16 - 34)) \
75 $testdir/file2 $((blksz * 16 - 34)) 17 \
76 || echo "Middle sections do not match (intentional)"
78 _compare_range $testdir/file1 $((blksz * 48 - 8)) \
79 $testdir/file2 $((blksz * 48 - 8)) 17 \
80 || echo "End sections do not match (intentional)"
82 echo "Compare the CoW'd section to the after file"
83 _compare_range $testdir/file2 0 $testdir/file3 0 17 \
84 || echo "Start sections do not match"
86 _compare_range $testdir/file2 $((blksz * 16 - 34)) \
87 $testdir/file3 $((blksz * 16 - 34)) 17 \
88 || echo "Middle sections do not match"
90 _compare_range $testdir/file2 $((blksz * 48 - 8)) \
91 $testdir/file3 $((blksz * 48 - 8)) 17 \
92 || echo "End sections do not match"
94 echo "Compare the not CoW'd sections"
95 _compare_range $testdir/file1 18 $testdir/file2 18 17 \
96 || echo "Start sections of 1-2 do not match"
98 _compare_range $testdir/file2 18 $testdir/file3 18 17 \
99 || echo "Start sections of 2-3 do not match"
101 _compare_range $testdir/file1 $((blksz * 16 - 17)) \
102 $testdir/file2 $((blksz * 16 - 17)) 82 \
103 || echo "Middle sections of 1-2 do not match"
105 _compare_range $testdir/file2 $((blksz * 16 - 17)) \
106 $testdir/file3 $((blksz * 16 - 17)) 82 \
107 || echo "Middle sections of 2-3 do not match"
109 _compare_range $testdir/file1 $((blksz * 48 - 108)) \
110 $testdir/file2 $((blksz * 48 - 108)) 100 \
111 || echo "End sections of 1-2 do not match"
113 _compare_range $testdir/file2 $((blksz * 48 - 108)) \
114 $testdir/file3 $((blksz * 48 - 108)) 100 \
115 || echo "End sections of 2-3 do not match"
117 _compare_range $testdir/file1 $((blksz * 14)) \
118 $testdir/file2 $((blksz * 14)) $blksz \
119 || echo "Untouched sections of 1-2 do not match"
121 _compare_range $testdir/file2 $((blksz * 14)) \
122 $testdir/file3 $((blksz * 14)) $blksz \
123 || echo "Untouched sections of 2-3 do not match"