Skip to content

Commit 16e1fbd

Browse files
Darrick J. WongChandan Babu R
authored andcommitted
xfs: take m_growlock when running growfsrt
Take the grow lock when we're expanding the realtime volume, like we do for the other growfs calls. Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]> Signed-off-by: Chandan Babu R <[email protected]>
1 parent ca6448a commit 16e1fbd

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

fs/xfs/xfs_rtalloc.c

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -821,51 +821,58 @@ xfs_growfs_rt(
821821
/* Needs to have been mounted with an rt device. */
822822
if (!XFS_IS_REALTIME_MOUNT(mp))
823823
return -EINVAL;
824+
825+
if (!mutex_trylock(&mp->m_growlock))
826+
return -EWOULDBLOCK;
824827
/*
825828
* Mount should fail if the rt bitmap/summary files don't load, but
826829
* we'll check anyway.
827830
*/
831+
error = -EINVAL;
828832
if (!mp->m_rbmip || !mp->m_rsumip)
829-
return -EINVAL;
833+
goto out_unlock;
830834

831835
/* Shrink not supported. */
832836
if (in->newblocks <= sbp->sb_rblocks)
833-
return -EINVAL;
837+
goto out_unlock;
834838

835839
/* Can only change rt extent size when adding rt volume. */
836840
if (sbp->sb_rblocks > 0 && in->extsize != sbp->sb_rextsize)
837-
return -EINVAL;
841+
goto out_unlock;
838842

839843
/* Range check the extent size. */
840844
if (XFS_FSB_TO_B(mp, in->extsize) > XFS_MAX_RTEXTSIZE ||
841845
XFS_FSB_TO_B(mp, in->extsize) < XFS_MIN_RTEXTSIZE)
842-
return -EINVAL;
846+
goto out_unlock;
843847

844848
/* Unsupported realtime features. */
849+
error = -EOPNOTSUPP;
845850
if (xfs_has_rmapbt(mp) || xfs_has_reflink(mp) || xfs_has_quota(mp))
846-
return -EOPNOTSUPP;
851+
goto out_unlock;
847852

848853
nrblocks = in->newblocks;
849854
error = xfs_sb_validate_fsb_count(sbp, nrblocks);
850855
if (error)
851-
return error;
856+
goto out_unlock;
852857
/*
853858
* Read in the last block of the device, make sure it exists.
854859
*/
855860
error = xfs_buf_read_uncached(mp->m_rtdev_targp,
856861
XFS_FSB_TO_BB(mp, nrblocks - 1),
857862
XFS_FSB_TO_BB(mp, 1), 0, &bp, NULL);
858863
if (error)
859-
return error;
864+
goto out_unlock;
860865
xfs_buf_relse(bp);
861866

862867
/*
863868
* Calculate new parameters. These are the final values to be reached.
864869
*/
865870
nrextents = nrblocks;
866871
do_div(nrextents, in->extsize);
867-
if (!xfs_validate_rtextents(nrextents))
868-
return -EINVAL;
872+
if (!xfs_validate_rtextents(nrextents)) {
873+
error = -EINVAL;
874+
goto out_unlock;
875+
}
869876
nrbmblocks = xfs_rtbitmap_blockcount(mp, nrextents);
870877
nrextslog = xfs_compute_rextslog(nrextents);
871878
nrsumlevels = nrextslog + 1;
@@ -876,8 +883,11 @@ xfs_growfs_rt(
876883
* the log. This prevents us from getting a log overflow,
877884
* since we'll log basically the whole summary file at once.
878885
*/
879-
if (nrsumblocks > (mp->m_sb.sb_logblocks >> 1))
880-
return -EINVAL;
886+
if (nrsumblocks > (mp->m_sb.sb_logblocks >> 1)) {
887+
error = -EINVAL;
888+
goto out_unlock;
889+
}
890+
881891
/*
882892
* Get the old block counts for bitmap and summary inodes.
883893
* These can't change since other growfs callers are locked out.
@@ -889,10 +899,10 @@ xfs_growfs_rt(
889899
*/
890900
error = xfs_growfs_rt_alloc(mp, rbmblocks, nrbmblocks, mp->m_rbmip);
891901
if (error)
892-
return error;
902+
goto out_unlock;
893903
error = xfs_growfs_rt_alloc(mp, rsumblocks, nrsumblocks, mp->m_rsumip);
894904
if (error)
895-
return error;
905+
goto out_unlock;
896906

897907
rsum_cache = mp->m_rsum_cache;
898908
if (nrbmblocks != sbp->sb_rbmblocks)
@@ -1059,6 +1069,8 @@ xfs_growfs_rt(
10591069
}
10601070
}
10611071

1072+
out_unlock:
1073+
mutex_unlock(&mp->m_growlock);
10621074
return error;
10631075
}
10641076

0 commit comments

Comments
 (0)