Skip to content

Commit a49b7ff

Browse files
Nirjhar-Roy-0211cmaiolino
authored andcommitted
xfs: Refactoring the nagcount and delta calculation
Introduce xfs_growfs_compute_delta() to calculate the nagcount and delta blocks and refactor the code from xfs_growfs_data_private(). No functional changes. Reviewed-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Nirjhar Roy (IBM) <nirjhar.roy.lists@gmail.com> Signed-off-by: Carlos Maiolino <cem@kernel.org>
1 parent 18c16f6 commit a49b7ff

3 files changed

Lines changed: 33 additions & 15 deletions

File tree

fs/xfs/libxfs/xfs_ag.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,34 @@ xfs_ag_shrink_space(
872872
return err2;
873873
}
874874

875+
void
876+
xfs_growfs_compute_deltas(
877+
struct xfs_mount *mp,
878+
xfs_rfsblock_t nb,
879+
int64_t *deltap,
880+
xfs_agnumber_t *nagcountp)
881+
{
882+
xfs_rfsblock_t nb_div, nb_mod;
883+
int64_t delta;
884+
xfs_agnumber_t nagcount;
885+
886+
nb_div = nb;
887+
nb_mod = do_div(nb_div, mp->m_sb.sb_agblocks);
888+
if (nb_mod && nb_mod >= XFS_MIN_AG_BLOCKS)
889+
nb_div++;
890+
else if (nb_mod)
891+
nb = nb_div * mp->m_sb.sb_agblocks;
892+
893+
if (nb_div > XFS_MAX_AGNUMBER + 1) {
894+
nb_div = XFS_MAX_AGNUMBER + 1;
895+
nb = nb_div * mp->m_sb.sb_agblocks;
896+
}
897+
nagcount = nb_div;
898+
delta = nb - mp->m_sb.sb_dblocks;
899+
*deltap = delta;
900+
*nagcountp = nagcount;
901+
}
902+
875903
/*
876904
* Extent the AG indicated by the @id by the length passed in
877905
*/

fs/xfs/libxfs/xfs_ag.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ struct aghdr_init_data {
331331
int xfs_ag_init_headers(struct xfs_mount *mp, struct aghdr_init_data *id);
332332
int xfs_ag_shrink_space(struct xfs_perag *pag, struct xfs_trans **tpp,
333333
xfs_extlen_t delta);
334+
void
335+
xfs_growfs_compute_deltas(struct xfs_mount *mp, xfs_rfsblock_t nb,
336+
int64_t *deltap, xfs_agnumber_t *nagcountp);
334337
int xfs_ag_extend_space(struct xfs_perag *pag, struct xfs_trans *tp,
335338
xfs_extlen_t len);
336339
int xfs_ag_get_geometry(struct xfs_perag *pag, struct xfs_ag_geometry *ageo);

fs/xfs/xfs_fsops.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,17 @@ xfs_growfs_data_private(
9595
struct xfs_growfs_data *in) /* growfs data input struct */
9696
{
9797
xfs_agnumber_t oagcount = mp->m_sb.sb_agcount;
98+
xfs_rfsblock_t nb = in->newblocks;
9899
struct xfs_buf *bp;
99100
int error;
100101
xfs_agnumber_t nagcount;
101102
xfs_agnumber_t nagimax = 0;
102-
xfs_rfsblock_t nb, nb_div, nb_mod;
103103
int64_t delta;
104104
bool lastag_extended = false;
105105
struct xfs_trans *tp;
106106
struct aghdr_init_data id = {};
107107
struct xfs_perag *last_pag;
108108

109-
nb = in->newblocks;
110109
error = xfs_sb_validate_fsb_count(&mp->m_sb, nb);
111110
if (error)
112111
return error;
@@ -125,20 +124,8 @@ xfs_growfs_data_private(
125124
mp->m_sb.sb_rextsize);
126125
if (error)
127126
return error;
127+
xfs_growfs_compute_deltas(mp, nb, &delta, &nagcount);
128128

129-
nb_div = nb;
130-
nb_mod = do_div(nb_div, mp->m_sb.sb_agblocks);
131-
if (nb_mod && nb_mod >= XFS_MIN_AG_BLOCKS)
132-
nb_div++;
133-
else if (nb_mod)
134-
nb = nb_div * mp->m_sb.sb_agblocks;
135-
136-
if (nb_div > XFS_MAX_AGNUMBER + 1) {
137-
nb_div = XFS_MAX_AGNUMBER + 1;
138-
nb = nb_div * mp->m_sb.sb_agblocks;
139-
}
140-
nagcount = nb_div;
141-
delta = nb - mp->m_sb.sb_dblocks;
142129
/*
143130
* Reject filesystems with a single AG because they are not
144131
* supported, and reject a shrink operation that would cause a

0 commit comments

Comments
 (0)