xfs/007: fix regressions on V4 filesystems
[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 . ./common/preamble
13 _begin_fstest auto enospc growfs
14
15 create_file()
16 {
17         local dir=$1
18         local i=0
19         local in_growfs=false
20
21         # keep running until failed after growfs
22         while true; do
23                 [ -f $tmp.growfs ] && in_growfs=true
24                 while echo -n >$dir/testfile_$i; do
25                         let i=$i+1
26                 done
27                 $in_growfs && break
28                 usleep 1000
29         done
30 }
31
32 # Import common functions.
33 . ./common/filter
34
35 # real QA test starts here
36 _supported_fs xfs
37
38 _require_scratch
39
40 # need 128M space, don't make any assumption
41 _scratch_mkfs >/dev/null 2>&1
42 _scratch_mount
43 _require_fs_space $SCRATCH_MNT 131072
44 _scratch_unmount
45
46 _scratch_mkfs_sized $((32 * 1024 * 1024)) > $tmp.mkfs.raw
47 cat $tmp.mkfs.raw | _filter_mkfs >$seqres.full 2>$tmp.mkfs
48 # get original data blocks number and agcount
49 . $tmp.mkfs
50 _scratch_mount
51
52 nr_worker=$((agcount * 2))
53 echo "Fork $nr_worker workers to consume free inodes in background" >>$seqres.full
54 (
55         i=0
56         while [ $i -lt $nr_worker ]; do
57                 mkdir $SCRATCH_MNT/testdir_$i
58                 create_file $SCRATCH_MNT/testdir_$i &
59                 let i=$i+1
60         done
61         wait
62 ) >/dev/null 2>&1 &
63
64 # Grow fs at the same time, at least x4
65 # doubling or tripling the size couldn't reproduce
66 echo "Grow fs to $((dblocks * 4)) blocks" >>$seqres.full
67 $XFS_GROWFS_PROG -D $((dblocks * 4)) $SCRATCH_MNT >>$seqres.full
68
69 # mark xfs_growfs finished to create_file
70 touch $tmp.growfs
71
72 # Wait for background create_file to hit ENOSPC
73 wait
74
75 # log inode status in $seqres.full for debug purpose
76 echo "Inode status after growing fs" >>$seqres.full
77 $DF_PROG -i $SCRATCH_MNT >>$seqres.full
78
79 # inode should be at least 99% used
80 total_inode=`_get_total_inode $SCRATCH_MNT`
81 used_inode=`_get_used_inode $SCRATCH_MNT`
82 _within_tolerance "used inodes" $used_inode $total_inode %1 -v
83
84 status=$?
85 exit