Linux XFS filesystem development
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: cem@kernel.org
Cc: djwong@kernel.org, linux-xfs@vger.kernel.org
Subject: [PATCH] xfs: improve RT geometry validation
Date: Thu,  7 May 2026 07:25:35 +0200	[thread overview]
Message-ID: <20260507052543.1305129-1-hch@lst.de> (raw)

Make sure the rtgcount is plausible for the given RT group size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/libxfs/xfs_sb.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
index 47322adb7690..c0354f43704f 100644
--- a/fs/xfs/libxfs/xfs_sb.c
+++ b/fs/xfs/libxfs/xfs_sb.c
@@ -302,17 +302,25 @@ xfs_validate_rt_geometry(
 		return false;
 
 	if (xfs_sb_is_v5(sbp) &&
-	    (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_ZONED)) {
+	    (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_METADIR)) {
+		uint64_t		nr_rgs;
 		uint32_t		mod;
 
 		/*
-		 * Zoned RT devices must be aligned to the RT group size,
-		 * because garbage collection assumes that all zones have the
-		 * same size to avoid insane complexity if that weren't the
-		 * case.
+		 * Check that the number of rgcounts is plausible for the RG
+		 * size.
+		 */
+		nr_rgs = div_u64_rem(sbp->sb_rextents, sbp->sb_rgextents, &mod);
+		if (nr_rgs != sbp->sb_rgcount + !!mod)
+			return false;
+
+		/*
+		 * Zoned RT devices must be aligned to the RT group size because
+		 * garbage collection assumes that all zones have the same size
+		 * to avoid insane complexity if that weren't the case.
 		 */
-		div_u64_rem(sbp->sb_rextents, sbp->sb_rgextents, &mod);
-		if (mod)
+		if ((sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_ZONED) &&
+		    mod > 0)
 			return false;
 	}
 
-- 
2.53.0


             reply	other threads:[~2026-05-07  5:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <wV6uRtt8Mdv0dR-Ory4pMu4E-SDYDmUrTwaPRauY7S4lM07r4ogMmp38xxeF3FNG3X_E46ujDJHX94Lq_Oe-Vg==@protonmail.internalid>
2026-05-07  5:25 ` Christoph Hellwig [this message]
2026-05-07 12:17   ` [PATCH] xfs: improve RT geometry validation Carlos Maiolino
2026-05-07 17:17   ` Darrick J. Wong
2026-05-08  8:16     ` Christoph Hellwig
2026-05-09  0:54       ` Darrick J. Wong

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=20260507052543.1305129-1-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