Skip to content

Commit bde86b4

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
xfs: factor out a xfs_growfs_check_rtgeom helper
Split the check that the rtsummary fits into the log into a separate helper, and use xfs_growfs_rt_alloc_fake_mount to calculate the new RT geometry. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> [djwong: avoid division for the 0-rtx growfs check] Signed-off-by: Darrick J. Wong <[email protected]>
1 parent fc233f1 commit bde86b4

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

fs/xfs/xfs_rtalloc.c

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,31 @@ xfs_growfs_rtg(
10231023
return error;
10241024
}
10251025

1026+
static int
1027+
xfs_growfs_check_rtgeom(
1028+
const struct xfs_mount *mp,
1029+
xfs_rfsblock_t rblocks,
1030+
xfs_extlen_t rextsize)
1031+
{
1032+
struct xfs_mount *nmp;
1033+
int error = 0;
1034+
1035+
nmp = xfs_growfs_rt_alloc_fake_mount(mp, rblocks, rextsize);
1036+
if (!nmp)
1037+
return -ENOMEM;
1038+
1039+
/*
1040+
* New summary size can't be more than half the size of the log. This
1041+
* prevents us from getting a log overflow, since we'll log basically
1042+
* the whole summary file at once.
1043+
*/
1044+
if (nmp->m_rsumblocks > (mp->m_sb.sb_logblocks >> 1))
1045+
error = -EINVAL;
1046+
1047+
kfree(nmp);
1048+
return error;
1049+
}
1050+
10261051
/*
10271052
* Grow the realtime area of the filesystem.
10281053
*/
@@ -1031,9 +1056,6 @@ xfs_growfs_rt(
10311056
xfs_mount_t *mp, /* mount point for filesystem */
10321057
xfs_growfs_rt_t *in) /* growfs rt input struct */
10331058
{
1034-
xfs_rtxnum_t nrextents;
1035-
xfs_extlen_t nrbmblocks;
1036-
xfs_extlen_t nrsumblocks;
10371059
struct xfs_buf *bp;
10381060
xfs_agblock_t old_rextsize = mp->m_sb.sb_rextsize;
10391061
int error;
@@ -1082,20 +1104,13 @@ xfs_growfs_rt(
10821104
/*
10831105
* Calculate new parameters. These are the final values to be reached.
10841106
*/
1085-
nrextents = div_u64(in->newblocks, in->extsize);
10861107
error = -EINVAL;
1087-
if (nrextents == 0)
1108+
if (in->newblocks < in->extsize)
10881109
goto out_unlock;
1089-
nrbmblocks = xfs_rtbitmap_blockcount(mp, nrextents);
1090-
nrsumblocks = xfs_rtsummary_blockcount(mp,
1091-
xfs_compute_rextslog(nrextents) + 1, nrbmblocks);
10921110

1093-
/*
1094-
* New summary size can't be more than half the size of
1095-
* the log. This prevents us from getting a log overflow,
1096-
* since we'll log basically the whole summary file at once.
1097-
*/
1098-
if (nrsumblocks > (mp->m_sb.sb_logblocks >> 1))
1111+
/* Make sure the new fs size won't cause problems with the log. */
1112+
error = xfs_growfs_check_rtgeom(mp, in->newblocks, in->extsize);
1113+
if (error)
10991114
goto out_unlock;
11001115

11011116
error = xfs_growfs_rtg(mp, in->newblocks, in->extsize);

0 commit comments

Comments
 (0)