generic/405: test mkfs against thin provision device
[xfstests-dev.git] / tests / generic / 256
1 #! /bin/bash
2 # FS QA Test No. 256
3 #
4 # Test Full File System Hole Punching
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2011 IBM Corporation.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #
22 #-----------------------------------------------------------------------
23 #
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32
33 _cleanup()
34 {
35     rm -f $tmp.*
36 }
37
38 trap "_cleanup ; exit \$status" 0 1 2 3 15
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/populate
43 . ./common/filter
44 . ./common/punch
45
46 # real QA test starts here
47 _supported_fs generic
48 _supported_os Linux
49
50 _require_xfs_io_command "fpunch"
51 _require_scratch
52 _require_user
53 _require_test
54
55 testfile=$TEST_DIR/256.$$
56
57 # _test_full_fs_punch()
58 #
59 # This function will test that a hole may be punched
60 # even when the file system is full.  Reserved blocks
61 # should be used to allow a punch hole to proceed even
62 # when there is not enough blocks to further fragment the
63 # file. To test this, this function will fragment the file
64 # system by punching holes in regular intervals and filling
65 # the file system between punches.
66 #
67 _test_full_fs_punch()
68 {
69         local hole_len=$1      # The length of the holes to punch
70         local hole_interval=$2 # The interval between the holes
71         local iterations=$3    # The number of holes to punch
72         local file_name=$4     # File to punch holes in
73         local block_size=$5    # File system block size
74         local file_len=$(( $(( $hole_len + $hole_interval )) * $iterations ))
75         local path=`dirname $file_name`
76         local hole_offset=0
77
78         if [ $# -ne 5 ]
79         then
80                 echo "USAGE: _test_full_fs_punch hole_len hole_interval iterations file_name block_size"
81                 exit 1
82         fi
83
84         rm -f $file_name &> /dev/null
85
86         $XFS_IO_PROG -f -c "pwrite 0 $file_len" \
87                 -c "fsync" $file_name &> /dev/null
88         chmod 666 $file_name
89
90         # All files are created as a non root user to prevent reserved blocks
91         # from being consumed.
92         _fill_fs $(( 1024 * 1024 * 1024 )) $path/fill $block_size 1 \
93                 > /dev/null 2>&1
94
95         for (( i=0; i<$iterations; i++ ))
96         do
97                 # This part must not be done as root in order to
98                 # test that reserved blocks are used when needed
99                 _user_do "$XFS_IO_PROG -f -c \"fpunch $hole_offset $hole_len\" $file_name"
100                 rc=$?
101                 if [ $? -ne 0 ] ; then
102                         echo Punch hole failed
103                         break
104                 fi
105
106                 hole_offset=$(( $hole_offset + $hole_len + $hole_interval ))
107
108                 _fill_fs $hole_len $path/fill.$i $block_size 1 > /dev/null 2>&1
109
110         done
111 }
112
113 # Make a small file system to fill
114 _scratch_unmount &> /dev/null
115 _scratch_mkfs_sized $(( 1536 * 1024 * 1024 )) &> /dev/null
116 _scratch_mount
117 # Test must be able to write files with non-root permissions
118 chmod 777 $SCRATCH_MNT
119
120 block_size=`_get_block_size $SCRATCH_MNT`
121 _test_full_fs_punch $(( $block_size * 2 )) $block_size 500 $SCRATCH_MNT/252.$$ $block_size
122
123 status=0 ; exit