common: kill _supported_os
[xfstests-dev.git] / tests / generic / 256
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2011 IBM Corporation.  All Rights Reserved.
4 #
5 # FS QA Test No. 256
6 #
7 # Test Full File System Hole Punching
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16
17 _cleanup()
18 {
19     rm -f $tmp.*
20 }
21
22 trap "_cleanup ; exit \$status" 0 1 2 3 15
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/populate
27 . ./common/filter
28 . ./common/punch
29
30 # real QA test starts here
31 _supported_fs generic
32
33 _require_xfs_io_command "fpunch"
34 _require_scratch
35 _require_user
36 _require_test
37
38 testfile=$TEST_DIR/256.$$
39
40 # _test_full_fs_punch()
41 #
42 # This function will test that a hole may be punched
43 # even when the file system is full.  Reserved blocks
44 # should be used to allow a punch hole to proceed even
45 # when there is not enough blocks to further fragment the
46 # file. To test this, this function will fragment the file
47 # system by punching holes in regular intervals and filling
48 # the file system between punches.
49 #
50 _test_full_fs_punch()
51 {
52         local hole_len=$1      # The length of the holes to punch
53         local hole_interval=$2 # The interval between the holes
54         local iterations=$3    # The number of holes to punch
55         local file_name=$4     # File to punch holes in
56         local block_size=$5    # File system block size
57         local file_len=$(( $(( $hole_len + $hole_interval )) * $iterations ))
58         local path=`dirname $file_name`
59         local hole_offset=0
60
61         if [ $# -ne 5 ]
62         then
63                 echo "USAGE: _test_full_fs_punch hole_len hole_interval iterations file_name block_size"
64                 exit 1
65         fi
66
67         rm -f $file_name &> /dev/null
68
69         $XFS_IO_PROG -f -c "pwrite 0 $file_len" \
70                 -c "fsync" $file_name &> /dev/null
71         chmod 666 $file_name
72
73         # All files are created as a non root user to prevent reserved blocks
74         # from being consumed.
75         _fill_fs $(( 1024 * 1024 * 1024 )) $path/fill $block_size 1 \
76                 > /dev/null 2>&1
77
78         for (( i=0; i<$iterations; i++ ))
79         do
80                 # This part must not be done as root in order to
81                 # test that reserved blocks are used when needed
82                 _user_do "$XFS_IO_PROG -f -c \"fpunch $hole_offset $hole_len\" $file_name"
83                 rc=$?
84                 if [ $? -ne 0 ] ; then
85                         echo Punch hole failed
86                         break
87                 fi
88
89                 hole_offset=$(( $hole_offset + $hole_len + $hole_interval ))
90
91                 _fill_fs $hole_len $path/fill.$i $block_size 1 > /dev/null 2>&1
92
93         done
94 }
95
96 # Make a small file system to fill
97 _scratch_unmount &> /dev/null
98 _scratch_mkfs_sized $(( 1536 * 1024 * 1024 )) &> /dev/null
99 _scratch_mount
100 # Test must be able to write files with non-root permissions
101 chmod 777 $SCRATCH_MNT
102
103 block_size=`_get_block_size $SCRATCH_MNT`
104 _test_full_fs_punch $(( $block_size * 2 )) $block_size 500 $SCRATCH_MNT/252.$$ $block_size
105
106 status=0 ; exit