2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
7 # Ensure that xfs_fsr un-reflinks files while defragmenting
10 _begin_fstest auto quick clone fsr
12 # Import common functions.
16 # real QA test starts here
19 _require_scratch_reflink
21 _require_xfs_io_command "falloc"
23 echo "Format and mount"
24 _scratch_mkfs > $seqres.full 2>&1
25 _scratch_mount >> $seqres.full 2>&1
27 testdir=$SCRATCH_MNT/test-$seq
29 free_blocks0=$(stat -f $testdir -c '%f')
31 echo "Create the original file and reflink to file2, file3"
35 real_blksz="$(_get_block_size $testdir)"
36 blksz_factor=$((blksz / real_blksz))
37 _pwrite_byte 0x61 0 $((blks * blksz)) $testdir/file1 >> $seqres.full
38 _cp_reflink $testdir/file1 $testdir/file2
39 _cp_reflink $testdir/file2 $testdir/file3
40 _cp_reflink $testdir/file3 $testdir/file4
42 free_blocks1=$(stat -f $testdir -c '%f')
44 md5sum $testdir/file1 | _filter_scratch
45 md5sum $testdir/file2 | _filter_scratch
46 md5sum $testdir/file3 | _filter_scratch
47 md5sum $testdir/file4 | _filter_scratch
49 c01=$(_md5_checksum $testdir/file1)
50 c02=$(_md5_checksum $testdir/file2)
51 c03=$(_md5_checksum $testdir/file3)
52 c04=$(_md5_checksum $testdir/file4)
54 echo "CoW the reflink copies"
55 _pwrite_byte 0x62 $blksz $blksz $testdir/file2 >> $seqres.full
56 _pwrite_byte 0x63 $(( blksz * (blks - 1) )) $blksz $testdir/file3 >> $seqres.full
58 free_blocks2=$(stat -f $testdir -c '%f')
60 md5sum $testdir/file1 | _filter_scratch
61 md5sum $testdir/file2 | _filter_scratch
62 md5sum $testdir/file3 | _filter_scratch
63 md5sum $testdir/file4 | _filter_scratch
65 c11=$(_md5_checksum $testdir/file1)
66 c12=$(_md5_checksum $testdir/file2)
67 c13=$(_md5_checksum $testdir/file3)
68 c14=$(_md5_checksum $testdir/file4)
71 lsattr -l $testdir/ | _filter_scratch | _filter_spaces
72 $XFS_FSR_PROG -v -d $testdir/file1 >> $seqres.full
73 $XFS_FSR_PROG -v -d $testdir/file2 >> $seqres.full # fsr probably breaks the link
74 $XFS_FSR_PROG -v -d $testdir/file3 >> $seqres.full # fsr probably breaks the link
75 $XFS_FSR_PROG -v -d $testdir/file4 >> $seqres.full # fsr probably ignores this file
77 free_blocks3=$(stat -f $testdir -c '%f')
79 md5sum $testdir/file1 | _filter_scratch
80 md5sum $testdir/file2 | _filter_scratch
81 md5sum $testdir/file3 | _filter_scratch
82 md5sum $testdir/file4 | _filter_scratch
84 c21=$(_md5_checksum $testdir/file1)
85 c22=$(_md5_checksum $testdir/file2)
86 c23=$(_md5_checksum $testdir/file3)
87 c24=$(_md5_checksum $testdir/file4)
90 test $c01 = $c02 || echo "Files 1-2 do not match"
91 test $c01 = $c03 || echo "Files 1-3 do not match"
92 test $c01 = $c04 || echo "Files 1-4 do not match"
93 test $c02 = $c03 || echo "Files 2-3 do not match"
94 test $c02 = $c04 || echo "Files 2-4 do not match"
95 test $c03 = $c04 || echo "Files 3-4 do not match"
97 test $c01 = $c11 || echo "File1 should not be different after CoW"
98 test $c02 != $c12 || echo "File2 should be different after CoW"
99 test $c03 != $c13 || echo "File3 should be different after CoW"
100 test $c04 = $c14 || echo "File4 should not be different after CoW"
102 test $c11 = $c21 || echo "File1 changed by defrag"
103 test $c12 = $c22 || echo "File2 changed by defrag"
104 test $c13 = $c23 || echo "File3 changed by defrag"
105 test $c14 = $c24 || echo "File4 changed by defrag"
107 #echo $free_blocks0 $free_blocks1 $free_blocks2 $free_blocks3
109 _within_tolerance "free blocks after creating some reflink copies" $free_blocks1 $((free_blocks0 - (blks * blksz_factor) )) $margin -v
110 _within_tolerance "free blocks after CoW some reflink copies" $free_blocks2 $((free_blocks1 - 2)) $margin -v
111 _within_tolerance "free blocks after defragging all reflink copies" $free_blocks3 $((free_blocks2 - (blks * 2 * blksz_factor))) $margin -v
112 _within_tolerance "free blocks after all tests" $free_blocks3 $((free_blocks0 - (blks * 3 * blksz_factor))) $margin -v