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 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
40 testdir=$TEST_DIR/test-$seq
44 echo "Create the original files"
46 _pwrite_byte 0x61 0 $((blksz * 48 - 3)) $testdir/file1 >> $seqres.full
47 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
48 _pwrite_byte 0x61 0 $((blksz * 48 - 3)) $testdir/file3 >> $seqres.full
52 md5sum $testdir/file1 | _filter_test_dir
53 md5sum $testdir/file2 | _filter_test_dir
54 md5sum $testdir/file3 | _filter_test_dir
56 cmp -s $testdir/file1 $testdir/file2 || echo "Files 1-2 should match"
57 cmp -s $testdir/file1 $testdir/file3 || echo "Files 1-3 should match"
58 cmp -s $testdir/file2 $testdir/file3 || echo "Files 2-3 should match"
60 echo "directio CoW the second file"
61 _pwrite_byte 0x62 0 $blksz $testdir/file2 -d >> $seqres.full
62 _pwrite_byte 0x62 0 $blksz $testdir/file3 -d >> $seqres.full
64 _pwrite_byte 0x62 $((blksz * 16 - 512)) 512 $testdir/file2 -d >> $seqres.full
65 _pwrite_byte 0x62 $((blksz * 16 - 512)) 512 $testdir/file3 -d >> $seqres.full
67 _pwrite_byte 0x62 $((blksz * 48)) $blksz $testdir/file2 -d >> $seqres.full
68 _pwrite_byte 0x62 $((blksz * 48)) $blksz $testdir/file3 -d >> $seqres.full
72 md5sum $testdir/file1 | _filter_test_dir
73 md5sum $testdir/file2 | _filter_test_dir
74 md5sum $testdir/file3 | _filter_test_dir
76 cmp -s $testdir/file1 $testdir/file2 || echo "Files 1-2 should not match (intentional)"
77 cmp -s $testdir/file1 $testdir/file3 || echo "Files 1-3 should not match (intentional)"
78 cmp -s $testdir/file2 $testdir/file3 || echo "Files 2-3 should match"
80 echo "Compare the CoW'd section to the before file"
81 _compare_range $testdir/file1 0 $testdir/file2 0 $blksz \
82 || echo "Start sections do not match (intentional)"
84 _compare_range $testdir/file1 $((blksz * 16 - 512)) \
85 $testdir/file2 $((blksz * 16 - 512)) 512 \
86 || echo "Middle sections do not match (intentional)"
88 _compare_range $testdir/file1 $((blksz * 48 - 512)) \
89 $testdir/file2 $((blksz * 48 - 512)) $blksz \
90 || echo "End sections do not match (intentional)"
92 echo "Compare the CoW'd section to the after file"
93 _compare_range $testdir/file2 0 $testdir/file3 0 $blksz \
94 || echo "Start sections do not match"
96 _compare_range $testdir/file2 $((blksz * 16 - 512)) \
97 $testdir/file3 $((blksz * 16 - 512)) 512 \
98 || echo "Middle sections do not match"
100 _compare_range $testdir/file2 $((blksz * 48 - 512)) \
101 $testdir/file3 $((blksz * 48 - 512)) $blksz \
102 || echo "End sections do not match"
104 echo "Compare the not CoW'd sections"
105 _compare_range $testdir/file1 $blksz $testdir/file2 $blksz 512 \
106 || echo "Start sections of 1-2 do not match"
107 _compare_range $testdir/file2 $blksz $testdir/file3 $blksz 512 \
108 || echo "Start sections of 2-3 do not match"
111 _compare_range $testdir/file1 $((blksz * 16 - 1024)) \
112 $testdir/file2 $((blksz * 16 - 1024)) 512 \
113 || echo "Middle sections of 1-2 do not match"
115 _compare_range $testdir/file2 $((blksz * 16 - 1024)) \
116 $testdir/file3 $((blksz * 16 - 1024)) 512 \
117 || echo "Middle sections of 2-3 do not match"
119 _compare_range $testdir/file1 $((blksz * 48 - 1024)) \
120 $testdir/file2 $((blksz * 48 - 1024)) 512 \
121 || echo "End sections of 1-2 do not match"
123 _compare_range $testdir/file2 $((blksz * 48 - 1024)) \
124 $testdir/file3 $((blksz * 48 - 1024)) 512 \
125 || echo "End sections of 2-3 do not match"
128 _compare_range $testdir/file1 $((blksz * 16)) \
129 $testdir/file2 $((blksz * 16)) 512 \
130 || echo "Untouched sections of 1-2 do not match"
132 _compare_range $testdir/file2 $((blksz * 16)) \
133 $testdir/file3 $((blksz * 16)) 512 \
134 || echo "Untouched sections of 2-3 do not match"