xfs: improve RT geometry validation
PATCH 1/1 xfs: improve RT geometry validation
Make sure the rtgcount is plausible for the given RT group size.
--- fs/xfs/libxfs/xfs_sb.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
fs/xfs/libxfs/xfs_sb.c +15 -7
@@ -302,17 +302,25 @@ xfs_validate_rt_geometry(return false;if (xfs_sb_is_v5 (sbp) && - (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_ZONED )) { + (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_METADIR )) { +uint64_t nr_rgs;uint32_t mod;/* -* Zoned RT devices must be aligned to the RT group size, -* because garbage collection assumes that all zones have the -* same size to avoid insane complexity if that weren't the -* case. +* Check that the number of rgcounts is plausible for the RG +* size. +*/ + nr_rgs =div_u64_rem (sbp->sb_rextents, sbp->sb_rgextents, &mod); +if (nr_rgs != sbp->sb_rgcount + !!mod) +return false; + +/* +* Zoned RT devices must be aligned to the RT group size because +* garbage collection assumes that all zones have the same size +* to avoid insane complexity if that weren't the case. */ -div_u64_rem (sbp->sb_rextents, sbp->sb_rgextents, &mod); -if (mod) +if ((sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_ZONED ) && + mod >0 )return false; }
Signature · 1 line
2.53.0
Quoted 33 lines · Christoph Hellwig
Make sure the rtgcount is plausible for the given RT group size.
Signed-off-by Christoph Hellwig <[email protected]>--- fs/xfs/libxfs/xfs_sb.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)fs/xfs/libxfs/xfs_sb.c +10
-5@@ -302,17 +302,25 @@ xfs_validate_rt_geometry(return false;if (xfs_sb_is_v5 (sbp) && - (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_ZONED )) { + (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_METADIR )) { +uint64_t nr_rgs;uint32_t mod;/* -* Zoned RT devices must be aligned to the RT group size, -* because garbage collection assumes that all zones have the -* same size to avoid insane complexity if that weren't the -* case. +* Check that the number of rgcounts is plausible for the RG +* size. +*/ + nr_rgs =div_u64_rem (sbp->sb_rextents, sbp->sb_rgextents, &mod); +if (nr_rgs != sbp->sb_rgcount + !!mod) +return false; + +/*
fs/xfs/libxfs/xfs_sb.c xfs_validate_rt_geometry( · line 325
Quoted 10 lines
fs/xfs/libxfs/xfs_sb.c +5
-2+* Zoned RT devices must be aligned to the RT group size because +* garbage collection assumes that all zones have the same size +* to avoid insane complexity if that weren't the case. */ -div_u64_rem (sbp->sb_rextents, sbp->sb_rgextents, &mod); -if (mod) +if ((sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_ZONED ) && + mod >0 )return false; }
Looks good
Quoted 4 lines
fs/xfs/libxfs/xfs_sb.c +0
-1--2.53.0
Quoted 21 lines · Christoph Hellwig
Make sure the rtgcount is plausible for the given RT group size.
Signed-off-by Christoph Hellwig <[email protected]>--- fs/xfs/libxfs/xfs_sb.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)fs/xfs/libxfs/xfs_sb.c +2
-1@@ -302,17 +302,25 @@ xfs_validate_rt_geometry(return false;if (xfs_sb_is_v5 (sbp) && - (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_ZONED )) { + (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_METADIR )) { +uint64_t nr_rgs;uint32_t mod;/*
fs/xfs/libxfs/xfs_sb.c xfs_validate_rt_geometry( · line 315
Quoted 10 lines
fs/xfs/libxfs/xfs_sb.c +6
-4-* Zoned RT devices must be aligned to the RT group size, -* because garbage collection assumes that all zones have the -* same size to avoid insane complexity if that weren't the -* case. +* Check that the number of rgcounts is plausible for the RG +* size. +*/ + nr_rgs =div_u64_rem (sbp->sb_rextents, sbp->sb_rgextents, &mod); +if (nr_rgs != sbp->sb_rgcount + !!mod) +return false;
Isn't this already covered by xfs_validate_sb_rtgroups?
groups = howmany_64(sbp->sb_rextents, sbp->sb_rgextents);
if (groups != sbp->sb_rgcount) {
xfs_warn(mp,
"Realtime groups (%u) do not cover the entire rt section; need (%llu) groups.",
sbp->sb_rgcount, groups);
return -EINVAL;
}fs/xfs/libxfs/xfs_sb.c xfs_validate_rt_geometry( · line 324
Quoted 11 lines
fs/xfs/libxfs/xfs_sb.c +7
-2+ +/* +* Zoned RT devices must be aligned to the RT group size because +* garbage collection assumes that all zones have the same size +* to avoid insane complexity if that weren't the case. */ -div_u64_rem (sbp->sb_rextents, sbp->sb_rgextents, &mod); -if (mod) +if ((sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_ZONED ) && + mod >0 )return false;
And shouldn't this be in xfs_validate_sb_zoned?
Or do you want this in xfs_validate_rt_geometry because that's what xfs_repair calls to check the superblock?
--D
Quoted 1 line · Darrick J. Wong
Isn't this already covered by
xfs_validate_sb_rtgroups?
From a quick look it should...
Quoted 7 lines
fs/xfs/libxfs/xfs_sb.c xfs_validate_rt_geometry( · line 324
Quoted 5 lines
fs/xfs/libxfs/xfs_sb.c +2
-2-div_u64_rem (sbp->sb_rextents, sbp->sb_rgextents, &mod); -if (mod) +if ((sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_ZONED ) && + mod >0 )return false;And shouldn't this be in
xfs_validate_sb_zoned?
This just slightly moves code.
Quoted 2 lines
Or do you want this in
xfs_validate_rt_geometrybecause that's whatxfs_repaircalls to check the superblock?
I guess. At least it was repair that went off on my badly messed up file system without this fix.
Maybe it's time to go back to the drawing board for the sb validation.
Quoted 15 lines · Christoph Hellwig
Quoted 1 line · Darrick J. Wong
Isn't this already covered by
xfs_validate_sb_rtgroups?From a quick look it should...
Quoted 7 lines
fs/xfs/libxfs/xfs_sb.c xfs_validate_rt_geometry( · line 324
Quoted 5 lines
fs/xfs/libxfs/xfs_sb.c +2
-2-div_u64_rem (sbp->sb_rextents, sbp->sb_rgextents, &mod); -if (mod) +if ((sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_ZONED ) && + mod >0 )return false;And shouldn't this be in
xfs_validate_sb_zoned?This just slightly moves code.
Quoted 7 lines
Quoted 2 lines
Or do you want this in
xfs_validate_rt_geometrybecause that's whatxfs_repaircalls to check the superblock?I guess. At least it was repair that went off on my badly messed up file system without this fix.
Maybe it's time to go back to the drawing board for the sb validation.
Yeah, it's unfortunate that xfs_repair duplicates most of that sb validation code just so it can return an enum instead of xfs_err()ing all over the place. :/
--D