2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2009 Christoph Hellwig.
7 # Test out ENOSPC flushing on small filesystems.
10 _begin_fstest metadata rw auto
12 # Override the default cleanup function.
19 # Import common functions.
22 # real QA test starts here
27 # get the block size first
28 _scratch_mkfs 2> /dev/null | _filter_mkfs 2> $tmp.mkfs > /dev/null
31 # For xfs, we need to handle the different default log sizes that different
32 # versions of mkfs create. All should be valid with a 16MB log, so use that.
33 # And v4/512 v5/1k xfs don't have enough free inodes, set imaxpct=50 at mkfs
34 # time solves this problem.
35 [ $FSTYP = "xfs" ] && MKFS_OPTIONS="$MKFS_OPTIONS -l size=16m -i maxpct=50"
37 SIZE=`expr 115 \* 1024 \* 1024`
38 _scratch_mkfs_sized $SIZE $dbsize 2> /dev/null > $tmp.mkfs.raw
39 cat $tmp.mkfs.raw | _filter_mkfs 2> $tmp.mkfs > /dev/null
42 # Source $tmp.mkfs to get geometry
45 # fix the reserve block pool to a known size so that the enospc calculations
46 # work out correctly. Space usages is based 22500 files and 1024 reserved blocks
47 # on a 4k block size 256 byte inode size filesystem.
49 space=$(stat -f -c '%f * %S' $SCRATCH_MNT | $BC_PROG)
51 # decrease files for inode size.
52 # 22500 * (256 + 4k) = ~97MB
53 # files * (isize + bsize) = 97MB
54 # files = (97920000 / (isize + bsize))
56 files=$((space / (isize + dbsize)))
58 # Now do it again, but factor in the filename sizes too.
59 # We naively assume 8 bytes for inode number, 1 byte for ftype,
60 # and 1 more byte for namelen, then round up to the nearest 8
63 namelen="$(echo -n "$files" | wc -c)"
64 direntlen="$(echo "(10 + $namelen + 7) / 8 * 8" | $BC_PROG)"
66 files=$((space / (direntlen + isize + dbsize)))
68 echo files $files, resvblks $resv_blks >> $seqres.full
69 _scratch_resvblks $resv_blks >> $seqres.full 2>&1
72 test $FSTYP != xfs && sed -e '/No space left on device/d'
75 for i in `seq -w 1 $files`; do
76 (echo -n > $SCRATCH_MNT/$i;
77 echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX > $SCRATCH_MNT/$i) 2>&1 | filter