Skip to content

Commit 0e2af92

Browse files
author
Darrick J. Wong
committed
xfs: improve FSGROWFSRT precondition checking
Improve the checking at the start of a realtime grow operation so that we avoid accidentally set a new extent size that is too large and avoid adding an rt volume to a filesystem with rmap or reflink because we don't support rt rmap or reflink yet. While we're at it, separate the checks so that we're only testing one aspect at a time. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Dave Chinner <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent 5aa5b27 commit 0e2af92

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

fs/xfs/xfs_rtalloc.c

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -923,16 +923,41 @@ xfs_growfs_rt(
923923
uint8_t *rsum_cache; /* old summary cache */
924924

925925
sbp = &mp->m_sb;
926-
/*
927-
* Initial error checking.
928-
*/
926+
929927
if (!capable(CAP_SYS_ADMIN))
930928
return -EPERM;
931-
if (mp->m_rtdev_targp == NULL || mp->m_rbmip == NULL ||
932-
(nrblocks = in->newblocks) <= sbp->sb_rblocks ||
933-
(sbp->sb_rblocks && (in->extsize != sbp->sb_rextsize)))
929+
930+
/* Needs to have been mounted with an rt device. */
931+
if (!XFS_IS_REALTIME_MOUNT(mp))
932+
return -EINVAL;
933+
/*
934+
* Mount should fail if the rt bitmap/summary files don't load, but
935+
* we'll check anyway.
936+
*/
937+
if (!mp->m_rbmip || !mp->m_rsumip)
938+
return -EINVAL;
939+
940+
/* Shrink not supported. */
941+
if (in->newblocks <= sbp->sb_rblocks)
942+
return -EINVAL;
943+
944+
/* Can only change rt extent size when adding rt volume. */
945+
if (sbp->sb_rblocks > 0 && in->extsize != sbp->sb_rextsize)
946+
return -EINVAL;
947+
948+
/* Range check the extent size. */
949+
if (XFS_FSB_TO_B(mp, in->extsize) > XFS_MAX_RTEXTSIZE ||
950+
XFS_FSB_TO_B(mp, in->extsize) < XFS_MIN_RTEXTSIZE)
934951
return -EINVAL;
935-
if ((error = xfs_sb_validate_fsb_count(sbp, nrblocks)))
952+
953+
/* Unsupported realtime features. */
954+
if (xfs_sb_version_hasrmapbt(&mp->m_sb) ||
955+
xfs_sb_version_hasreflink(&mp->m_sb))
956+
return -EOPNOTSUPP;
957+
958+
nrblocks = in->newblocks;
959+
error = xfs_sb_validate_fsb_count(sbp, nrblocks);
960+
if (error)
936961
return error;
937962
/*
938963
* Read in the last block of the device, make sure it exists.

0 commit comments

Comments
 (0)