4 # Ensure that CoW on all copies of a file reflinked N times increases block count
5 # - Record fs block usage (0)
6 # - Create a file and some reflink copies
7 # - Record fs block usage (1)
8 # - CoW some blocks of the copies
9 # - Record fs block usage (2)
10 # - CoW all the rest of the blocks of the copies
11 # - Compare fs block usage to (2), (1), and (0)
13 #-----------------------------------------------------------------------
14 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #-----------------------------------------------------------------------
31 seqres=$RESULT_DIR/$seq
32 echo "QA output created by $seq"
36 status=1 # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
42 rm -rf $tmp.* $testdir
45 # get standard environment, filters and checks
50 # real QA test starts here
57 testdir=$TEST_DIR/test-$seq
61 echo "Create the original file blocks"
62 blksz="$(_get_block_size $testdir)"
65 free_blocks0=$(stat -f $testdir -c '%f')
67 filesize=$((blksz * nr))
69 _pwrite_byte 0x61 0 $sz $testdir/file1 >> $seqres.full
72 echo "Create the reflink copies"
73 for i in `seq 2 $nr`; do
74 _cp_reflink $testdir/file1 $testdir/file$i
77 free_blocks1=$(stat -f $testdir -c '%f')
79 echo "Rewrite some of the blocks"
80 _pwrite_byte 0x62 0 $sz $testdir/file2 >> $seqres.full
81 _pwrite_byte 0x63 0 $((sz / 2)) $testdir/file3 >> $seqres.full
82 _pwrite_byte 0x64 $((sz / 2)) $((sz / 2)) $testdir/file4 >> $seqres.full
84 free_blocks2=$(stat -f $testdir -c '%f')
86 echo "Rewrite all the files"
87 _pwrite_byte 0x62 0 $sz $testdir/file2 >> $seqres.full
88 _pwrite_byte 0x63 0 $sz $testdir/file3 >> $seqres.full
89 _pwrite_byte 0x64 0 $sz $testdir/file4 >> $seqres.full
91 free_blocks3=$(stat -f $testdir -c '%f')
93 echo "Rewrite the original file"
94 _pwrite_byte 0x65 0 $sz $testdir/file1 >> $seqres.full
96 free_blocks4=$(stat -f $testdir -c '%f')
97 #echo $free_blocks0 $free_blocks1 $free_blocks2 $free_blocks3 $free_blocks4
99 _within_tolerance "free blocks after reflinking" $free_blocks1 $((free_blocks0 - blks)) $margin -v
101 _within_tolerance "free blocks after partially CoWing some copies" $free_blocks2 $((free_blocks1 - (2 * blks))) $margin -v
103 _within_tolerance "free blocks after CoWing all copies" $free_blocks3 $((free_blocks2 - blks)) $margin -v
105 _within_tolerance "free blocks after overwriting original" $free_blocks4 $free_blocks3 $margin -v
107 _within_tolerance "free blocks after all tests" $free_blocks4 $((free_blocks0 - (4 * blks))) $margin -v