aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2024-03-07 15:22:55 -0800
committerZorro Lang <zlang@kernel.org>2024-03-12 11:39:52 +0800
commit70fc4244b7dc015c6d371b3c32ed6d92c4f03b37 (patch)
tree60c8630a31737cd6042b8e174889c287b1c9a4da
parentb41b9ca96f6947ed99dfe39114b63de6ef8b2e67 (diff)
downloadxfstests-dev-70fc4244b7dc015c6d371b3c32ed6d92c4f03b37.tar.gz
xfs: test for premature ENOSPC with large cow delalloc extents
On a higly fragmented filesystem a Direct IO write can fail with -ENOSPC error even though the filesystem has sufficient number of free blocks. This occurs if the file offset range on which the write operation is being performed has a delalloc extent in the cow fork and this delalloc extent begins much before the Direct IO range. In such a scenario, xfs_reflink_allocate_cow() invokes xfs_bmapi_write() to allocate the blocks mapped by the delalloc extent. The extent thus allocated may not cover the beginning of file offset range on which the Direct IO write was issued. Hence xfs_reflink_allocate_cow() ends up returning -ENOSPC. This test addresses this issue. Signed-off-by: "Darrick J. Wong" <djwong@kernel.org> Reviewed-by: Zorro Lang <zlang@redhat.com> Signed-off-by: Zorro Lang <zlang@kernel.org>
-rw-r--r--common/rc14
-rwxr-xr-xtests/xfs/60786
-rw-r--r--tests/xfs/607.out8
3 files changed, 108 insertions, 0 deletions
diff --git a/common/rc b/common/rc
index 36cad89cfc..a098032753 100644
--- a/common/rc
+++ b/common/rc
@@ -1888,6 +1888,20 @@ _require_scratch_delalloc()
_scratch_unmount
}
+# Require test fs supports delay allocation.
+_require_test_delalloc()
+{
+ _require_command "$FILEFRAG_PROG" filefrag
+
+ rm -f $TEST_DIR/testy
+ $XFS_IO_PROG -f -c 'pwrite 0 64k' $TEST_DIR/testy &> /dev/null
+ $FILEFRAG_PROG -v $TEST_DIR/testy 2>&1 | grep -q delalloc
+ res=$?
+ rm -f $TEST_DIR/testy
+ test $res -eq 0 || \
+ _notrun "test requires delayed allocation buffered writes"
+}
+
# this test needs a test partition - check we're ok & mount it
#
_require_test()
diff --git a/tests/xfs/607 b/tests/xfs/607
new file mode 100755
index 0000000000..e1120eacac
--- /dev/null
+++ b/tests/xfs/607
@@ -0,0 +1,86 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2022-2024 Oracle. All Rights Reserved.
+#
+# FS QA Test No. 607
+#
+# This is a regression test for "xfs: Fix false ENOSPC when performing direct
+# write on a delalloc extent in cow fork". If there is a lot of free space but
+# it is very fragmented, it's possible that a very large delalloc reservation
+# could be created in the CoW fork by a buffered write. If a directio write
+# tries to convert the delalloc reservation to a real extent, it's possible
+# that the allocation will succeed but fail to convert even the first block of
+# the directio write range. In this case, XFS will return ENOSPC even though
+# all it needed to do was to keep converting until the allocator returns ENOSPC
+# or the first block of the direct write got some space.
+#
+. ./common/preamble
+_begin_fstest auto quick clone
+
+_cleanup()
+{
+ cd /
+ rm -f $file1 $file2 $fragmentedfile
+}
+
+# Import common functions.
+. ./common/reflink
+. ./common/inject
+
+# real QA test starts here
+_fixed_by_kernel_commit d62113303d69 \
+ "xfs: Fix false ENOSPC when performing direct write on a delalloc extent in cow fork"
+
+# Modify as appropriate.
+_supported_fs xfs
+_require_test_program "punch-alternating"
+_require_test_reflink
+_require_xfs_io_error_injection "bmap_alloc_minlen_extent"
+_require_test_delalloc
+
+file1=$TEST_DIR/file1.$seq
+file2=$TEST_DIR/file2.$seq
+fragmentedfile=$TEST_DIR/fragmentedfile.$seq
+
+rm -f $file1 $file2 $fragmentedfile
+
+# COW operates on pages, so we must not perform operations in units smaller
+# than a page.
+blksz=$(_get_file_block_size $TEST_DIR)
+pagesz=$(_get_page_size)
+if (( $blksz < $pagesz )); then
+ blksz=$pagesz
+fi
+
+echo "Create source file"
+$XFS_IO_PROG -f -c "pwrite 0 $((blksz * 256))" $file1 >> $seqres.full
+
+sync
+
+echo "Create Reflinked file"
+_cp_reflink $file1 $file2 >> $seqres.full
+
+echo "Set cowextsize"
+$XFS_IO_PROG -c "cowextsize $((blksz * 128))" -c stat $file1 >> $seqres.full
+
+echo "Fragment FS"
+$XFS_IO_PROG -f -c "pwrite 0 $((blksz * 512))" $fragmentedfile >> $seqres.full
+sync
+$here/src/punch-alternating $fragmentedfile
+
+echo "Allocate block sized extent from now onwards"
+_test_inject_error bmap_alloc_minlen_extent 1
+
+echo "Create big delalloc extent in CoW fork"
+$XFS_IO_PROG -c "pwrite 0 $blksz" $file1 >> $seqres.full
+
+sync
+
+$XFS_IO_PROG -c 'bmap -elpv' -c 'bmap -celpv' $file1 &>> $seqres.full
+
+echo "Direct I/O write at offset 3FSB"
+$XFS_IO_PROG -d -c "pwrite $((blksz * 3)) $((blksz * 2))" $file1 >> $seqres.full
+
+# success, all done
+status=0
+exit
diff --git a/tests/xfs/607.out b/tests/xfs/607.out
new file mode 100644
index 0000000000..0fd9134b4e
--- /dev/null
+++ b/tests/xfs/607.out
@@ -0,0 +1,8 @@
+QA output created by 607
+Create source file
+Create Reflinked file
+Set cowextsize
+Fragment FS
+Allocate block sized extent from now onwards
+Create big delalloc extent in CoW fork
+Direct I/O write at offset 3FSB