lib/: spdx license conversion
[xfstests-dev.git] / tests / generic / 144
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. 144
6 #
7 # Ensure that fallocate steps around reflinked ranges:
8 #   - Reflink parts of two files together
9 #   - Fallocate all the other sparse space.
10 #   - Check that the reflinked areas are still there.
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_xfs_io_command "falloc"
37 _require_xfs_io_command "truncate"
38
39 rm -f $seqres.full
40
41 testdir=$TEST_DIR/test-$seq
42 rm -rf $testdir
43 mkdir $testdir
44
45 echo "Create the original files"
46 blksz=65536
47 _pwrite_byte 0x61 0 $((blksz * 5 + 37)) $testdir/file1 >> $seqres.full
48
49 _reflink_range $testdir/file1 $blksz $testdir/file2 $blksz \
50                 $((blksz * 4 + 37)) >> $seqres.full
51
52 $XFS_IO_PROG -f -c "truncate $((blksz * 5 + 37))" $testdir/file3 >> $seqres.full
53 _reflink_range $testdir/file1 0 $testdir/file3 0 $blksz >> $seqres.full
54
55 $XFS_IO_PROG -f -c "truncate $((blksz * 5 + 37))" $testdir/file4 >> $seqres.full
56 _reflink_range $testdir/file1 $blksz $testdir/file4 $blksz $blksz >> $seqres.full
57 _reflink_range $testdir/file1 $((blksz * 3)) $testdir/file4 $((blksz * 3)) \
58                 $blksz >> $seqres.full
59
60 _cp_reflink $testdir/file1 $testdir/file5
61 _test_cycle_mount
62
63 echo "Compare sections"
64 md5sum $testdir/file1 | _filter_test_dir
65 md5sum $testdir/file2 | _filter_test_dir
66 md5sum $testdir/file3 | _filter_test_dir
67 md5sum $testdir/file4 | _filter_test_dir
68 md5sum $testdir/file5 | _filter_test_dir
69
70 _compare_range $testdir/file1 $blksz $testdir/file2 $blksz \
71                 $((blksz * 4 + 37)) \
72         || echo "shared parts of files 1-2 changed"
73
74 _compare_range $testdir/file1 0 $testdir/file3 0 $blksz \
75         || echo "shared parts of files 1-3 changed"
76
77 _compare_range $testdir/file1 $blksz $testdir/file4 $blksz $blksz \
78         || echo "shared parts of files 1-4 changed"
79
80 _compare_range $testdir/file1 0 $testdir/file5 0 $((blksz * 5 + 37)) \
81         || echo "shared parts of files 1-5 changed"
82
83 echo "Compare files"
84 c1=$(_md5_checksum $testdir/file1)
85 c2=$(_md5_checksum $testdir/file2)
86 c3=$(_md5_checksum $testdir/file3)
87 c4=$(_md5_checksum $testdir/file4)
88 c5=$(_md5_checksum $testdir/file5)
89
90 test ${c1} != ${c2} || echo "file1 and file2 should not match"
91 test ${c1} != ${c3} || echo "file1 and file3 should not match"
92 test ${c1} != ${c4} || echo "file1 and file4 should not match"
93 test ${c1}  = ${c5} || echo "file1 and file5 should match"
94 test ${c2} != ${c3} || echo "file2 and file3 should not match"
95 test ${c2} != ${c4} || echo "file2 and file4 should not match"
96 test ${c2} != ${c5} || echo "file2 and file5 should not match"
97 test ${c3} != ${c4} || echo "file3 and file4 should not match"
98 test ${c3} != ${c5} || echo "file3 and file5 should not match"
99 test ${c4} != ${c5} || echo "file4 and file5 should not match"
100
101 echo "falloc everything"
102 $XFS_IO_PROG -f -c "falloc 0 $((blksz * 5))" $testdir/file2 >> $seqres.full
103 $XFS_IO_PROG -f -c "falloc 0 $((blksz * 5))" $testdir/file3 >> $seqres.full
104 $XFS_IO_PROG -f -c "falloc 0 $((blksz * 5))" $testdir/file4 >> $seqres.full
105 _test_cycle_mount
106
107 echo "Compare files"
108 md5sum $testdir/file1 | _filter_test_dir
109 md5sum $testdir/file2 | _filter_test_dir
110 md5sum $testdir/file3 | _filter_test_dir
111 md5sum $testdir/file4 | _filter_test_dir
112 md5sum $testdir/file5 | _filter_test_dir
113
114 d1=$(_md5_checksum $testdir/file1)
115 d2=$(_md5_checksum $testdir/file2)
116 d3=$(_md5_checksum $testdir/file3)
117 d4=$(_md5_checksum $testdir/file4)
118 d5=$(_md5_checksum $testdir/file5)
119
120 test ${c1} = ${d1} || echo "file1 should not change"
121 test ${c2} = ${d2} || echo "file2 should not change"
122 test ${c3} = ${d3} || echo "file3 should not change"
123 test ${c4} = ${d4} || echo "file4 should not change"
124 test ${c5} = ${d5} || echo "file2 should not change"
125
126 # success, all done
127 status=0
128 exit