fstests: use _require_symlinks on all necessary tests
[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 _supported_os Linux
33
34 _require_xfs_io_command "fpunch"
35 _require_scratch
36 _require_user
37 _require_test
38
39 testfile=$TEST_DIR/256.$$
40
41 # _test_full_fs_punch()
42 #
43 # This function will test that a hole may be punched
44 # even when the file system is full.  Reserved blocks
45 # should be used to allow a punch hole to proceed even
46 # when there is not enough blocks to further fragment the
47 # file. To test this, this function will fragment the file
48 # system by punching holes in regular intervals and filling
49 # the file system between punches.
50 #
51 _test_full_fs_punch()
52 {
53         local hole_len=$1      # The length of the holes to punch
54         local hole_interval=$2 # The interval between the holes
55         local iterations=$3    # The number of holes to punch
56         local file_name=$4     # File to punch holes in
57         local block_size=$5    # File system block size
58         local file_len=$(( $(( $hole_len + $hole_interval )) * $iterations ))
59         local path=`dirname $file_name`
60         local hole_offset=0
61
62         if [ $# -ne 5 ]
63         then
64                 echo "USAGE: _test_full_fs_punch hole_len hole_interval iterations file_name block_size"
65                 exit 1
66         fi
67
68         rm -f $file_name &> /dev/null
69
70         $XFS_IO_PROG -f -c "pwrite 0 $file_len" \
71                 -c "fsync" $file_name &> /dev/null
72         chmod 666 $file_name
73
74         # All files are created as a non root user to prevent reserved blocks
75         # from being consumed.
76         _fill_fs $(( 1024 * 1024 * 1024 )) $path/fill $block_size 1 \
77                 > /dev/null 2>&1
78
79         for (( i=0; i<$iterations; i++ ))
80         do
81                 # This part must not be done as root in order to
82                 # test that reserved blocks are used when needed
83                 _user_do "$XFS_IO_PROG -f -c \"fpunch $hole_offset $hole_len\" $file_name"
84                 rc=$?
85                 if [ $? -ne 0 ] ; then
86                         echo Punch hole failed
87                         break
88                 fi
89
90                 hole_offset=$(( $hole_offset + $hole_len + $hole_interval ))
91
92                 _fill_fs $hole_len $path/fill.$i $block_size 1 > /dev/null 2>&1
93
94         done
95 }
96
97 # Make a small file system to fill
98 _scratch_unmount &> /dev/null
99 _scratch_mkfs_sized $(( 1536 * 1024 * 1024 )) &> /dev/null
100 _scratch_mount
101 # Test must be able to write files with non-root permissions
102 chmod 777 $SCRATCH_MNT
103
104 block_size=`_get_block_size $SCRATCH_MNT`
105 _test_full_fs_punch $(( $block_size * 2 )) $block_size 500 $SCRATCH_MNT/252.$$ $block_size
106
107 status=0 ; exit