4 # Ensure that xfs_fsr un-reflinks files while defragmenting
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #-----------------------------------------------------------------------
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
30 status=1 # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
39 # get standard environment, filters and checks
44 # real QA test starts here
48 _require_scratch_reflink
51 echo "Format and mount"
52 _scratch_mkfs > $seqres.full 2>&1
53 _scratch_mount >> $seqres.full 2>&1
55 testdir=$SCRATCH_MNT/test-$seq
57 free_blocks0=$(stat -f $testdir -c '%f')
59 echo "Create the original file and reflink to file2, file3"
63 real_blksz="$(stat -f $testdir -c '%S')"
64 blksz_factor=$((blksz / real_blksz))
65 _pwrite_byte 0x61 0 $((blks * blksz)) $testdir/file1 >> $seqres.full
66 _cp_reflink $testdir/file1 $testdir/file2
67 _cp_reflink $testdir/file2 $testdir/file3
68 _cp_reflink $testdir/file3 $testdir/file4
70 free_blocks1=$(stat -f $testdir -c '%f')
72 md5sum $testdir/file1 | _filter_scratch
73 md5sum $testdir/file2 | _filter_scratch
74 md5sum $testdir/file3 | _filter_scratch
75 md5sum $testdir/file4 | _filter_scratch
77 c01=$(_md5_checksum $testdir/file1)
78 c02=$(_md5_checksum $testdir/file2)
79 c03=$(_md5_checksum $testdir/file3)
80 c04=$(_md5_checksum $testdir/file4)
82 echo "CoW the reflink copies"
83 _pwrite_byte 0x62 $blksz $blksz $testdir/file2 >> $seqres.full
84 _pwrite_byte 0x63 $(( blksz * (blks - 1) )) $blksz $testdir/file3 >> $seqres.full
86 free_blocks2=$(stat -f $testdir -c '%f')
88 md5sum $testdir/file1 | _filter_scratch
89 md5sum $testdir/file2 | _filter_scratch
90 md5sum $testdir/file3 | _filter_scratch
91 md5sum $testdir/file4 | _filter_scratch
93 c11=$(_md5_checksum $testdir/file1)
94 c12=$(_md5_checksum $testdir/file2)
95 c13=$(_md5_checksum $testdir/file3)
96 c14=$(_md5_checksum $testdir/file4)
99 lsattr -l $testdir/ | _filter_scratch | _filter_spaces
100 xfs_fsr -v -d $testdir/file1 >> $seqres.full
101 xfs_fsr -v -d $testdir/file2 >> $seqres.full # fsr probably breaks the link
102 xfs_fsr -v -d $testdir/file3 >> $seqres.full # fsr probably breaks the link
103 xfs_fsr -v -d $testdir/file4 >> $seqres.full # fsr probably ignores this file
105 free_blocks3=$(stat -f $testdir -c '%f')
107 md5sum $testdir/file1 | _filter_scratch
108 md5sum $testdir/file2 | _filter_scratch
109 md5sum $testdir/file3 | _filter_scratch
110 md5sum $testdir/file4 | _filter_scratch
112 c21=$(_md5_checksum $testdir/file1)
113 c22=$(_md5_checksum $testdir/file2)
114 c23=$(_md5_checksum $testdir/file3)
115 c24=$(_md5_checksum $testdir/file4)
118 test $c01 = $c02 || echo "Files 1-2 do not match"
119 test $c01 = $c03 || echo "Files 1-3 do not match"
120 test $c01 = $c04 || echo "Files 1-4 do not match"
121 test $c02 = $c03 || echo "Files 2-3 do not match"
122 test $c02 = $c04 || echo "Files 2-4 do not match"
123 test $c03 = $c04 || echo "Files 3-4 do not match"
125 test $c01 = $c11 || echo "File1 should not be different after CoW"
126 test $c02 != $c12 || echo "File2 should be different after CoW"
127 test $c03 != $c13 || echo "File3 should be different after CoW"
128 test $c04 = $c14 || echo "File4 should not be different after CoW"
130 test $c11 = $c21 || echo "File1 changed by defrag"
131 test $c12 = $c22 || echo "File2 changed by defrag"
132 test $c13 = $c23 || echo "File3 changed by defrag"
133 test $c14 = $c24 || echo "File4 changed by defrag"
135 #echo $free_blocks0 $free_blocks1 $free_blocks2 $free_blocks3
137 _within_tolerance "free blocks after creating some reflink copies" $free_blocks1 $((free_blocks0 - (blks * blksz_factor) )) $margin -v
138 _within_tolerance "free blocks after CoW some reflink copies" $free_blocks2 $((free_blocks1 - 2)) $margin -v
139 _within_tolerance "free blocks after defragging all reflink copies" $free_blocks3 $((free_blocks2 - (blks * 2 * blksz_factor))) $margin -v
140 _within_tolerance "free blocks after all tests" $free_blocks3 $((free_blocks0 - (blks * 3 * blksz_factor))) $margin -v