xfs/419: remove irrelevant swapfile test
[xfstests-dev.git] / tests / xfs / 076
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. xfs/076
6 #
7 # Verify that a filesystem with sparse inode support can allocate inodes in the
8 # event of free space fragmentation. This test is generic in nature but
9 # primarily relevant to filesystems that implement dynamic inode allocation
10 # (e.g., XFS).
11 #
12 # The test is inspired by inode allocation limitations on XFS when available
13 # free space is fragmented. XFS allocates inodes 64 at a time and thus requires
14 # an extent of length that depends on inode size (64 * isize / blksize).
15 #
16 # The test creates a small, sparse inode enabled filesystem. It fragments free
17 # space, allocates inodes to ENOSPC and then verifies that most of the available
18 # inodes (.i.e., free space) have been consumed.
19 #
20 seq=`basename $0`
21 seqres=$RESULT_DIR/$seq
22 echo "QA output created by $seq"
23
24 here=`pwd`
25 tmp=/tmp/$$
26 status=1        # failure is the default!
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31
32 _cleanup()
33 {
34         cd /
35         _scratch_unmount 2>/dev/null
36         rm -f $tmp.*
37 }
38 trap "_cleanup; exit \$status" 0 1 2 3 15
39
40 _consume_freesp()
41 {
42         file=$1
43
44         # consume nearly all available space (leave ~1MB)
45         avail=`_get_available_space $SCRATCH_MNT`
46         filesizemb=$((avail / 1024 / 1024 - 1))
47         $XFS_IO_PROG -fc "falloc 0 ${filesizemb}m" $file
48 }
49
50 # Allocate inodes in a directory until failure.
51 _alloc_inodes()
52 {
53         dir=$1
54
55         i=0
56         while [ true ]; do
57                 touch $dir/$i 2>> $seqres.full || break
58                 i=$((i + 1))
59         done
60 }
61
62 # real QA test starts here
63
64 _require_scratch
65 _require_xfs_io_command "falloc"
66 _require_xfs_io_command "fpunch"
67 _require_xfs_sparse_inodes
68
69 rm -f $seqres.full
70
71 _scratch_mkfs "-d size=50m -m crc=1 -i sparse" |
72         _filter_mkfs > /dev/null 2> $tmp.mkfs
73 . $tmp.mkfs     # for isize
74
75 _scratch_mount
76
77 # Calculate the fs inode chunk size based on the inode size and fixed 64-inode
78 # record. This value is used as the target level of free space fragmentation
79 # induced by the test (i.e., max size of free extents). We don't need to go
80 # smaller than a full chunk because the XFS block allocator tacks on alignment
81 # requirements to the size of the requested allocation. In other words, a chunk
82 # sized free chunk is not enough to guarantee a successful chunk sized
83 # allocation.
84 CHUNK_SIZE=$((isize * 64))
85
86 _consume_freesp $SCRATCH_MNT/spc
87
88 # Now that the fs is nearly full, punch holes in every other $CHUNK_SIZE range
89 # of the space consumer file. This should ensure that most freed extents are not
90 # contiguous with any others and thus sufficiently fragment free space. After
91 # each hole punch, allocate as many inodes as possible into the newly freed
92 # space. Note that we start at the end of the file and work backwards as a
93 # reverse allocation pattern increases the chances of both left and right sparse
94 # record merges.
95 offset=`_get_filesize $SCRATCH_MNT/spc`
96 offset=$((offset - $CHUNK_SIZE * 2))
97 while [ $offset -ge 0 ]; do
98         $XFS_IO_PROG -c "fpunch $offset $CHUNK_SIZE" $SCRATCH_MNT/spc \
99                 2>> $seqres.full || _fail "fpunch failed"
100
101         # allocate as many inodes as possible
102         mkdir -p $SCRATCH_MNT/offset.$offset > /dev/null 2>&1
103         _alloc_inodes $SCRATCH_MNT/offset.$offset
104
105         offset=$((offset - $CHUNK_SIZE * 2))
106 done
107
108 # check that we've hit at least 95% inode usage
109 iusepct=`_get_used_inode_percent $SCRATCH_MNT`
110 _within_tolerance "iusepct" $iusepct 100 5 0 -v
111
112 status=0
113 exit