Linux XFS filesystem development
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Carlos Maiolino <cem@kernel.org>
Cc: "Darrick J . Wong" <djwong@kernel.org>, linux-xfs@vger.kernel.org
Subject: [PATCH 8/9] xfs: factor out a xfs_zoned_fill_srcmap helper
Date: Thu, 24 Sep 2026 11:57:09 +0200	[thread overview]
Message-ID: <20260924095740.2732474-9-hch@lst.de> (raw)
In-Reply-To: <20260924095740.2732474-1-hch@lst.de>

The code filling the srcmap in xfs_zoned_buffered_write_iomap_begin isn't
terribly complicated, but fairly deeply indented and will become a bit
more complex soon.  Factor it into a helper and add some comments.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/xfs_iomap.c | 53 ++++++++++++++++++++++++++++++----------------
 1 file changed, 35 insertions(+), 18 deletions(-)

diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index 7c6238fed61e..7bc17f179be7 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -1588,6 +1588,37 @@ xfs_bmapi_reserve_delalloc(
 	return error;
 }
 
+static int
+xfs_zoned_fill_srcmap(
+	struct xfs_inode	*ip,
+	xfs_fileoff_t		offset_fsb,
+	xfs_fileoff_t		*end_fsb,
+	unsigned		flags,
+	struct iomap		*srcmap)
+{
+	struct xfs_bmbt_irec	smap;
+	struct xfs_iext_cursor	scur;
+
+	if (!xfs_iext_lookup_extent(ip, &ip->i_df, offset_fsb, &scur, &smap))
+		smap.br_startoff = *end_fsb; /* fake hole until EOF */
+	if (smap.br_startoff > offset_fsb) {
+		/*
+		 * There is a hole at @offset_fsb.  Only map until the end of
+		 * the of it.
+		 */
+		*end_fsb = min(*end_fsb, smap.br_startoff);
+		return 0;
+	}
+
+	/*
+	 * There is a data fork mapping, only map until the end of it.
+	 */
+	*end_fsb = min(*end_fsb, smap.br_startoff + smap.br_blockcount);
+	xfs_trim_extent(&smap, offset_fsb, *end_fsb - offset_fsb);
+	return xfs_bmbt_to_iomap(ip, srcmap, &smap, flags, 0,
+			xfs_iomap_inode_sequence(ip, 0));
+}
+
 static int
 xfs_zoned_buffered_write_iomap_begin(
 	struct inode		*inode,
@@ -1655,24 +1686,10 @@ xfs_zoned_buffered_write_iomap_begin(
 	if (!IS_ALIGNED(offset, mp->m_sb.sb_blocksize) ||
 	    !IS_ALIGNED(offset + count, mp->m_sb.sb_blocksize) ||
 	    (flags & IOMAP_ZERO)) {
-		struct xfs_bmbt_irec	smap;
-		struct xfs_iext_cursor	scur;
-
-		if (!xfs_iext_lookup_extent(ip, &ip->i_df, offset_fsb, &scur,
-				&smap))
-			smap.br_startoff = end_fsb; /* fake hole until EOF */
-		if (smap.br_startoff > offset_fsb) {
-			end_fsb = min(end_fsb, smap.br_startoff);
-		} else {
-			end_fsb = min(end_fsb,
-				smap.br_startoff + smap.br_blockcount);
-			xfs_trim_extent(&smap, offset_fsb,
-					end_fsb - offset_fsb);
-			error = xfs_bmbt_to_iomap(ip, srcmap, &smap, flags, 0,
-					xfs_iomap_inode_sequence(ip, 0));
-			if (error)
-				goto out_unlock;
-		}
+		error = xfs_zoned_fill_srcmap(ip, offset_fsb, &end_fsb, flags,
+				srcmap);
+		if (error)
+			goto out_unlock;
 	}
 
 	if (!ip->i_cowfp)
-- 
2.53.0


  parent reply	other threads:[~2026-09-24  9:58 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24  9:57 misc cleanups Christoph Hellwig
2026-09-24  9:57 ` [PATCH 1/9] xfs: centralize setting of buf_ops/buf_type/magic for rtblocks Christoph Hellwig
2026-09-24 19:01   ` Darrick J. Wong
2026-09-24  9:57 ` [PATCH 2/9] xfs: factor out a xfs_rtfile_initialize_buf helper Christoph Hellwig
2026-09-24 19:02   ` Darrick J. Wong
2026-09-24  9:57 ` [PATCH 3/9] xfs: add a xfs_rtblock_payload helper Christoph Hellwig
2026-09-24 20:13   ` Darrick J. Wong
2026-09-24  9:57 ` [PATCH 4/9] xfs: cleanup xfs_verify_media_error Christoph Hellwig
2026-09-24 20:14   ` Darrick J. Wong
2026-09-24  9:57 ` [PATCH 5/9] xfs: use bdev_rw_virt in xfs_verify_media Christoph Hellwig
2026-09-24 20:18   ` Darrick J. Wong
2026-09-24  9:57 ` [PATCH 6/9] xfs: lift setting the NOFS context to xfs_end_io Christoph Hellwig
2026-09-24 20:18   ` Darrick J. Wong
2026-09-24  9:57 ` [PATCH 7/9] xfs: split xfs_end_ioend_write Christoph Hellwig
2026-09-24 20:26   ` Darrick J. Wong
2026-09-25  5:46     ` Christoph Hellwig
2026-09-24  9:57 ` Christoph Hellwig [this message]
2026-09-24 20:27   ` [PATCH 8/9] xfs: factor out a xfs_zoned_fill_srcmap helper Darrick J. Wong
2026-09-24  9:57 ` [PATCH 9/9] xfs: calculate end_fsb later in xfs_zoned_fill_srcmap Christoph Hellwig
2026-09-24 20:29   ` Darrick J. Wong
2026-10-05 18:06 ` misc cleanups Carlos Maiolino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260924095740.2732474-9-hch@lst.de \
    --to=hch@lst.de \
    --cc=cem@kernel.org \
    --cc=djwong@kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox