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
17 # "funshare" refers to fallocate copy-on-writing the shared blocks
19 #-----------------------------------------------------------------------
20 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
22 # This program is free software; you can redistribute it and/or
23 # modify it under the terms of the GNU General Public License as
24 # published by the Free Software Foundation.
26 # This program is distributed in the hope that it would be useful,
27 # but WITHOUT ANY WARRANTY; without even the implied warranty of
28 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 # GNU General Public License for more details.
31 # You should have received a copy of the GNU General Public License
32 # along with this program; if not, write the Free Software Foundation,
33 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 #-----------------------------------------------------------------------
37 seqres=$RESULT_DIR/$seq
38 echo "QA output created by $seq"
42 status=1 # failure is the default!
43 trap "_cleanup; exit \$status" 0 1 2 3 15
48 rm -rf $tmp.* $testdir
51 # get standard environment, filters and checks
57 # real QA test starts here
61 _require_xfs_io_command "funshare"
65 testdir=$TEST_DIR/test-$seq
69 echo "Create the original file blocks"
70 blksz="$(get_block_size $testdir)"
74 free_blocks0=$(stat -f $testdir -c '%f')
76 filesize=$((blksz * nr))
77 _pwrite_byte 0x61 0 $sz $testdir/file1 >> $seqres.full
80 echo "Create the reflink copies"
81 for i in `seq 2 $nr`; do
82 _cp_reflink $testdir/file1 $testdir/file$i
85 free_blocks1=$(stat -f $testdir -c '%f')
87 echo "funshare part of a file"
88 $XFS_IO_PROG -f -c "funshare 0 $((sz / 2))" $testdir/file2
91 echo "funshare some of the copies"
92 $XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file2
93 $XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file3
95 free_blocks2=$(stat -f $testdir -c '%f')
97 echo "funshare the rest of the files"
98 $XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file4
99 $XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file1
101 free_blocks3=$(stat -f $testdir -c '%f')
103 echo "Rewrite the original file"
104 _pwrite_byte 0x65 0 $sz $testdir/file1 >> $seqres.full
106 free_blocks4=$(stat -f $testdir -c '%f')
107 #echo $free_blocks0 $free_blocks1 $free_blocks2 $free_blocks3 $free_blocks4
109 _within_tolerance "free blocks after reflinking" $free_blocks1 $((free_blocks0 - blks)) $margin -v
111 _within_tolerance "free blocks after nocow'ing some copies" $free_blocks2 $((free_blocks1 - (2 * blks))) $margin -v
113 _within_tolerance "free blocks after nocow'ing all copies" $free_blocks3 $((free_blocks2 - blks)) $margin -v
115 _within_tolerance "free blocks after overwriting original" $free_blocks4 $free_blocks3 $margin -v
117 _within_tolerance "free blocks after all tests" $free_blocks4 $((free_blocks0 - (4 * blks))) $margin -v