fstests: move test group info to test files
[xfstests-dev.git] / tests / generic / 152
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. 152
6 #
7 # Ensure that punching 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 #   - Punch some blocks of the copies
12 #   - Record fs block usage (2)
13 #   - Punch all blocks of the copies
14 #   - Compare fs block usage to (2), (1), and (0)
15 #
16 . ./common/preamble
17 _begin_fstest auto quick clone punch
18
19 # Override the default cleanup function.
20 _cleanup()
21 {
22     cd /
23     rm -rf $tmp.* $testdir
24 }
25
26 # Import common functions.
27 . ./common/filter
28 . ./common/reflink
29
30 # real QA test starts here
31 _require_test_reflink
32 _require_cp_reflink
33 _require_xfs_io_command "fpunch"
34
35 testdir=$TEST_DIR/test-$seq
36 rm -rf $testdir
37 mkdir $testdir
38
39 echo "Create the original file blocks"
40 blksz="$(_get_block_size $testdir)"
41 blks=2000
42 margin='15%'
43 sz=$((blksz * blks))
44 free_blocks0=$(stat -f $testdir -c '%f')
45 nr=4
46 filesize=$((blksz * nr))
47 _pwrite_byte 0x61 0 $sz $testdir/file1 >> $seqres.full
48 sync
49
50 echo "Create the reflink copies"
51 for i in `seq 2 $nr`; do
52         _cp_reflink $testdir/file1 $testdir/file$i
53 done
54 _test_cycle_mount
55 free_blocks1=$(stat -f $testdir -c '%f')
56
57 echo "Punch most of the blocks"
58 $XFS_IO_PROG -f -c "fpunch 0 $sz" $testdir/file2
59 $XFS_IO_PROG -f -c "fpunch 0 $((sz / 2))" $testdir/file3
60 $XFS_IO_PROG -f -c "fpunch $((sz / 2)) $((sz / 2))" $testdir/file4
61 _test_cycle_mount
62 free_blocks2=$(stat -f $testdir -c '%f')
63
64 echo "Punch all the files"
65 for i in `seq 2 $nr`; do
66         $XFS_IO_PROG -f -c "fpunch 0 $sz" $testdir/file$i
67 done
68 $XFS_IO_PROG -f -c "fpunch 0 $sz" $testdir/file1
69 _test_cycle_mount
70 free_blocks3=$(stat -f $testdir -c '%f')
71 #echo $free_blocks0 $free_blocks1 $free_blocks2 $free_blocks3
72
73 _within_tolerance "free blocks after reflink" $free_blocks1 $((free_blocks0 - blks)) $margin -v
74
75 _within_tolerance "free blocks after punching some reflink copies" $free_blocks2 $free_blocks1 $margin -v
76
77 _within_tolerance "free blocks after punching all copies" $free_blocks3 $free_blocks0 $margin -v
78
79 # success, all done
80 status=0
81 exit