common/rc: add _scratch_{u}mount_idmapped() helpers
[xfstests-dev.git] / tests / generic / 119
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. 119
6 #
7 # Reflinking two sets of files together:
8 #   - Reflink identical parts of two identical files
9 #   - Reflink identical parts of two other identical files
10 #   - Reflink identical parts of all four files
11 #   - Check that we end up with identical contents
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1    # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24     cd /
25     rm -rf $tmp.* $testdir
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31 . ./common/reflink
32
33 # real QA test starts here
34 _require_test_reflink
35 _require_arbitrary_fileset_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 * 8)) $testdir/file1 >> $seqres.full
46 _pwrite_byte 0x62 0 $((blksz * 8)) $testdir/file2 >> $seqres.full
47 _pwrite_byte 0x63 0 $((blksz * 8)) $testdir/file3 >> $seqres.full
48 _pwrite_byte 0x64 0 $((blksz * 8)) $testdir/file4 >> $seqres.full
49 _test_cycle_mount
50
51 md5sum $testdir/file1 | _filter_test_dir
52 md5sum $testdir/file2 | _filter_test_dir
53 md5sum $testdir/file3 | _filter_test_dir
54 md5sum $testdir/file4 | _filter_test_dir
55
56 _compare_range $testdir/file1 0 $testdir/file2 0 $((blksz * 8)) \
57        || echo "Files 1-2 do not match (intentional)"
58
59 _compare_range $testdir/file1 0 $testdir/file3 0 $((blksz * 8)) \
60        || echo "Files 1-3 do not match (intentional)"
61
62 _compare_range $testdir/file1 0 $testdir/file4 0 $((blksz * 8)) \
63        || echo "Files 1-4 do not match (intentional)"
64
65 echo "Reflink the first four blocks together, 1-2 3-4"
66 free_before=$(stat -f -c '%a' $testdir)
67 _reflink_range $testdir/file1 0 $testdir/file2 0 $((blksz * 4)) >> $seqres.full
68 _reflink_range $testdir/file3 0 $testdir/file4 0 $((blksz * 4)) >> $seqres.full
69 _test_cycle_mount
70 free_after=$(stat -f -c '%a' $testdir)
71 echo "freesp changed by $free_before -> $free_after" >> $seqres.full
72
73 echo "Compare sections"
74 md5sum $testdir/file1 | _filter_test_dir
75 md5sum $testdir/file2 | _filter_test_dir
76 md5sum $testdir/file3 | _filter_test_dir
77 md5sum $testdir/file4 | _filter_test_dir
78
79 _compare_range $testdir/file1 0 $testdir/file2 0 $((blksz * 4)) \
80        || echo "Sections of file 1-2 do not match"
81
82 _compare_range $testdir/file1 0 $testdir/file3 0 $((blksz * 4)) \
83        || echo "Sections of file 1-3 do not match (intentional)"
84
85 _compare_range $testdir/file1 0 $testdir/file4 0 $((blksz * 4)) \
86        || echo "Sections of file 1-4 do not match (intentional)"
87
88 _compare_range $testdir/file2 0 $testdir/file3 0 $((blksz * 4)) \
89        || echo "Sections of file 2-3 do not match (intentional)"
90
91 _compare_range $testdir/file2 0 $testdir/file4 0 $((blksz * 4)) \
92        || echo "Sections of file 2-4 do not match (intentional)"
93
94 _compare_range $testdir/file3 0 $testdir/file4 0 $((blksz * 4)) \
95        || echo "Sections of file 3-4 do not match"
96
97 echo "Reflink the first two blocks together, 1-3 1-4"
98 free_before=$(stat -f -c '%a' $testdir)
99 _reflink_range $testdir/file1 0 $testdir/file3 0 $((blksz * 2)) >> $seqres.full
100 _reflink_range $testdir/file1 0 $testdir/file4 0 $((blksz * 2)) >> $seqres.full
101 _test_cycle_mount
102 free_after=$(stat -f -c '%a' $testdir)
103 echo "freesp changed by $free_before -> $free_after" >> $seqres.full
104
105 echo "Compare sections"
106 md5sum $testdir/file1 | _filter_test_dir
107 md5sum $testdir/file2 | _filter_test_dir
108 md5sum $testdir/file3 | _filter_test_dir
109 md5sum $testdir/file4 | _filter_test_dir
110
111 _compare_range $testdir/file1 0 $testdir/file2 0 $((blksz * 2)) \
112        || echo "Sections of files 1-2 do not match"
113
114 _compare_range $testdir/file1 0 $testdir/file3 0 $((blksz * 2)) \
115        || echo "Sections of files 1-3 do not match"
116
117 _compare_range $testdir/file1 0 $testdir/file4 0 $((blksz * 2)) \
118        || echo "Sections of files 1-4 do not match"
119
120 _compare_range $testdir/file2 0 $testdir/file3 0 $((blksz * 2)) \
121        || echo "Sections of files 2-3 do not match"
122
123 _compare_range $testdir/file2 0 $testdir/file4 0 $((blksz * 2)) \
124        || echo "Sections of files 2-4 do not match"
125
126 _compare_range $testdir/file3 0 $testdir/file4 0 $((blksz * 2)) \
127        || echo "Sections of files 3-4 do not match"
128
129 echo "Compare previously reflinked sections"
130 _compare_range $testdir/file1 $((blksz * 2)) $testdir/file2 \
131                 $((blksz * 2)) $((blksz * 2)) \
132        || echo "Sections of file 1-2 do not match"
133
134 _compare_range $testdir/file1 $((blksz * 2)) $testdir/file3 \
135                 $((blksz * 2)) $((blksz * 2)) \
136        || echo "Sections of file 1-3 do not match (intentional)"
137
138 _compare_range $testdir/file1 $((blksz * 2)) $testdir/file4 \
139                 $((blksz * 2)) $((blksz * 2)) \
140        || echo "Sections of file 1-4 do not match (intentional)"
141
142 _compare_range $testdir/file2 $((blksz * 2)) $testdir/file3 \
143                 $((blksz * 2)) $((blksz * 2)) \
144        || echo "Sections of file 2-3 do not match (intentional)"
145
146 _compare_range $testdir/file2 $((blksz * 2)) $testdir/file4 \
147                 $((blksz * 2)) $((blksz * 2)) \
148        || echo "Sections of file 2-4 do not match (intentional)"
149
150 _compare_range $testdir/file3 $((blksz * 2)) $testdir/file4 \
151                 $((blksz * 2)) $((blksz * 2)) \
152        || echo "Sections of file 3-4 do not match"
153
154 # success, all done
155 status=0
156 exit