xfs: Check for extent overflow when trivally adding a new extent
[xfstests-dev.git] / tests / xfs / 015
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Red Hat Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. xfs/015
6 #
7 # Make sure inodes can be allocated in new space added by xfs_growfs
8 #
9 # Regression test for
10 # xfs: allow inode allocations in post-growfs disk space
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23     cd /
24     rm -f $tmp.*
25 }
26
27 create_file()
28 {
29         local dir=$1
30         local i=0
31         local in_growfs=false
32
33         # keep running until failed after growfs
34         while true; do
35                 [ -f $tmp.growfs ] && in_growfs=true
36                 while echo -n >$dir/testfile_$i; do
37                         let i=$i+1
38                 done
39                 $in_growfs && break
40                 usleep 1000
41         done
42 }
43
44 # get standard environment, filters and checks
45 . ./common/rc
46 . ./common/filter
47
48 # real QA test starts here
49 _supported_fs xfs
50
51 _require_scratch
52
53 # need 128M space, don't make any assumption
54 _scratch_mkfs >/dev/null 2>&1
55 _scratch_mount
56 _require_fs_space $SCRATCH_MNT 131072
57 _scratch_unmount
58
59 rm -f $seqres.full
60
61 _scratch_mkfs_sized $((32 * 1024 * 1024)) > $tmp.mkfs.raw
62 cat $tmp.mkfs.raw | _filter_mkfs >$seqres.full 2>$tmp.mkfs
63 # get original data blocks number and agcount
64 . $tmp.mkfs
65 _scratch_mount
66
67 nr_worker=$((agcount * 2))
68 echo "Fork $nr_worker workers to consume free inodes in background" >>$seqres.full
69 (
70         i=0
71         while [ $i -lt $nr_worker ]; do
72                 mkdir $SCRATCH_MNT/testdir_$i
73                 create_file $SCRATCH_MNT/testdir_$i &
74                 let i=$i+1
75         done
76         wait
77 ) >/dev/null 2>&1 &
78
79 # Grow fs at the same time, at least x4
80 # doubling or tripling the size couldn't reproduce
81 echo "Grow fs to $((dblocks * 4)) blocks" >>$seqres.full
82 $XFS_GROWFS_PROG -D $((dblocks * 4)) $SCRATCH_MNT >>$seqres.full
83
84 # mark xfs_growfs finished to create_file
85 touch $tmp.growfs
86
87 # Wait for background create_file to hit ENOSPC
88 wait
89
90 # log inode status in $seqres.full for debug purpose
91 echo "Inode status after growing fs" >>$seqres.full
92 $DF_PROG -i $SCRATCH_MNT >>$seqres.full
93
94 # inode should be at least 99% used
95 total_inode=`_get_total_inode $SCRATCH_MNT`
96 used_inode=`_get_used_inode $SCRATCH_MNT`
97 _within_tolerance "used inodes" $used_inode $total_inode %1 -v
98
99 status=$?
100 exit