Linux XFS filesystem development
 help / color / mirror / Atom feed
* [PATCH] xfs: punch delalloc blocks past EOF before mapping a pNFS layout
@ 2026-11-26  1:45 Daejun Park via B4 Relay
  2026-11-30 13:02 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Daejun Park via B4 Relay @ 2026-11-26  1:45 UTC (permalink / raw)
  To: Carlos Maiolino, linux-xfs
  Cc: Darrick J. Wong, Dave Chinner, Christoph Hellwig, Chuck Lever,
	Jeff Layton, linux-nfs, linux-kernel, stable, Daejun Park

From: Daejun Park <daejun7.park@samsung.com>

Writeback on fragmented free space can leave speculative
preallocation past EOF as delalloc. A LAYOUTGET over it BUG()s on
XFS_DEBUG kernels. Other kernels warn in nfsd and refuse the layout.
A LAYOUTCOMMIT past it moves EOF over it. Inode reclaim then asserts.

Punch it after the flush. Delalloc past EOF holds no data.

Fixes: 527851124d10 ("xfs: implement pNFS export operations")
Cc: stable@vger.kernel.org
Signed-off-by: Daejun Park <daejun7.park@samsung.com>
---
Tested with pynfs on XFS_DEBUG, with free space fragmented as in
xfs/538 and the bmap_alloc_minlen_extent error tag set. LAYOUTGETs over
the 512 KiB left delalloc no longer assert. Neither does eviction after
a LAYOUTCOMMIT past it. The pynfs block tests and fstests over pNFS
show no change (BLOCK3, generic/075, 112 and 127 fail either way).

xfs_bmap_punch_delalloc_range() takes the same arguments in the 6.18.y
and 7.3.y stable trees. Older trees need them adjusted (5.10.y and
5.15.y take a start block and a length).
---
 fs/xfs/xfs_pnfs.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/fs/xfs/xfs_pnfs.c b/fs/xfs/xfs_pnfs.c
index 945f7a3e11c..4a6c1a399d7 100644
--- a/fs/xfs/xfs_pnfs.c
+++ b/fs/xfs/xfs_pnfs.c
@@ -11,6 +11,7 @@
 #include "xfs_inode.h"
 #include "xfs_trans.h"
 #include "xfs_bmap.h"
+#include "xfs_bmap_util.h"
 #include "xfs_iomap.h"
 #include "xfs_pnfs.h"
 #include <linux/exportfs_block.h>
@@ -192,6 +193,18 @@ xfs_fs_map_blocks(
 	if (WARN_ON_ONCE(error))
 		goto out_unlock;
 
+	/*
+	 * Writeback stops allocating a delalloc extent once the page it writes
+	 * is covered, so speculative preallocation past EOF can stay delalloc.
+	 * Delalloc past EOF never holds data. Punch all of it, as
+	 * xfs_free_eofblocks() does for preallocated files, so that a layout
+	 * never maps it and a LAYOUTCOMMIT never moves EOF over it.
+	 */
+	if (ip->i_delayed_blks)
+		xfs_bmap_punch_delalloc_range(ip, XFS_DATA_FORK,
+				round_up(XFS_ISIZE(ip), mp->m_sb.sb_blocksize),
+				LLONG_MAX, NULL);
+
 	end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + length);
 	offset_fsb = XFS_B_TO_FSBT(mp, offset);
 

---
base-commit: 5e7b6fe39324913f6416c854c6ed3a1793aaba8e
change-id: 20261126-xfs-pnfs-delalloc-eof-75b3260aecbc

Best regards,
-- 
Daejun Park <daejun7.park@samsung.com>



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] xfs: punch delalloc blocks past EOF before mapping a pNFS layout
  2026-11-26  1:45 [PATCH] xfs: punch delalloc blocks past EOF before mapping a pNFS layout Daejun Park via B4 Relay
@ 2026-11-30 13:02 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2026-11-30 13:02 UTC (permalink / raw)
  To: daejun7.park
  Cc: Carlos Maiolino, linux-xfs, Darrick J. Wong, Dave Chinner,
	Christoph Hellwig, Chuck Lever, Jeff Layton, linux-nfs,
	linux-kernel, stable

On Thu, Nov 26, 2026 at 10:45:47AM +0900, Daejun Park via B4 Relay wrote:
> @@ -192,6 +193,18 @@ xfs_fs_map_blocks(
>  	if (WARN_ON_ONCE(error))
>  		goto out_unlock;
>  
> +	/*
> +	 * Writeback stops allocating a delalloc extent once the page it writes
> +	 * is covered, so speculative preallocation past EOF can stay delalloc.
> +	 * Delalloc past EOF never holds data. Punch all of it, as
> +	 * xfs_free_eofblocks() does for preallocated files, so that a layout
> +	 * never maps it and a LAYOUTCOMMIT never moves EOF over it.
> +	 */
> +	if (ip->i_delayed_blks)
> +		xfs_bmap_punch_delalloc_range(ip, XFS_DATA_FORK,
> +				round_up(XFS_ISIZE(ip), mp->m_sb.sb_blocksize),
> +				LLONG_MAX, NULL);
> +

This is basically a xfs_free_eofblocks.  I think we also should do a
xfs_inode_clear_eofblocks_tag here, and we also need to do a
inode_dio_wait to settle i_size after taking the iolock.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-30 13:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  1:45 [PATCH] xfs: punch delalloc blocks past EOF before mapping a pNFS layout Daejun Park via B4 Relay
2026-11-30 13:02 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox