[PATCH 30/33] ext4/009: fix ENOSPC errors

Darrick J. Wong
2025-10-29T01:28:15Z

This test periodically fails with:

--- tests/ext4/009.out 2025-04-30 16:20:44.428030637 -0700
+++ /var/tmp/fstests/ext4/009.out.bad 2025-09-12 15:30:44.929374431 -0700
@@ -9,4 +9,5 @@
+ repair fs
+ mount image (2)
+ modify files (2)
+fallocate: No space left on device
+ check fs (2)
...

This can happen if the amount of space requested by fallocate exceeds
the number of reserved blocks in the filesystem. Reduce the fallocation
requests a little bit to prevent this.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
tests/ext4/009 | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/tests/ext4/009 b/tests/ext4/009
index 71e59f90e4b844..867e0cdefd4223 100755
--- a/tests/ext4/009
+++ b/tests/ext4/009
@@ -45,7 +45,8 @@ for i in `seq 1 $((nr_groups * 8))`; do
done
blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
freeblks="$(stat -f -c '%a' "${SCRATCH_MNT}")"
-$XFS_IO_PROG -f -c "falloc 0 $((blksz * freeblks))" "${SCRATCH_MNT}/bigfile2" >> $seqres.full
+fallocblks=$((freeblks * 95 / 100))
+$XFS_IO_PROG -f -c "falloc 0 $((blksz * fallocblks))" "${SCRATCH_MNT}/bigfile2" >> $seqres.full
umount "${SCRATCH_MNT}"

echo "+ make some files"
@@ -67,7 +68,9 @@ _scratch_mount

echo "+ modify files"
b_bytes="$(stat -c '%B' "${SCRATCH_MNT}/bigfile")"
-$XFS_IO_PROG -f -c "falloc 0 $((blksz * freeblks))" "${SCRATCH_MNT}/bigfile" >> $seqres.full 2> /dev/null
+freeblks="$(stat -f -c '%a' "${SCRATCH_MNT}")"
+fallocblks=$((freeblks * 95 / 100))
+$XFS_IO_PROG -f -c "falloc 0 $((blksz * fallocblks))" "${SCRATCH_MNT}/bigfile" >> $seqres.full 2> /dev/null
after="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")"
echo "$((after * b_bytes))" lt "$((blksz * freeblks / 4))" >> $seqres.full
test "$((after * b_bytes))" -lt "$((blksz * freeblks / 4))" || _fail "falloc should fail"
@@ -80,7 +83,9 @@ echo "+ mount image (2)"
_scratch_mount

echo "+ modify files (2)"
-$XFS_IO_PROG -f -c "falloc 0 $((blksz * freeblks))" "${SCRATCH_MNT}/bigfile" >> $seqres.full
+freeblks="$(stat -f -c '%a' "${SCRATCH_MNT}")"
+fallocblks=$((freeblks * 95 / 100))
+$XFS_IO_PROG -f -c "falloc 0 $((blksz * fallocblks))" "${SCRATCH_MNT}/bigfile" >> $seqres.full
umount "${SCRATCH_MNT}"

echo "+ check fs (2)"