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
39 testdir=$TEST_DIR/test-$seq
43 echo "Create the original files"
45 _pwrite_byte 0x61 0 $((blksz * 48 - 3)) $testdir/file1 >> $seqres.full
46 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
47 _pwrite_byte 0x61 0 $((blksz * 48 - 3)) $testdir/file3 >> $seqres.full
51 md5sum $testdir/file1 | _filter_test_dir
52 md5sum $testdir/file2 | _filter_test_dir
53 md5sum $testdir/file3 | _filter_test_dir
55 cmp -s $testdir/file1 $testdir/file2 || echo "Files 1-2 should match"
56 cmp -s $testdir/file1 $testdir/file3 || echo "Files 1-3 should match"
57 cmp -s $testdir/file2 $testdir/file3 || echo "Files 2-3 should match"
59 echo "directio CoW the second file"
60 _pwrite_byte 0x62 0 $blksz $testdir/file2 -d >> $seqres.full
61 _pwrite_byte 0x62 0 $blksz $testdir/file3 -d >> $seqres.full
63 _pwrite_byte 0x62 $((blksz * 16 - 512)) 512 $testdir/file2 -d >> $seqres.full
64 _pwrite_byte 0x62 $((blksz * 16 - 512)) 512 $testdir/file3 -d >> $seqres.full
66 _pwrite_byte 0x62 $((blksz * 48)) $blksz $testdir/file2 -d >> $seqres.full
67 _pwrite_byte 0x62 $((blksz * 48)) $blksz $testdir/file3 -d >> $seqres.full
71 md5sum $testdir/file1 | _filter_test_dir
72 md5sum $testdir/file2 | _filter_test_dir
73 md5sum $testdir/file3 | _filter_test_dir
75 cmp -s $testdir/file1 $testdir/file2 || echo "Files 1-2 should not match (intentional)"
76 cmp -s $testdir/file1 $testdir/file3 || echo "Files 1-3 should not match (intentional)"
77 cmp -s $testdir/file2 $testdir/file3 || echo "Files 2-3 should match"
79 echo "Compare the CoW'd section to the before file"
80 _compare_range $testdir/file1 0 $testdir/file2 0 $blksz \
81 || echo "Start sections do not match (intentional)"
83 _compare_range $testdir/file1 $((blksz * 16 - 512)) \
84 $testdir/file2 $((blksz * 16 - 512)) 512 \
85 || echo "Middle sections do not match (intentional)"
87 _compare_range $testdir/file1 $((blksz * 48 - 512)) \
88 $testdir/file2 $((blksz * 48 - 512)) $blksz \
89 || echo "End sections do not match (intentional)"
91 echo "Compare the CoW'd section to the after file"
92 _compare_range $testdir/file2 0 $testdir/file3 0 $blksz \
93 || echo "Start sections do not match"
95 _compare_range $testdir/file2 $((blksz * 16 - 512)) \
96 $testdir/file3 $((blksz * 16 - 512)) 512 \
97 || echo "Middle sections do not match"
99 _compare_range $testdir/file2 $((blksz * 48 - 512)) \
100 $testdir/file3 $((blksz * 48 - 512)) $blksz \
101 || echo "End sections do not match"
103 echo "Compare the not CoW'd sections"
104 _compare_range $testdir/file1 $blksz $testdir/file2 $blksz 512 \
105 || echo "Start sections of 1-2 do not match"
106 _compare_range $testdir/file2 $blksz $testdir/file3 $blksz 512 \
107 || echo "Start sections of 2-3 do not match"
110 _compare_range $testdir/file1 $((blksz * 16 - 1024)) \
111 $testdir/file2 $((blksz * 16 - 1024)) 512 \
112 || echo "Middle sections of 1-2 do not match"
114 _compare_range $testdir/file2 $((blksz * 16 - 1024)) \
115 $testdir/file3 $((blksz * 16 - 1024)) 512 \
116 || echo "Middle sections of 2-3 do not match"
118 _compare_range $testdir/file1 $((blksz * 48 - 1024)) \
119 $testdir/file2 $((blksz * 48 - 1024)) 512 \
120 || echo "End sections of 1-2 do not match"
122 _compare_range $testdir/file2 $((blksz * 48 - 1024)) \
123 $testdir/file3 $((blksz * 48 - 1024)) 512 \
124 || echo "End sections of 2-3 do not match"
127 _compare_range $testdir/file1 $((blksz * 16)) \
128 $testdir/file2 $((blksz * 16)) 512 \
129 || echo "Untouched sections of 1-2 do not match"
131 _compare_range $testdir/file2 $((blksz * 16)) \
132 $testdir/file3 $((blksz * 16)) 512 \
133 || echo "Untouched sections of 2-3 do not match"