#! /bin/bash # SPDX-License-Identifier: GPL-2.0 # Copyright (c) 2009 Christoph Hellwig. # # FS QA Test No. 204 # # Test out ENOSPC flushing on small filesystems. # seq=`basename $0` seqres=$RESULT_DIR/$seq echo "QA output created by $seq" here=`pwd` tmp=/tmp/$$ status=1 # failure is the default! trap "_cleanup; exit \$status" 0 1 2 3 15 _cleanup() { rm -f $tmp.* sync } # get standard environment, filters and checks . ./common/rc . ./common/filter # real QA test starts here _supported_fs generic _require_scratch rm -f $seqres.full # get the block size first _scratch_mkfs 2> /dev/null | _filter_mkfs 2> $tmp.mkfs > /dev/null . $tmp.mkfs # For xfs, we need to handle the different default log sizes that different # versions of mkfs create. All should be valid with a 16MB log, so use that. # And v4/512 v5/1k xfs don't have enough free inodes, set imaxpct=50 at mkfs # time solves this problem. [ $FSTYP = "xfs" ] && MKFS_OPTIONS="$MKFS_OPTIONS -l size=16m -i maxpct=50" SIZE=`expr 115 \* 1024 \* 1024` _scratch_mkfs_sized $SIZE $dbsize 2> /dev/null > $tmp.mkfs.raw cat $tmp.mkfs.raw | _filter_mkfs 2> $tmp.mkfs > /dev/null _scratch_mount # Source $tmp.mkfs to get geometry . $tmp.mkfs # fix the reserve block pool to a known size so that the enospc calculations # work out correctly. Space usages is based 22500 files and 1024 reserved blocks # on a 4k block size 256 byte inode size filesystem. resv_blks=1024 space=$(stat -f -c '%f * %S' $SCRATCH_MNT | $BC_PROG) # decrease files for inode size. # 22500 * (256 + 4k) = ~97MB # files * (isize + bsize) = 97MB # files = (97920000 / (isize + bsize)) files=$((space / (isize + dbsize))) # Now do it again, but factor in the filename sizes too. # We naively assume 8 bytes for inode number, 1 byte for ftype, # and 1 more byte for namelen, then round up to the nearest 8 # bytes. namelen="$(echo -n "$files" | wc -c)" direntlen="$(echo "(10 + $namelen + 7) / 8 * 8" | $BC_PROG)" files=$((space / (direntlen + isize + dbsize))) echo files $files, resvblks $resv_blks >> $seqres.full _scratch_resvblks $resv_blks >> $seqres.full 2>&1 filter() { test $FSTYP != xfs && sed -e '/No space left on device/d' } for i in `seq -w 1 $files`; do (echo -n > $SCRATCH_MNT/$i; echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX > $SCRATCH_MNT/$i) 2>&1 | filter done # success, all done echo "*** done" status=0