2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
7 # Ensure that deleting 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 # - Delete some copies of the file
12 # - Record fs block usage (2)
13 # - Delete all copies of the file
14 # - Compare fs block usage to (2), (1), and (0)
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
22 status=1 # failure is the default!
23 trap "_cleanup; exit \$status" 0 1 2 3 15
28 rm -rf $tmp.* $testdir
31 # get standard environment, filters and checks
36 # real QA test starts here
43 testdir=$TEST_DIR/test-$seq
47 echo "Create the original file blocks"
48 blksz="$(_get_block_size $testdir)"
52 free_blocks0=$(stat -f $testdir -c '%f')
54 filesize=$((blksz * nr))
55 _pwrite_byte 0x61 0 $sz $testdir/file1 >> $seqres.full
58 echo "Create the reflink copies"
59 for i in `seq 2 $nr`; do
60 _cp_reflink $testdir/file1 $testdir/file.$i
62 _cp_reflink $testdir/file1 $testdir/survivor
64 free_blocks1=$(stat -f $testdir -c '%f')
66 echo "Delete most of the files"
69 free_blocks2=$(stat -f $testdir -c '%f')
71 echo "Delete all the files"
74 free_blocks3=$(stat -f $testdir -c '%f')
75 #echo $free_blocks0 $free_blocks1 $free_blocks2 $free_blocks3
77 _within_tolerance "free blocks after reflink" $free_blocks1 $((free_blocks0 - blks)) $margin -v
79 _within_tolerance "free blocks after deleting some reflink copies" $free_blocks2 $free_blocks1 $margin -v
81 _within_tolerance "free blocks after deleting all copies" $free_blocks3 $free_blocks0 $margin -v