xfs: fix more xfs_db open-coding instances
[xfstests-dev.git] / tests / xfs / 015
1 #! /bin/bash
2 # FS QA Test No. xfs/015
3 #
4 # Make sure inodes can be allocated in new space added by xfs_growfs
5 #
6 # Regression test for
7 # xfs: allow inode allocations in post-growfs disk space
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2014 Red Hat Inc.  All Rights Reserved.
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #-----------------------------------------------------------------------
25 #
26
27 seq=`basename $0`
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38     cd /
39     rm -f $tmp.*
40 }
41
42 create_file()
43 {
44         local dir=$1
45         local i=0
46         local in_growfs=false
47
48         # keep running until failed after growfs
49         while true; do
50                 [ -f $tmp.growfs ] && in_growfs=true
51                 while echo -n >$dir/testfile_$i; do
52                         let i=$i+1
53                 done
54                 $in_growfs && break
55                 usleep 1000
56         done
57 }
58
59 # get standard environment, filters and checks
60 . ./common/rc
61 . ./common/filter
62
63 # real QA test starts here
64 _supported_fs xfs
65 _supported_os Linux
66
67 _require_scratch
68
69 # need 64M space, don't make any assumption
70 _scratch_mkfs >/dev/null 2>&1
71 _scratch_mount
72 _require_fs_space $SCRATCH_MNT 65536
73 _scratch_unmount
74
75 rm -f $seqres.full
76
77 _scratch_mkfs_sized $((16 * 1024 * 1024)) | _filter_mkfs >$seqres.full 2>$tmp.mkfs
78 # get original data blocks number and agcount
79 . $tmp.mkfs
80 _scratch_mount
81
82 nr_worker=$((agcount * 2))
83 echo "Fork $nr_worker workers to consume free inodes in background" >>$seqres.full
84 (
85         i=0
86         while [ $i -lt $nr_worker ]; do
87                 mkdir $SCRATCH_MNT/testdir_$i
88                 create_file $SCRATCH_MNT/testdir_$i &
89                 let i=$i+1
90         done
91         wait
92 ) >/dev/null 2>&1 &
93
94 # Grow fs at the same time, at least x4
95 # doubling or tripling the size couldn't reproduce
96 echo "Grow fs to $((dblocks * 4)) blocks" >>$seqres.full
97 $XFS_GROWFS_PROG -D $((dblocks * 4)) $SCRATCH_MNT >>$seqres.full
98
99 # mark xfs_growfs finished to create_file
100 touch $tmp.growfs
101
102 # Wait for background create_file to hit ENOSPC
103 wait
104
105 # log inode status in $seqres.full for debug purpose
106 echo "Inode status after growing fs" >>$seqres.full
107 $DF_PROG -i $SCRATCH_MNT >>$seqres.full
108
109 # inode should be at least 99% used
110 total_inode=`_get_total_inode $SCRATCH_MNT`
111 used_inode=`_get_used_inode $SCRATCH_MNT`
112 _within_tolerance "used inodes" $used_inode $total_inode %1 -v
113
114 status=$?
115 exit