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 in direct-io mode works:
8 # - Reflink two files together
9 # - Write to the beginning, middle, and end in direct-io mode
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
31 testdir=$TEST_DIR/test-$seq
35 echo "Create the original files"
37 _pwrite_byte 0x61 0 $((blksz * 48 - 3)) $testdir/file1 >> $seqres.full
38 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
39 _pwrite_byte 0x61 0 $((blksz * 48 - 3)) $testdir/file2.chk >> $seqres.full
43 md5sum $testdir/file1 | _filter_test_dir
44 md5sum $testdir/file2 | _filter_test_dir
45 md5sum $testdir/file2.chk | _filter_test_dir
47 cmp -s $testdir/file1 $testdir/file2 || echo "file1 and file2 should match"
48 cmp -s $testdir/file1 $testdir/file2.chk || echo "file1 and file2.chk should match"
49 cmp -s $testdir/file2 $testdir/file2.chk || echo "file2 and file2.chk should match"
51 echo "directio CoW the second file"
52 _pwrite_byte 0x62 0 $blksz $testdir/file2 -d >> $seqres.full
53 _pwrite_byte 0x62 0 $blksz $testdir/file2.chk -d >> $seqres.full
55 _pwrite_byte 0x62 $((blksz * 16 - 512)) 512 $testdir/file2 -d >> $seqres.full
56 _pwrite_byte 0x62 $((blksz * 16 - 512)) 512 $testdir/file2.chk -d >> $seqres.full
58 _pwrite_byte 0x62 $((blksz * 48)) $blksz $testdir/file2 -d >> $seqres.full
59 _pwrite_byte 0x62 $((blksz * 48)) $blksz $testdir/file2.chk -d >> $seqres.full
63 md5sum $testdir/file1 | _filter_test_dir
64 md5sum $testdir/file2 | _filter_test_dir
65 md5sum $testdir/file2.chk | _filter_test_dir
67 cmp -s $testdir/file1 $testdir/file2 || echo "file1 and file2 should not match (intentional)"
68 cmp -s $testdir/file1 $testdir/file2.chk || echo "file1 and file2.chk should not match (intentional)"
69 cmp -s $testdir/file2 $testdir/file2.chk || echo "file2 and file2.chk should match"
71 echo "Compare the CoW'd section to the before file"
72 _compare_range $testdir/file1 0 $testdir/file2 0 $blksz \
73 || echo "Start sections do not match (intentional)"
75 _compare_range $testdir/file1 $((blksz * 16 - 512)) \
76 $testdir/file2 $((blksz * 16 - 512)) 512 \
77 || echo "Middle sections do not match (intentional)"
79 _compare_range $testdir/file1 $((blksz * 48 - 512)) \
80 $testdir/file2 $((blksz * 48 - 512)) $blksz \
81 || echo "End sections do not match (intentional)"
83 echo "Compare the CoW'd section to the after file"
84 _compare_range $testdir/file2 0 $testdir/file2.chk 0 $blksz \
85 || echo "Start sections do not match"
87 _compare_range $testdir/file2 $((blksz * 16 - 512)) \
88 $testdir/file2.chk $((blksz * 16 - 512)) 512 \
89 || echo "Middle sections do not match"
91 _compare_range $testdir/file2 $((blksz * 48 - 512)) \
92 $testdir/file2.chk $((blksz * 48 - 512)) $blksz \
93 || echo "End sections do not match"
95 echo "Compare the not CoW'd sections"
96 _compare_range $testdir/file1 $blksz $testdir/file2 $blksz 512 \
97 || echo "Start sections of file1 and file2 do not match"
98 _compare_range $testdir/file2 $blksz $testdir/file2.chk $blksz 512 \
99 || echo "Start sections of file2 and file2.chk do not match"
101 _compare_range $testdir/file1 $((blksz * 16 - 1024)) \
102 $testdir/file2 $((blksz * 16 - 1024)) 512 \
103 || echo "Middle sections of file1 and file2 do not match"
105 _compare_range $testdir/file2 $((blksz * 16 - 1024)) \
106 $testdir/file2.chk $((blksz * 16 - 1024)) 512 \
107 || echo "Middle sections of file2 and file2.chk do not match"
109 _compare_range $testdir/file1 $((blksz * 48 - 1024)) \
110 $testdir/file2 $((blksz * 48 - 1024)) 512 \
111 || echo "End sections of file1 and file2 do not match"
113 _compare_range $testdir/file2 $((blksz * 48 - 1024)) \
114 $testdir/file2.chk $((blksz * 48 - 1024)) 512 \
115 || echo "End sections of file2 and file2.chk do not match"
117 _compare_range $testdir/file1 $((blksz * 16)) \
118 $testdir/file2 $((blksz * 16)) 512 \
119 || echo "Untouched sections of file1 and file2 do not match"
121 _compare_range $testdir/file2 $((blksz * 16)) \
122 $testdir/file2.chk $((blksz * 16)) 512 \
123 || echo "Untouched sections of file2 and file2.chk do not match"