diff options
author | Darrick J. Wong <djwong@kernel.org> | 2024-11-03 20:19:35 -0800 |
---|---|---|
committer | Darrick J. Wong <djwong@kernel.org> | 2024-11-05 13:38:44 -0800 |
commit | e0b5b97dde8e4737d06cb5888abd88373abc22df (patch) | |
tree | 2e3bc144a4a8a44bd5b31281a9758b3e83ac1371 /fs/xfs/libxfs/xfs_group.h | |
parent | ceaa0bd773e2d6d5726d6535f605ecd6b26d2fcc (diff) | |
download | linux-e0b5b97dde8e4737d06cb5888abd88373abc22df.tar.gz linux-e0b5b97dde8e4737d06cb5888abd88373abc22df.tar.bz2 linux-e0b5b97dde8e4737d06cb5888abd88373abc22df.zip |
xfs: move the min and max group block numbers to xfs_group
Move the min and max agblock numbers to the generic xfs_group structure
so that we can start building validators for extents within an rtgroup.
While we're at it, use check_add_overflow for the extent length
computation because that has much better overflow checking.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'fs/xfs/libxfs/xfs_group.h')
-rw-r--r-- | fs/xfs/libxfs/xfs_group.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/fs/xfs/libxfs/xfs_group.h b/fs/xfs/libxfs/xfs_group.h index 5b7362277c3f..242b05627c7a 100644 --- a/fs/xfs/libxfs/xfs_group.h +++ b/fs/xfs/libxfs/xfs_group.h @@ -12,6 +12,10 @@ struct xfs_group { atomic_t xg_ref; /* passive reference count */ atomic_t xg_active_ref; /* active reference count */ + /* Precalculated geometry info */ + uint32_t xg_block_count; /* max usable gbno */ + uint32_t xg_min_gbno; /* min usable gbno */ + #ifdef __KERNEL__ /* -- kernel only structures below this line -- */ @@ -128,4 +132,33 @@ xfs_fsb_to_gbno( return fsbno & mp->m_groups[type].blkmask; } +static inline bool +xfs_verify_gbno( + struct xfs_group *xg, + uint32_t gbno) +{ + if (gbno >= xg->xg_block_count) + return false; + if (gbno < xg->xg_min_gbno) + return false; + return true; +} + +static inline bool +xfs_verify_gbext( + struct xfs_group *xg, + uint32_t gbno, + uint32_t glen) +{ + uint32_t end; + + if (!xfs_verify_gbno(xg, gbno)) + return false; + if (glen == 0 || check_add_overflow(gbno, glen - 1, &end)) + return false; + if (!xfs_verify_gbno(xg, end)) + return false; + return true; +} + #endif /* __LIBXFS_GROUP_H */ |