common: add leading underscore to get_block_size
[xfstests-dev.git] / tests / xfs / 132
1 #! /bin/bash
2 # FS QA Test No. 132
3 #
4 # Ensure that fallocate on reflinked files actually CoWs the shared blocks.
5 #   - Record fs block usage (0)
6 #   - Create a file and some reflink copies
7 #   - Record fs block usage (1)
8 #   - funshare half of one of the copies
9 #   - Record fs block usage (2)
10 #   - funshare all of the copies
11 #   - Record fs block usage (3)
12 #   - rewrite the original file
13 #   - Record fs block usage (4)
14 #   - Compare fs block usage of 0-4 to ensure that block usage behaves as
15 #     we expect.
16 #   - Compare the status of the inode reflink flag at each step.
17 #
18 # "funshare" refers to fallocate copy-on-writing the shared blocks
19 #
20 # This is the same test as generic/156 except that we also check the inode
21 # reflink flag.
22 #
23 #-----------------------------------------------------------------------
24 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
25 #
26 # This program is free software; you can redistribute it and/or
27 # modify it under the terms of the GNU General Public License as
28 # published by the Free Software Foundation.
29 #
30 # This program is distributed in the hope that it would be useful,
31 # but WITHOUT ANY WARRANTY; without even the implied warranty of
32 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33 # GNU General Public License for more details.
34 #
35 # You should have received a copy of the GNU General Public License
36 # along with this program; if not, write the Free Software Foundation,
37 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
38 #-----------------------------------------------------------------------
39
40 seq=`basename $0`
41 seqres=$RESULT_DIR/$seq
42 echo "QA output created by $seq"
43
44 here=`pwd`
45 tmp=/tmp/$$
46 status=1    # failure is the default!
47 trap "_cleanup; exit \$status" 0 1 2 3 15
48
49 _cleanup()
50 {
51     cd /
52     rm -rf $tmp.* $testdir
53 }
54
55 # get standard environment, filters and checks
56 . ./common/rc
57 . ./common/filter
58 . ./common/attr
59 . ./common/reflink
60
61 # real QA test starts here
62 _supported_os Linux
63 _require_test_reflink
64 _require_test_lsattr
65 _require_cp_reflink
66 _require_xfs_io_command "funshare"
67
68 rm -f $seqres.full
69
70 testdir=$TEST_DIR/test-$seq
71 rm -rf $testdir
72 mkdir $testdir
73
74 echo "Create the original file blocks"
75 blksz="$(_get_block_size $testdir)"
76 blks=2000
77 margin=100
78 sz=$((blksz * blks))
79 free_blocks0=$(stat -f $testdir -c '%f')
80 nr=4
81 filesize=$((blksz * nr))
82 _pwrite_byte 0x61 0 $sz $testdir/file1 >> $seqres.full
83 _test_cycle_mount
84
85 echo "Create the reflink copies"
86 for i in `seq 2 $nr`; do
87         _cp_reflink $testdir/file1 $testdir/file$i
88 done
89 _test_cycle_mount
90 free_blocks1=$(stat -f $testdir -c '%f')
91
92 echo "funshare part of a file"
93 $XFS_IO_PROG -f -c "funshare 0 $((sz / 2))" $testdir/file2
94 _test_cycle_mount
95
96 echo "funshare some of the copies"
97 $XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file2
98 $XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file3
99 _test_cycle_mount
100 free_blocks2=$(stat -f $testdir -c '%f')
101
102 echo "funshare the rest of the files"
103 $XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file4
104 $XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file1
105 _test_cycle_mount
106 free_blocks3=$(stat -f $testdir -c '%f')
107
108 echo "Rewrite the original file"
109 _pwrite_byte 0x65 0 $sz $testdir/file1 >> $seqres.full
110 _test_cycle_mount
111 free_blocks4=$(stat -f $testdir -c '%f')
112 #echo $free_blocks0 $free_blocks1 $free_blocks2 $free_blocks3 $free_blocks4
113
114 _within_tolerance "free blocks after reflinking" $free_blocks1 $((free_blocks0 - blks)) $margin -v
115
116 _within_tolerance "free blocks after nocow'ing some copies" $free_blocks2 $((free_blocks1 - (2 * blks))) $margin -v
117
118 _within_tolerance "free blocks after nocow'ing all copies" $free_blocks3 $((free_blocks2 - blks)) $margin -v
119
120 _within_tolerance "free blocks after overwriting original" $free_blocks4 $free_blocks3 $margin -v
121
122 _within_tolerance "free blocks after all tests" $free_blocks4 $((free_blocks0 - (4 * blks))) $margin -v
123
124 # success, all done
125 status=0
126 exit