generic/554: hide permision warning on exfat
[xfstests-dev.git] / tests / generic / 151
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. 151
6 #
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)
15 #
16 seq=`basename $0`
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
19
20 here=`pwd`
21 tmp=/tmp/$$
22 status=1    # failure is the default!
23 trap "_cleanup; exit \$status" 0 1 2 3 15
24
25 _cleanup()
26 {
27     cd /
28     rm -rf $tmp.* $testdir
29 }
30
31 # get standard environment, filters and checks
32 . ./common/rc
33 . ./common/filter
34 . ./common/reflink
35
36 # real QA test starts here
37 _require_test_reflink
38 _require_cp_reflink
39
40 rm -f $seqres.full
41
42 testdir=$TEST_DIR/test-$seq
43 rm -rf $testdir
44 mkdir $testdir
45
46 echo "Create the original file blocks"
47 blksz="$(_get_block_size $testdir)"
48 blks=2000
49 margin='15%'
50 sz=$((blksz * blks))
51 free_blocks0=$(stat -f $testdir -c '%f')
52 nr=7
53 filesize=$((blksz * nr))
54 _pwrite_byte 0x61 0 $sz $testdir/file1 >> $seqres.full
55 sync
56
57 echo "Create the reflink copies"
58 for i in `seq 2 $nr`; do
59         _cp_reflink $testdir/file1 $testdir/file.$i
60 done
61 _cp_reflink $testdir/file1 $testdir/survivor
62 _test_cycle_mount
63 free_blocks1=$(stat -f $testdir -c '%f')
64
65 echo "Delete most of the files"
66 rm -rf $testdir/file*
67 _test_cycle_mount
68 free_blocks2=$(stat -f $testdir -c '%f')
69
70 echo "Delete all the files"
71 rm -rf $testdir/*
72 _test_cycle_mount
73 free_blocks3=$(stat -f $testdir -c '%f')
74 #echo $free_blocks0 $free_blocks1 $free_blocks2 $free_blocks3
75
76 _within_tolerance "free blocks after reflink" $free_blocks1 $((free_blocks0 - blks)) $margin -v
77
78 _within_tolerance "free blocks after deleting some reflink copies" $free_blocks2 $free_blocks1 $margin -v
79
80 _within_tolerance "free blocks after deleting all copies" $free_blocks3 $free_blocks0 $margin -v
81
82 # success, all done
83 status=0
84 exit