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 "falloc"
70 testdir=$TEST_DIR/test-$seq
74 echo "Create the original file blocks"
75 blksz="$(stat -f $testdir -c '%S')"
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')
91 lsattr -l $testdir/ | _filter_test_dir | _filter_spaces
93 echo "funshare part of a file"
94 $XFS_IO_PROG -f -c "falloc 0 $((sz / 2))" $testdir/file2
96 lsattr -l $testdir/ | _filter_test_dir | _filter_spaces
98 echo "funshare some of the copies"
99 $XFS_IO_PROG -f -c "falloc 0 $sz" $testdir/file2
100 $XFS_IO_PROG -f -c "falloc 0 $sz" $testdir/file3
102 free_blocks2=$(stat -f $testdir -c '%f')
103 lsattr -l $testdir/ | _filter_test_dir | _filter_spaces
105 echo "funshare the rest of the files"
106 $XFS_IO_PROG -f -c "falloc 0 $sz" $testdir/file4
107 $XFS_IO_PROG -f -c "falloc 0 $sz" $testdir/file1
109 free_blocks3=$(stat -f $testdir -c '%f')
110 lsattr -l $testdir/ | _filter_test_dir | _filter_spaces
112 echo "Rewrite the original file"
113 _pwrite_byte 0x65 0 $sz $testdir/file1 >> $seqres.full
115 free_blocks4=$(stat -f $testdir -c '%f')
116 lsattr -l $testdir/ | _filter_test_dir | _filter_spaces
117 #echo $free_blocks0 $free_blocks1 $free_blocks2 $free_blocks3 $free_blocks4
119 _within_tolerance "free blocks after reflinking" $free_blocks1 $((free_blocks0 - blks)) $margin -v
121 _within_tolerance "free blocks after nocow'ing some copies" $free_blocks2 $((free_blocks1 - (2 * blks))) $margin -v
123 _within_tolerance "free blocks after nocow'ing all copies" $free_blocks3 $((free_blocks2 - blks)) $margin -v
125 _within_tolerance "free blocks after overwriting original" $free_blocks4 $free_blocks3 $margin -v
127 _within_tolerance "free blocks after all tests" $free_blocks4 $((free_blocks0 - (4 * blks))) $margin -v