generic: convert tests to SPDX license tags
[xfstests-dev.git] / tests / generic / 139
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 139
6 #
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.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1    # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23     cd /
24     rm -rf $tmp.* $testdir
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30 . ./common/reflink
31
32 # real QA test starts here
33 _supported_os Linux
34 _require_test_reflink
35 _require_cp_reflink
36 _require_odirect
37
38 rm -f $seqres.full
39
40 testdir=$TEST_DIR/test-$seq
41 rm -rf $testdir
42 mkdir $testdir
43
44 echo "Create the original files"
45 blksz=65536
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
49 _test_cycle_mount
50
51 echo "Compare files"
52 md5sum $testdir/file1 | _filter_test_dir
53 md5sum $testdir/file2 | _filter_test_dir
54 md5sum $testdir/file3 | _filter_test_dir
55
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"
59
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
63
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
66
67 _pwrite_byte 0x62 $((blksz * 48)) $blksz $testdir/file2 -d >> $seqres.full
68 _pwrite_byte 0x62 $((blksz * 48)) $blksz $testdir/file3 -d >> $seqres.full
69 _test_cycle_mount
70
71 echo "Compare files"
72 md5sum $testdir/file1 | _filter_test_dir
73 md5sum $testdir/file2 | _filter_test_dir
74 md5sum $testdir/file3 | _filter_test_dir
75
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"
79
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)"
83
84 _compare_range  $testdir/file1 $((blksz * 16 - 512)) \
85                 $testdir/file2 $((blksz * 16 - 512)) 512 \
86        || echo "Middle sections do not match (intentional)"
87
88 _compare_range  $testdir/file1 $((blksz * 48 - 512)) \
89                 $testdir/file2 $((blksz * 48 - 512)) $blksz \
90        || echo "End sections do not match (intentional)"
91
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"
95
96 _compare_range  $testdir/file2 $((blksz * 16 - 512)) \
97                 $testdir/file3 $((blksz * 16 - 512)) 512 \
98        || echo "Middle sections do not match"
99
100 _compare_range  $testdir/file2 $((blksz * 48 - 512)) \
101                 $testdir/file3 $((blksz * 48 - 512)) $blksz \
102        || echo "End sections do not match"
103
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"
109
110
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"
114
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"
118
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"
122
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"
126
127
128 _compare_range  $testdir/file1 $((blksz * 16)) \
129                 $testdir/file2 $((blksz * 16)) 512 \
130        || echo "Untouched sections of 1-2 do not match"
131
132 _compare_range  $testdir/file2 $((blksz * 16)) \
133                 $testdir/file3 $((blksz * 16)) 512 \
134        || echo "Untouched sections of 2-3 do not match"
135
136 # success, all done
137 status=0
138 exit