From: Andrey Albershteyn <aalbersh@kernel.org>
To: linux-xfs@vger.kernel.org, aalbersh@kernel.org
Cc: bestswngs@gmail.com, brauner@kernel.org, cem@kernel.org,
chuck.lever@oracle.com, cmaiolino@redhat.com,
dawei.feng@seu.edu.cn, djwong@kernel.org,
gaoyingjie@uniontech.com, hch@lst.de, jiapenglin@tencent.com,
roland.mainz@nrubsig.org, xmei5@asu.edu
Subject: [PATCH 16/21] xfs: cleanup xfs_growfs_compute_deltas
Date: Mon, 24 Aug 2026 12:40:14 +0200 [thread overview]
Message-ID: <20260824104022.420566-17-aalbersh@kernel.org> (raw)
In-Reply-To: <20260824104022.420566-1-aalbersh@kernel.org>
From: Christoph Hellwig <hch@lst.de>
Source kernel commit: dfac6ba84819bd12535943c4090766bbc6c5ea7e
xfs_growfs_compute_deltas has an odd calling conventions, and looks
very convoluted due to the use of do_div and strangely named and typed
variables.
Rename it, make it return the agcount and let the caller calculate the
delta. The internally use the better div_u64_rem helper and descriptive
variable names and types. Also add a comment describing what the
function is used for.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_ag.c | 42 ++++++++++++++++++++----------------------
libxfs/xfs_ag.h | 5 ++---
2 files changed, 22 insertions(+), 25 deletions(-)
diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c
index fb8c9bb3df82..2f47a02cc6fd 100644
--- a/libxfs/xfs_ag.c
+++ b/libxfs/xfs_ag.c
@@ -861,32 +861,30 @@ resv_err:
return err2;
}
-void
-xfs_growfs_compute_deltas(
+/*
+ * Return the agcount for the new file system size passed in *nb and adjust *nb
+ * when it has to be reduced because of maximum AG count or because it would
+ * create a below minimum size AG.
+ */
+xfs_agnumber_t
+xfs_growfs_compute_agcount(
struct xfs_mount *mp,
- xfs_rfsblock_t *nb,
- int64_t *deltap,
- xfs_agnumber_t *nagcountp)
+ xfs_rfsblock_t *nb)
{
- xfs_rfsblock_t nb_div, nb_mod;
- int64_t delta;
- xfs_agnumber_t nagcount;
+ uint64_t agcount; /* 64-bits wide to catch overflows */
+ xfs_extlen_t remainder;
- nb_div = *nb;
- nb_mod = do_div(nb_div, mp->m_sb.sb_agblocks);
- if (nb_mod && nb_mod >= XFS_MIN_AG_BLOCKS)
- nb_div++;
- else if (nb_mod)
- *nb = nb_div * mp->m_sb.sb_agblocks;
-
- if (nb_div > XFS_MAX_AGNUMBER + 1) {
- nb_div = XFS_MAX_AGNUMBER + 1;
- *nb = nb_div * mp->m_sb.sb_agblocks;
+ agcount = div_u64_rem(*nb, mp->m_sb.sb_agblocks, &remainder);
+ if (agcount >= XFS_MAX_AGNUMBER + 1) {
+ agcount = XFS_MAX_AGNUMBER + 1;
+ remainder = 0;
+ }
+ *nb = (xfs_rfsblock_t)agcount * mp->m_sb.sb_agblocks;
+ if (remainder >= XFS_MIN_AG_BLOCKS) {
+ *nb += remainder;
+ agcount++;
}
- nagcount = nb_div;
- delta = *nb - mp->m_sb.sb_dblocks;
- *deltap = delta;
- *nagcountp = nagcount;
+ return agcount;
}
/*
diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h
index 8aa4266c5571..fd22fe598931 100644
--- a/libxfs/xfs_ag.h
+++ b/libxfs/xfs_ag.h
@@ -329,12 +329,11 @@ struct aghdr_init_data {
int xfs_ag_init_headers(struct xfs_mount *mp, struct aghdr_init_data *id);
int xfs_ag_shrink_space(struct xfs_perag *pag, struct xfs_trans **tpp,
xfs_extlen_t delta);
-void
-xfs_growfs_compute_deltas(struct xfs_mount *mp, xfs_rfsblock_t *nb,
- int64_t *deltap, xfs_agnumber_t *nagcountp);
int xfs_ag_extend_space(struct xfs_perag *pag, struct xfs_trans *tp,
xfs_extlen_t len);
int xfs_ag_get_geometry(struct xfs_perag *pag, struct xfs_ag_geometry *ageo);
+xfs_agnumber_t xfs_growfs_compute_agcount(struct xfs_mount *mp,
+ xfs_rfsblock_t *nb);
static inline xfs_fsblock_t
xfs_agbno_to_fsb(
--
2.55.0
next prev parent reply other threads:[~2026-08-24 11:46 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 10:39 [PATCH 00/21] xfsprogs: libxfs sync for v7.2 Andrey Albershteyn
2026-08-24 10:39 ` [PATCH 01/21] xfs: Report case sensitivity in fileattr_get Andrey Albershteyn
2026-08-24 10:40 ` [PATCH 02/21] xfs: fix exchmaps reservation limit check Andrey Albershteyn
2026-08-24 10:40 ` [PATCH 03/21] xfs: add a XFS_INODE_TO_AGNO helper Andrey Albershteyn
2026-08-24 10:40 ` [PATCH 04/21] xfs: add a XFS_INODE_TO_AGINO helper Andrey Albershteyn
2026-08-24 10:40 ` [PATCH 05/21] xfs: add a XFS_INO_TO_FSB helper Andrey Albershteyn
2026-08-24 10:40 ` [PATCH 06/21] xfs: add a xfs_rmap_inode_bmbt_owner Andrey Albershteyn
2026-08-24 10:40 ` [PATCH 07/21] xfs: add a xfs_rmap_inode_owner helper Andrey Albershteyn
2026-08-24 10:40 ` [PATCH 08/21] xfs: remove the i_ino field in struct xfs_inode Andrey Albershteyn
2026-08-24 10:40 ` [PATCH 09/21] xfs: cleanup xfs_imap Andrey Albershteyn
2026-08-24 10:40 ` [PATCH 10/21] xfs: remove im_len field in struct xfs_imap Andrey Albershteyn
2026-08-24 10:40 ` [PATCH 11/21] xfs: massage xfs_imap_to_bp into xfs_read_icluster Andrey Albershteyn
2026-08-24 10:40 ` [PATCH 12/21] xfs: store an agbno in struct xfs_imap Andrey Albershteyn
2026-08-24 10:40 ` [PATCH 13/21] xfs: mark struct xfs_imap as __packed Andrey Albershteyn
2026-08-24 10:40 ` [PATCH 14/21] xfs: fix pointer arithmetic error on 32-bit systems Andrey Albershteyn
2026-08-24 10:40 ` [PATCH 15/21] xfs: pass back updated nb from xfs_growfs_compute_deltas Andrey Albershteyn
2026-08-24 10:40 ` Andrey Albershteyn [this message]
2026-08-24 10:40 ` [PATCH 17/21] xfs: fix memory leak in xfs_dqinode_metadir_create() Andrey Albershteyn
2026-08-24 10:40 ` [PATCH 18/21] xfs: fix null pointer dereference in tracepoint Andrey Albershteyn
2026-08-24 10:40 ` [PATCH 19/21] xfs: fix off-by-one in rtrefcount btree root level validation Andrey Albershteyn
2026-08-24 10:40 ` [PATCH 20/21] xfs: fix exchange-range reflink flag clearing issue with INO1_WRITTEN Andrey Albershteyn
2026-08-24 10:40 ` [PATCH 21/21] xfs: check v5 superblock features early Andrey Albershteyn
2026-08-24 18:14 ` [PATCH 00/21] xfsprogs: libxfs sync for v7.2 Darrick J. Wong
2026-08-26 5:13 ` Christoph Hellwig
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=20260824104022.420566-17-aalbersh@kernel.org \
--to=aalbersh@kernel.org \
--cc=bestswngs@gmail.com \
--cc=brauner@kernel.org \
--cc=cem@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=cmaiolino@redhat.com \
--cc=dawei.feng@seu.edu.cn \
--cc=djwong@kernel.org \
--cc=gaoyingjie@uniontech.com \
--cc=hch@lst.de \
--cc=jiapenglin@tencent.com \
--cc=linux-xfs@vger.kernel.org \
--cc=roland.mainz@nrubsig.org \
--cc=xmei5@asu.edu \
/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