]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xfs: fix the entry condition of exact EOF block allocation optimization
authorJinliang Zheng <alexjlzheng@gmail.com>
Wed, 15 Jan 2025 12:35:25 +0000 (20:35 +0800)
committerCarlos Maiolino <cem@kernel.org>
Fri, 24 Jan 2025 11:05:12 +0000 (12:05 +0100)
When we call create(), lseek() and write() sequentially, offset != 0
cannot be used as a judgment condition for whether the file already
has extents.

Furthermore, when xfs_bmap_adjacent() has not given a better blkno,
it is not necessary to use exact EOF block allocation.

Suggested-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
fs/xfs/libxfs/xfs_bmap.c

index 40ad22fb808b95025cbc1b7ebd80ba66b0469816..0ef19f1469ec9d1eb0d728f5874672154e29d94f 100644 (file)
@@ -3563,12 +3563,12 @@ xfs_bmap_btalloc_at_eof(
        int                     error;
 
        /*
-        * If there are already extents in the file, try an exact EOF block
-        * allocation to extend the file as a contiguous extent. If that fails,
-        * or it's the first allocation in a file, just try for a stripe aligned
-        * allocation.
+        * If there are already extents in the file, and xfs_bmap_adjacent() has
+        * given a better blkno, try an exact EOF block allocation to extend the
+        * file as a contiguous extent. If that fails, or it's the first
+        * allocation in a file, just try for a stripe aligned allocation.
         */
-       if (ap->offset) {
+       if (ap->eof) {
                xfs_extlen_t    nextminlen = 0;
 
                /*
@@ -3736,7 +3736,8 @@ xfs_bmap_btalloc_best_length(
        int                     error;
 
        ap->blkno = XFS_INO_TO_FSB(args->mp, ap->ip->i_ino);
-       xfs_bmap_adjacent(ap);
+       if (!xfs_bmap_adjacent(ap))
+               ap->eof = false;
 
        /*
         * Search for an allocation group with a single extent large enough for