Skip to content

Commit 1029f08

Browse files
author
Darrick J. Wong
committed
xfs: factor out a xfs_growfs_rt_alloc_fake_mount helper
Split the code to set up a fake mount point to calculate new RT geometry out of xfs_growfs_rt_bmblock so that it can be reused. Note that this changes the rmblocks calculation method to be based on the passed in rblocks and extsize and not the explicitly passed one, but both methods will always lead to the same result. The new version just does a little bit more math while being more general. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent cb9cd6e commit 1029f08

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

fs/xfs/xfs_rtalloc.c

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,36 @@ xfs_rtginode_ensure(
734734
return xfs_rtginode_create(rtg, type, true);
735735
}
736736

737+
static struct xfs_mount *
738+
xfs_growfs_rt_alloc_fake_mount(
739+
const struct xfs_mount *mp,
740+
xfs_rfsblock_t rblocks,
741+
xfs_agblock_t rextsize)
742+
{
743+
struct xfs_mount *nmp;
744+
745+
nmp = kmemdup(mp, sizeof(*mp), GFP_KERNEL);
746+
if (!nmp)
747+
return NULL;
748+
nmp->m_sb.sb_rextsize = rextsize;
749+
xfs_mount_sb_set_rextsize(nmp, &nmp->m_sb);
750+
nmp->m_sb.sb_rblocks = rblocks;
751+
nmp->m_sb.sb_rextents = xfs_rtb_to_rtx(nmp, nmp->m_sb.sb_rblocks);
752+
nmp->m_sb.sb_rbmblocks = xfs_rtbitmap_blockcount(nmp,
753+
nmp->m_sb.sb_rextents);
754+
nmp->m_sb.sb_rextslog = xfs_compute_rextslog(nmp->m_sb.sb_rextents);
755+
nmp->m_rsumlevels = nmp->m_sb.sb_rextslog + 1;
756+
nmp->m_rsumblocks = xfs_rtsummary_blockcount(nmp, nmp->m_rsumlevels,
757+
nmp->m_sb.sb_rbmblocks);
758+
759+
if (rblocks > 0)
760+
nmp->m_features |= XFS_FEAT_REALTIME;
761+
762+
/* recompute growfsrt reservation from new rsumsize */
763+
xfs_trans_resv_calc(nmp, &nmp->m_resv);
764+
return nmp;
765+
}
766+
737767
static int
738768
xfs_growfs_rt_bmblock(
739769
struct xfs_rtgroup *rtg,
@@ -756,25 +786,15 @@ xfs_growfs_rt_bmblock(
756786
xfs_rtbxlen_t freed_rtx;
757787
int error;
758788

759-
789+
/*
790+
* Calculate new sb and mount fields for this round.
791+
*/
760792
nrblocks_step = (bmbno + 1) * NBBY * mp->m_sb.sb_blocksize * rextsize;
761-
762-
nmp = nargs.mp = kmemdup(mp, sizeof(*mp), GFP_KERNEL);
793+
nmp = nargs.mp = xfs_growfs_rt_alloc_fake_mount(mp,
794+
min(nrblocks, nrblocks_step), rextsize);
763795
if (!nmp)
764796
return -ENOMEM;
765797

766-
/*
767-
* Calculate new sb and mount fields for this round.
768-
*/
769-
nmp->m_sb.sb_rextsize = rextsize;
770-
xfs_mount_sb_set_rextsize(nmp, &nmp->m_sb);
771-
nmp->m_sb.sb_rbmblocks = bmbno + 1;
772-
nmp->m_sb.sb_rblocks = min(nrblocks, nrblocks_step);
773-
nmp->m_sb.sb_rextents = xfs_rtb_to_rtx(nmp, nmp->m_sb.sb_rblocks);
774-
nmp->m_sb.sb_rextslog = xfs_compute_rextslog(nmp->m_sb.sb_rextents);
775-
nmp->m_rsumlevels = nmp->m_sb.sb_rextslog + 1;
776-
nmp->m_rsumblocks = xfs_rtsummary_blockcount(mp, nmp->m_rsumlevels,
777-
nmp->m_sb.sb_rbmblocks);
778798
rtg->rtg_extents = xfs_rtgroup_extents(nmp, rtg_rgno(rtg));
779799

780800
/*

0 commit comments

Comments
 (0)