generic: copy_file_range swapfile test
[xfstests-dev.git] / tests / generic / 138
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. 138
6 #
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.
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
37 rm -f $seqres.full
38
39 testdir=$TEST_DIR/test-$seq
40 rm -rf $testdir
41 mkdir $testdir
42
43 echo "Create the original files"
44 blksz=65536
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
48 _test_cycle_mount
49
50 echo "Compare files"
51 md5sum $testdir/file1 | _filter_test_dir
52 md5sum $testdir/file2 | _filter_test_dir
53 md5sum $testdir/file3 | _filter_test_dir
54
55 cmp -s $testdir/file1 $testdir/file2 || echo "Files 1-2 do not match"
56 cmp -s $testdir/file1 $testdir/file3 || echo "Files 1-3 do not match"
57 cmp -s $testdir/file2 $testdir/file3 || echo "Files 2-3 do not match"
58
59 echo "pagecache CoW the second file"
60 _pwrite_byte 0x62 0 17 $testdir/file2 >> $seqres.full
61 _pwrite_byte 0x62 0 17 $testdir/file3 >> $seqres.full
62
63 _pwrite_byte 0x62 $((blksz * 16 - 34)) 17 $testdir/file2 >> $seqres.full
64 _pwrite_byte 0x62 $((blksz * 16 - 34)) 17 $testdir/file3 >> $seqres.full
65
66 _pwrite_byte 0x62 $((blksz * 48 - 8)) 17 $testdir/file2 >> $seqres.full
67 _pwrite_byte 0x62 $((blksz * 48 - 8)) 17 $testdir/file3 >> $seqres.full
68 _test_cycle_mount
69
70 echo "Compare files"
71 md5sum $testdir/file1 | _filter_test_dir
72 md5sum $testdir/file2 | _filter_test_dir
73 md5sum $testdir/file3 | _filter_test_dir
74
75 cmp -s $testdir/file1 $testdir/file2 || echo "Files 1-2 do not match (intentional)"
76 cmp -s $testdir/file1 $testdir/file3 || echo "Files 1-3 do not match (intentional)"
77 cmp -s $testdir/file2 $testdir/file3 || echo "Files 2-3 do not match"
78
79 echo "Compare the CoW'd section to the before file"
80 _compare_range $testdir/file1 0 $testdir/file2 0 17 \
81        || echo "Start sections do not match (intentional)"
82
83 _compare_range  $testdir/file1 $((blksz * 16 - 34)) \
84                 $testdir/file2 $((blksz * 16 - 34)) 17 \
85        || echo "Middle sections do not match (intentional)"
86
87 _compare_range  $testdir/file1 $((blksz * 48 - 8)) \
88                 $testdir/file2 $((blksz * 48 - 8)) 17 \
89        || echo "End sections do not match (intentional)"
90
91 echo "Compare the CoW'd section to the after file"
92 _compare_range $testdir/file2 0 $testdir/file3 0 17 \
93        || echo "Start sections do not match"
94
95 _compare_range  $testdir/file2 $((blksz * 16 - 34)) \
96                 $testdir/file3 $((blksz * 16 - 34)) 17 \
97        || echo "Middle sections do not match"
98
99 _compare_range  $testdir/file2 $((blksz * 48 - 8)) \
100                 $testdir/file3 $((blksz * 48 - 8)) 17 \
101        || echo "End sections do not match"
102
103 echo "Compare the not CoW'd sections"
104 _compare_range $testdir/file1 18 $testdir/file2 18 17 \
105        || echo "Start sections of 1-2 do not match"
106
107 _compare_range $testdir/file2 18 $testdir/file3 18 17 \
108        || echo "Start sections of 2-3 do not match"
109
110
111 _compare_range  $testdir/file1 $((blksz * 16 - 17)) \
112                 $testdir/file2 $((blksz * 16 - 17)) 82 \
113        || echo "Middle sections of 1-2 do not match"
114
115 _compare_range  $testdir/file2 $((blksz * 16 - 17)) \
116                 $testdir/file3 $((blksz * 16 - 17)) 82 \
117        || echo "Middle sections of 2-3 do not match"
118
119 _compare_range  $testdir/file1 $((blksz * 48 - 108)) \
120                 $testdir/file2 $((blksz * 48 - 108)) 100 \
121        || echo "End sections of 1-2 do not match"
122
123 _compare_range  $testdir/file2 $((blksz * 48 - 108)) \
124                 $testdir/file3 $((blksz * 48 - 108)) 100 \
125        || echo "End sections of 2-3 do not match"
126
127
128 _compare_range  $testdir/file1 $((blksz * 14)) \
129                 $testdir/file2 $((blksz * 14)) $blksz \
130        || echo "Untouched sections of 1-2 do not match"
131
132 _compare_range  $testdir/file2 $((blksz * 14)) \
133                 $testdir/file3 $((blksz * 14)) $blksz \
134        || echo "Untouched sections of 2-3 do not match"
135
136 # success, all done
137 status=0
138 exit