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
16 # - Compare the status of the inode reflink flag at each step.
18 # "funshare" refers to fallocate copy-on-writing the shared blocks
20 # This is the same test as generic/156 except that we also check the inode
23 #-----------------------------------------------------------------------
24 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
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.
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.
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 #-----------------------------------------------------------------------
41 seqres=$RESULT_DIR/$seq
42 echo "QA output created by $seq"
46 status=1 # failure is the default!
47 trap "_cleanup; exit \$status" 0 1 2 3 15
52 rm -rf $tmp.* $testdir
55 # get standard environment, filters and checks
61 # real QA test starts here
66 _require_xfs_io_command "funshare"
70 testdir=$TEST_DIR/test-$seq
74 echo "Create the original file blocks"
75 blksz="$(get_block_size $testdir)"
79 free_blocks0=$(stat -f $testdir -c '%f')
81 filesize=$((blksz * nr))
82 _pwrite_byte 0x61 0 $sz $testdir/file1 >> $seqres.full
85 echo "Create the reflink copies"
86 for i in `seq 2 $nr`; do
87 _cp_reflink $testdir/file1 $testdir/file$i
90 free_blocks1=$(stat -f $testdir -c '%f')
92 echo "funshare part of a file"
93 $XFS_IO_PROG -f -c "funshare 0 $((sz / 2))" $testdir/file2
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
100 free_blocks2=$(stat -f $testdir -c '%f')
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
106 free_blocks3=$(stat -f $testdir -c '%f')
108 echo "Rewrite the original file"
109 _pwrite_byte 0x65 0 $sz $testdir/file1 >> $seqres.full
111 free_blocks4=$(stat -f $testdir -c '%f')
112 #echo $free_blocks0 $free_blocks1 $free_blocks2 $free_blocks3 $free_blocks4
114 _within_tolerance "free blocks after reflinking" $free_blocks1 $((free_blocks0 - blks)) $margin -v
116 _within_tolerance "free blocks after nocow'ing some copies" $free_blocks2 $((free_blocks1 - (2 * blks))) $margin -v
118 _within_tolerance "free blocks after nocow'ing all copies" $free_blocks3 $((free_blocks2 - blks)) $margin -v
120 _within_tolerance "free blocks after overwriting original" $free_blocks4 $free_blocks3 $margin -v
122 _within_tolerance "free blocks after all tests" $free_blocks4 $((free_blocks0 - (4 * blks))) $margin -v