2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
7 # Ensure that collapse-range on all copies of a file reflinked N times releases the blocks
8 # - Record fs block usage (0)
9 # - Create a file and some reflink copies
10 # - Record fs block usage (1)
11 # - Collapse-range some blocks of the copies
12 # - Record fs block usage (2)
13 # - Truncate all blocks of the copies
14 # - Compare fs block usage to (2), (1), and (0)
17 _begin_fstest auto quick clone collapse
19 # Override the default cleanup function.
23 rm -rf $tmp.* $testdir
26 # Import common functions.
30 # real QA test starts here
33 _require_xfs_io_command "fcollapse"
35 testdir=$TEST_DIR/test-$seq
39 echo "Create the original file blocks"
40 blksz="$(_get_block_size $testdir)"
44 free_blocks0=$(stat -f $testdir -c '%f')
46 filesize=$((blksz * nr))
47 _pwrite_byte 0x61 0 $sz $testdir/file1 >> $seqres.full
50 echo "Create the reflink copies"
51 for i in `seq 2 $nr`; do
52 _cp_reflink $testdir/file1 $testdir/file$i
55 free_blocks1=$(stat -f $testdir -c '%f')
57 echo "Collapse most of the blocks"
58 $XFS_IO_PROG -f -c "fcollapse 0 $(((blks - 1) * blksz))" $testdir/file2
59 $XFS_IO_PROG -f -c "fcollapse 0 $((sz / 2))" $testdir/file3
60 $XFS_IO_PROG -f -c "fcollapse $((sz / 2)) $(( ((blks / 2) - 1) * blksz))" $testdir/file4
62 free_blocks2=$(stat -f $testdir -c '%f')
64 echo "Collpase nearly all the files"
65 $XFS_IO_PROG -f -c "fcollapse 0 $(( ((blks / 2) - 1) * blksz))" $testdir/file3
66 $XFS_IO_PROG -f -c "fcollapse 0 $((sz / 2))" $testdir/file4
67 $XFS_IO_PROG -f -c "fcollapse 0 $(( (blks - 1) * blksz))" $testdir/file1
69 free_blocks3=$(stat -f $testdir -c '%f')
70 #echo $free_blocks0 $free_blocks1 $free_blocks2 $free_blocks3
72 _within_tolerance "free blocks after reflink" $free_blocks1 $((free_blocks0 - blks)) $margin -v
74 _within_tolerance "free blocks after fcollapsing some reflink copies" $free_blocks2 $free_blocks1 $margin -v
76 _within_tolerance "free blocks after fcollapsing all copies" $free_blocks3 $free_blocks0 $margin -v