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 2/9] xfs: factor out a xfs_rtfile_initialize_buf helper
Date: Thu, 24 Sep 2026 11:57:03 +0200	[thread overview]
Message-ID: <20260924095740.2732474-3-hch@lst.de> (raw)
In-Reply-To: <20260924095740.2732474-1-hch@lst.de>

Share the code to initialize the header and buf ops for rtfile blocks
into a single helper.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/libxfs/xfs_rtbitmap.c    | 38 +++++++++++++++++++++------------
 fs/xfs/libxfs/xfs_rtbitmap.h    |  3 +++
 fs/xfs/scrub/rtbitmap_repair.c  | 15 +------------
 fs/xfs/scrub/rtsummary_repair.c | 15 +------------
 4 files changed, 29 insertions(+), 42 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c
index 3f7877220e05..5cadde81b5da 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.c
+++ b/fs/xfs/libxfs/xfs_rtbitmap.c
@@ -1378,6 +1378,27 @@ xfs_rtfile_alloc_blocks(
 	return error;
 }
 
+void
+xfs_rtfile_initialize_buf(
+	struct xfs_rtgroup	*rtg,
+	enum xfs_rtg_inodes	type,
+	struct xfs_buf		*bp,
+	struct xfs_trans	*tp)
+{
+	bp->b_ops = xfs_rtblock_ops(bp->b_mount, type);
+	if (tp)
+		xfs_trans_buf_set_type(tp, bp, xfs_rtblock_buf_types[type]);
+	if (xfs_has_rtgroups(bp->b_mount)) {
+		struct xfs_rtbuf_blkinfo	*hdr = bp->b_addr;
+
+		hdr->rt_magic = bp->b_ops->magic[1];
+		hdr->rt_owner = cpu_to_be64(I_INO(rtg->rtg_inodes[type]));
+		hdr->rt_blkno = cpu_to_be64(xfs_buf_daddr(bp));
+		hdr->rt_lsn = 0;
+		uuid_copy(&hdr->rt_uuid, &bp->b_mount->m_sb.sb_meta_uuid);
+	}
+}
+
 /* Get a buffer for the block. */
 static int
 xfs_rtfile_initialize_block(
@@ -1408,21 +1429,10 @@ xfs_rtfile_initialize_block(
 	}
 	bufdata = bp->b_addr;
 
-	xfs_trans_buf_set_type(tp, bp, xfs_rtblock_buf_types[type]);
-	bp->b_ops = xfs_rtblock_ops(mp, type);
-
-	if (xfs_has_rtgroups(mp)) {
-		struct xfs_rtbuf_blkinfo	*hdr = bp->b_addr;
-
-		hdr->rt_magic = bp->b_ops->magic[1];
-		hdr->rt_owner = cpu_to_be64(I_INO(ip));
-		hdr->rt_blkno = cpu_to_be64(XFS_FSB_TO_DADDR(mp, fsbno));
-		hdr->rt_lsn = 0;
-		uuid_copy(&hdr->rt_uuid, &mp->m_sb.sb_meta_uuid);
-
-		bufdata += sizeof(*hdr);
-	}
+	xfs_rtfile_initialize_buf(rtg, type, bp, tp);
 
+	if (xfs_has_rtgroups(mp))
+		bufdata += sizeof(struct xfs_rtbuf_blkinfo);
 	if (data)
 		memcpy(bufdata, data, copylen);
 	else
diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h
index 375cc48e1a53..4a87e1fd3e99 100644
--- a/fs/xfs/libxfs/xfs_rtbitmap.h
+++ b/fs/xfs/libxfs/xfs_rtbitmap.h
@@ -408,6 +408,9 @@ xfs_filblks_t xfs_rtsummary_blockcount(struct xfs_mount *mp,
 
 const struct xfs_buf_ops *xfs_rtblock_ops(struct xfs_mount *mp,
 		enum xfs_rtg_inodes type);
+void xfs_rtfile_initialize_buf(struct xfs_rtgroup *rtg,
+		enum xfs_rtg_inodes type, struct xfs_buf *bp,
+		struct xfs_trans *tp);
 int xfs_rtfile_initialize_blocks(struct xfs_rtgroup *rtg,
 		enum xfs_rtg_inodes type, xfs_fileoff_t offset_fsb,
 		xfs_fileoff_t end_fsb, void *data);
diff --git a/fs/xfs/scrub/rtbitmap_repair.c b/fs/xfs/scrub/rtbitmap_repair.c
index 442a17bf9720..6a2efe3115f4 100644
--- a/fs/xfs/scrub/rtbitmap_repair.c
+++ b/fs/xfs/scrub/rtbitmap_repair.c
@@ -383,21 +383,8 @@ xrep_rtbitmap_prep_buf(
 	if (error)
 		return error;
 
-	if (xfs_has_rtgroups(sc->mp)) {
-		struct xfs_rtbuf_blkinfo	*hdr = bp->b_addr;
-
-		hdr->rt_magic = cpu_to_be32(XFS_RTBITMAP_MAGIC);
-		hdr->rt_owner = cpu_to_be64(I_INO(sc->ip));
-		hdr->rt_blkno = cpu_to_be64(xfs_buf_daddr(bp));
-		hdr->rt_lsn = 0;
-		uuid_copy(&hdr->rt_uuid, &sc->mp->m_sb.sb_meta_uuid);
-		bp->b_ops = &xfs_rtbitmap_buf_ops;
-	} else {
-		bp->b_ops = &xfs_rtbuf_ops;
-	}
-
+	xfs_rtfile_initialize_buf(sc->sr.rtg, XFS_RTGI_BITMAP, bp, sc->tp);
 	rtb->prep_wordoff += mp->m_blockwsize;
-	xfs_trans_buf_set_type(sc->tp, bp, XFS_BLFT_RTBITMAP_BUF);
 	return 0;
 }
 
diff --git a/fs/xfs/scrub/rtsummary_repair.c b/fs/xfs/scrub/rtsummary_repair.c
index f065c3e51ce2..6a66113f6562 100644
--- a/fs/xfs/scrub/rtsummary_repair.c
+++ b/fs/xfs/scrub/rtsummary_repair.c
@@ -87,21 +87,8 @@ xrep_rtsummary_prep_buf(
 	if (error)
 		return error;
 
-	if (xfs_has_rtgroups(sc->mp)) {
-		struct xfs_rtbuf_blkinfo	*hdr = bp->b_addr;
-
-		hdr->rt_magic = cpu_to_be32(XFS_RTSUMMARY_MAGIC);
-		hdr->rt_owner = cpu_to_be64(I_INO(sc->ip));
-		hdr->rt_blkno = cpu_to_be64(xfs_buf_daddr(bp));
-		hdr->rt_lsn = 0;
-		uuid_copy(&hdr->rt_uuid, &sc->mp->m_sb.sb_meta_uuid);
-		bp->b_ops = &xfs_rtsummary_buf_ops;
-	} else {
-		bp->b_ops = &xfs_rtbuf_ops;
-	}
-
+	xfs_rtfile_initialize_buf(sc->sr.rtg, XFS_RTGI_SUMMARY, bp, sc->tp);
 	rts->prep_wordoff += mp->m_blockwsize;
-	xfs_trans_buf_set_type(sc->tp, bp, XFS_BLFT_RTSUMMARY_BUF);
 	return 0;
 }
 
-- 
2.53.0


  parent reply	other threads:[~2026-09-24  9:57 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 ` Christoph Hellwig [this message]
2026-09-24 19:02   ` [PATCH 2/9] xfs: factor out a xfs_rtfile_initialize_buf helper 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 ` [PATCH 8/9] xfs: factor out a xfs_zoned_fill_srcmap helper Christoph Hellwig
2026-09-24 20:27   ` 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-3-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