generic: add _require_odirect to generic/113 and generic/214
[xfstests-dev.git] / tests / generic / 155
1 #! /bin/bash
2 # FS QA Test No. 155
3 #
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)
12 #
13 # The main difference from 834 is that we use zero range, directio, and
14 # mmap to mix things up a bit.
15 #
16 #-----------------------------------------------------------------------
17 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
18 #
19 # This program is free software; you can redistribute it and/or
20 # modify it under the terms of the GNU General Public License as
21 # published by the Free Software Foundation.
22 #
23 # This program is distributed in the hope that it would be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 # GNU General Public License for more details.
27 #
28 # You should have received a copy of the GNU General Public License
29 # along with this program; if not, write the Free Software Foundation,
30 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
31 #-----------------------------------------------------------------------
32
33 seq=`basename $0`
34 seqres=$RESULT_DIR/$seq
35 echo "QA output created by $seq"
36
37 here=`pwd`
38 tmp=/tmp/$$
39 status=1    # failure is the default!
40 trap "_cleanup; exit \$status" 0 1 2 3 15
41
42 _cleanup()
43 {
44     cd /
45     rm -rf $tmp.* $testdir
46 }
47
48 # get standard environment, filters and checks
49 . ./common/rc
50 . ./common/filter
51 . ./common/reflink
52
53 # real QA test starts here
54 _supported_os Linux
55 _require_test_reflink
56 _require_cp_reflink
57 _require_xfs_io_command "fzero"
58 _require_odirect
59
60 rm -f $seqres.full
61
62 testdir=$TEST_DIR/test-$seq
63 rm -rf $testdir
64 mkdir $testdir
65
66 echo "Create the original file blocks"
67 blksz="$(stat -f $testdir -c '%S')"
68 blks=2000
69 margin='15%'
70 sz=$((blksz * blks))
71 free_blocks0=$(stat -f $testdir -c '%f')
72 nr=4
73 filesize=$((blksz * nr))
74 _pwrite_byte 0x61 0 $sz $testdir/file1 >> $seqres.full
75 _test_remount
76
77 echo "Create the reflink copies"
78 for i in `seq 2 $nr`; do
79         _cp_reflink $testdir/file1 $testdir/file$i
80 done
81 _test_remount
82 free_blocks1=$(stat -f $testdir -c '%f')
83
84 echo "Rewrite some of the blocks"
85 $XFS_IO_PROG -f -c "fzero 0 $sz" $testdir/file2 >> $seqres.full
86 _pwrite_byte 0x63 0 $((sz / 2)) $testdir/file3 -d >> $seqres.full
87 _mwrite_byte 0x64 $((sz / 2)) $((sz / 2)) $sz $testdir/file4 >> $seqres.full
88 _test_remount
89 free_blocks2=$(stat -f $testdir -c '%f')
90
91 echo "Rewrite all the files"
92 _pwrite_byte 0x62 0 $sz $testdir/file2 -d >> $seqres.full
93 _mwrite_byte 0x63 0 $sz $sz $testdir/file3 >> $seqres.full
94 $XFS_IO_PROG -f -c "fzero 0 $sz" $testdir/file4 >> $seqres.full
95 _test_remount
96 free_blocks3=$(stat -f $testdir -c '%f')
97
98 echo "Rewrite the original file"
99 _pwrite_byte 0x65 0 $sz $testdir/file1 >> $seqres.full
100 _test_remount
101 free_blocks4=$(stat -f $testdir -c '%f')
102 #echo $free_blocks0 $free_blocks1 $free_blocks2 $free_blocks3 $free_blocks4
103
104 _within_tolerance "free blocks after reflinking" $free_blocks1 $((free_blocks0 - blks)) $margin -v
105
106 _within_tolerance "free blocks after partially CoWing some copies" $free_blocks2 $((free_blocks1 - (2 * blks))) $margin -v
107
108 _within_tolerance "free blocks after CoWing all copies" $free_blocks3 $((free_blocks2 - blks)) $margin -v
109
110 _within_tolerance "free blocks after overwriting original" $free_blocks4 $free_blocks3 $margin -v
111
112 _within_tolerance "free blocks after all tests" $free_blocks4 $((free_blocks0 - (4 * blks))) $margin -v
113
114 # success, all done
115 status=0
116 exit