generic/611: Use _getfattr instead of GETFATTR_PROG
[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 _require_test_reflink
34 _require_cp_reflink
35 _require_xfs_io_command "falloc"
36 _require_xfs_io_command "truncate"
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 * 5 + 37)) $testdir/file1 >> $seqres.full
47
48 _reflink_range $testdir/file1 $blksz $testdir/file2 $blksz \
49                 $((blksz * 4 + 37)) >> $seqres.full
50
51 $XFS_IO_PROG -f -c "truncate $((blksz * 5 + 37))" $testdir/file3 >> $seqres.full
52 _reflink_range $testdir/file1 0 $testdir/file3 0 $blksz >> $seqres.full
53
54 $XFS_IO_PROG -f -c "truncate $((blksz * 5 + 37))" $testdir/file4 >> $seqres.full
55 _reflink_range $testdir/file1 $blksz $testdir/file4 $blksz $blksz >> $seqres.full
56 _reflink_range $testdir/file1 $((blksz * 3)) $testdir/file4 $((blksz * 3)) \
57                 $blksz >> $seqres.full
58
59 _cp_reflink $testdir/file1 $testdir/file5
60 _test_cycle_mount
61
62 echo "Compare sections"
63 md5sum $testdir/file1 | _filter_test_dir
64 md5sum $testdir/file2 | _filter_test_dir
65 md5sum $testdir/file3 | _filter_test_dir
66 md5sum $testdir/file4 | _filter_test_dir
67 md5sum $testdir/file5 | _filter_test_dir
68
69 _compare_range $testdir/file1 $blksz $testdir/file2 $blksz \
70                 $((blksz * 4 + 37)) \
71         || echo "shared parts of files 1-2 changed"
72
73 _compare_range $testdir/file1 0 $testdir/file3 0 $blksz \
74         || echo "shared parts of files 1-3 changed"
75
76 _compare_range $testdir/file1 $blksz $testdir/file4 $blksz $blksz \
77         || echo "shared parts of files 1-4 changed"
78
79 _compare_range $testdir/file1 0 $testdir/file5 0 $((blksz * 5 + 37)) \
80         || echo "shared parts of files 1-5 changed"
81
82 echo "Compare files"
83 c1=$(_md5_checksum $testdir/file1)
84 c2=$(_md5_checksum $testdir/file2)
85 c3=$(_md5_checksum $testdir/file3)
86 c4=$(_md5_checksum $testdir/file4)
87 c5=$(_md5_checksum $testdir/file5)
88
89 test ${c1} != ${c2} || echo "file1 and file2 should not match"
90 test ${c1} != ${c3} || echo "file1 and file3 should not match"
91 test ${c1} != ${c4} || echo "file1 and file4 should not match"
92 test ${c1}  = ${c5} || echo "file1 and file5 should match"
93 test ${c2} != ${c3} || echo "file2 and file3 should not match"
94 test ${c2} != ${c4} || echo "file2 and file4 should not match"
95 test ${c2} != ${c5} || echo "file2 and file5 should not match"
96 test ${c3} != ${c4} || echo "file3 and file4 should not match"
97 test ${c3} != ${c5} || echo "file3 and file5 should not match"
98 test ${c4} != ${c5} || echo "file4 and file5 should not match"
99
100 echo "falloc everything"
101 $XFS_IO_PROG -f -c "falloc 0 $((blksz * 5))" $testdir/file2 >> $seqres.full
102 $XFS_IO_PROG -f -c "falloc 0 $((blksz * 5))" $testdir/file3 >> $seqres.full
103 $XFS_IO_PROG -f -c "falloc 0 $((blksz * 5))" $testdir/file4 >> $seqres.full
104 _test_cycle_mount
105
106 echo "Compare files"
107 md5sum $testdir/file1 | _filter_test_dir
108 md5sum $testdir/file2 | _filter_test_dir
109 md5sum $testdir/file3 | _filter_test_dir
110 md5sum $testdir/file4 | _filter_test_dir
111 md5sum $testdir/file5 | _filter_test_dir
112
113 d1=$(_md5_checksum $testdir/file1)
114 d2=$(_md5_checksum $testdir/file2)
115 d3=$(_md5_checksum $testdir/file3)
116 d4=$(_md5_checksum $testdir/file4)
117 d5=$(_md5_checksum $testdir/file5)
118
119 test ${c1} = ${d1} || echo "file1 should not change"
120 test ${c2} = ${d2} || echo "file2 should not change"
121 test ${c3} = ${d3} || echo "file3 should not change"
122 test ${c4} = ${d4} || echo "file4 should not change"
123 test ${c5} = ${d5} || echo "file2 should not change"
124
125 # success, all done
126 status=0
127 exit