summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Foster <bfoster@redhat.com>2026-03-11 19:24:56 +0300
committerCarlos Maiolino <cem@kernel.org>2026-03-23 13:07:59 +0300
commit2f46c239fce617ac26cc40d9520b1c0cf05cd34f (patch)
tree3376ed3a0a0a5cbbd2ea125c8cf78fd0a4794455
parent92e9dff9ca5026805798b13b967760f8058794e8 (diff)
downloadlinux-2f46c239fce617ac26cc40d9520b1c0cf05cd34f.tar.xz
xfs: flush dirty pagecache over hole in zoned mode zero range
For zoned filesystems a window exists between the first write to a sparse range (i.e. data fork hole) and writeback completion where we might spuriously observe holes in both the COW and data forks. This occurs because a buffered write populates the COW fork with delalloc, writeback submission removes the COW fork delalloc blocks and unlocks the inode, and then writeback completion remaps the physically allocated blocks into the data fork. If a zero range operation does a lookup during this window where both forks show a hole, it incorrectly reports a hole mapping for a range that contains data. This currently works because iomap checks for dirty pagecache over holes and unwritten mappings. If found, it flushes and retries the lookup. We plan to remove the hole flush logic from iomap, however, so lift the flush into xfs_zoned_buffered_write_iomap_begin() to preserve behavior and document the purpose for it. Zoned XFS filesystems don't support unwritten extents, so if zoned mode can come up with a way to close this transient hole window in the future, this flush can likely be removed. Signed-off-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Carlos Maiolino <cem@kernel.org>
-rw-r--r--fs/xfs/xfs_iomap.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index 8c3469d2c73e..d3b8c018c883 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -1590,6 +1590,7 @@ xfs_zoned_buffered_write_iomap_begin(
{
struct iomap_iter *iter =
container_of(iomap, struct iomap_iter, iomap);
+ struct address_space *mapping = inode->i_mapping;
struct xfs_zone_alloc_ctx *ac = iter->private;
struct xfs_inode *ip = XFS_I(inode);
struct xfs_mount *mp = ip->i_mount;
@@ -1614,6 +1615,7 @@ xfs_zoned_buffered_write_iomap_begin(
if (error)
return error;
+restart:
error = xfs_ilock_for_iomap(ip, flags, &lockmode);
if (error)
return error;
@@ -1686,8 +1688,25 @@ xfs_zoned_buffered_write_iomap_begin(
* When zeroing, don't allocate blocks for holes as they are already
* zeroes, but we need to ensure that no extents exist in both the data
* and COW fork to ensure this really is a hole.
+ *
+ * A window exists where we might observe a hole in both forks with
+ * valid data in cache. Writeback removes the COW fork blocks on
+ * submission but doesn't remap into the data fork until completion. If
+ * the data fork was previously a hole, we'll fail to zero. Until we
+ * find a way to avoid this transient state, check for dirty pagecache
+ * and flush to wait on blocks to land in the data fork.
*/
if ((flags & IOMAP_ZERO) && srcmap->type == IOMAP_HOLE) {
+ if (filemap_range_needs_writeback(mapping, offset,
+ offset + count - 1)) {
+ xfs_iunlock(ip, lockmode);
+ error = filemap_write_and_wait_range(mapping, offset,
+ offset + count - 1);
+ if (error)
+ return error;
+ goto restart;
+ }
+
xfs_hole_to_iomap(ip, iomap, offset_fsb, end_fsb);
goto out_unlock;
}