All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Foster <bfoster@redhat.com>
To: linux-xfs@vger.kernel.org
Cc: djwong@kernel.org, sandeen@sandeen.net
Subject: [RFC 3/4] xfs: factor out a helper to calculate post-growfs agcount
Date: Tue,  8 Oct 2024 09:13:47 -0400	[thread overview]
Message-ID: <20241008131348.81013-4-bfoster@redhat.com> (raw)
In-Reply-To: <20241008131348.81013-1-bfoster@redhat.com>

Factor out the new agcount calculation logic into a helper.

Signed-off-by: Brian Foster <bfoster@redhat.com>
---
 fs/xfs/xfs_fsops.c | 42 +++++++++++++++++++++++++++++-------------
 1 file changed, 29 insertions(+), 13 deletions(-)

diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c
index 6401424303c5..3b95a368584e 100644
--- a/fs/xfs/xfs_fsops.c
+++ b/fs/xfs/xfs_fsops.c
@@ -80,6 +80,33 @@ xfs_resizefs_init_new_ags(
 	return error;
 }
 
+/*
+ * Calculate new AG count based on provided AG size. May adjust final nblocks
+ * count if necessary for a valid AG count.
+ */
+static xfs_agnumber_t
+xfs_growfs_calc_agcount(
+	struct xfs_mount	*mp,
+	xfs_agblock_t		nagblocks,
+	xfs_rfsblock_t		*nblocks)
+{
+	xfs_rfsblock_t		nb_div, nb_mod;
+
+	nb_div = *nblocks;
+	nb_mod = do_div(nb_div, nagblocks);
+	if (nb_mod && nb_mod >= XFS_MIN_AG_BLOCKS)
+		nb_div++;
+	else if (nb_mod)
+		*nblocks = nb_div * nagblocks;
+
+	if (nb_div > XFS_MAX_AGNUMBER + 1) {
+		nb_div = XFS_MAX_AGNUMBER + 1;
+		*nblocks = nb_div * nagblocks;
+	}
+
+	return nb_div;
+}
+
 /*
  * growfs operations
  */
@@ -93,7 +120,7 @@ xfs_growfs_data_private(
 	xfs_agblock_t		nagblocks;
 	xfs_agnumber_t		nagcount;
 	xfs_agnumber_t		nagimax = 0;
-	xfs_rfsblock_t		nb, nb_div, nb_mod;
+	xfs_rfsblock_t		nb;
 	int64_t			delta;
 	bool			lastag_extended = false;
 	xfs_agnumber_t		oagcount;
@@ -117,18 +144,7 @@ xfs_growfs_data_private(
 
 	nagblocks = mp->m_sb.sb_agblocks;
 
-	nb_div = nb;
-	nb_mod = do_div(nb_div, nagblocks);
-	if (nb_mod && nb_mod >= XFS_MIN_AG_BLOCKS)
-		nb_div++;
-	else if (nb_mod)
-		nb = nb_div * nagblocks;
-
-	if (nb_div > XFS_MAX_AGNUMBER + 1) {
-		nb_div = XFS_MAX_AGNUMBER + 1;
-		nb = nb_div * nagblocks;
-	}
-	nagcount = nb_div;
+	nagcount = xfs_growfs_calc_agcount(mp, nagblocks, &nb);
 	delta = nb - mp->m_sb.sb_dblocks;
 	/*
 	 * Reject filesystems with a single AG because they are not
-- 
2.46.2


  parent reply	other threads:[~2024-10-08 13:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-08 13:13 [RFC 0/4] xfs: prototype dynamic AG size grow for image mode Brian Foster
2024-10-08 13:13 ` [RFC 1/4] xfs: factor out sb_agblocks usage in growfs Brian Foster
2024-10-08 13:13 ` [RFC 2/4] xfs: transaction support for sb_agblocks updates Brian Foster
2024-10-09  8:05   ` Christoph Hellwig
2024-10-09 12:38     ` Brian Foster
2024-10-09 12:44       ` Christoph Hellwig
2024-10-08 13:13 ` Brian Foster [this message]
2024-10-08 13:13 ` [RFC 4/4] xfs: support dynamic AG size growing on single AG filesystems Brian Foster
2024-10-08 13:25 ` [PATCH] xfsprogs/mkfs: prototype XFS image mode format for scalable AG growth Brian Foster

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=20241008131348.81013-4-bfoster@redhat.com \
    --to=bfoster@redhat.com \
    --cc=djwong@kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@sandeen.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.