Skip to content

Commit 0ec73eb

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: add a xfs_groups_to_rfsbs helper
Plus a rtgroup wrapper and use that to avoid overflows when converting zone/rtg counts to block counts. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Carlos Maiolino <cem@kernel.org>
1 parent d8a823c commit 0ec73eb

4 files changed

Lines changed: 21 additions & 7 deletions

File tree

fs/xfs/libxfs/xfs_group.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ xfs_group_max_blocks(
9898
return xg->xg_mount->m_groups[xg->xg_type].blocks;
9999
}
100100

101+
static inline xfs_rfsblock_t
102+
xfs_groups_to_rfsbs(
103+
struct xfs_mount *mp,
104+
uint32_t nr_groups,
105+
enum xfs_group_type type)
106+
{
107+
return (xfs_rfsblock_t)mp->m_groups[type].blocks * nr_groups;
108+
}
109+
101110
static inline xfs_fsblock_t
102111
xfs_group_start_fsb(
103112
struct xfs_group *xg)

fs/xfs/libxfs/xfs_rtgroup.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,4 +371,12 @@ static inline int xfs_initialize_rtgroups(struct xfs_mount *mp,
371371
# define xfs_rtgroup_get_geometry(rtg, rgeo) (-EOPNOTSUPP)
372372
#endif /* CONFIG_XFS_RT */
373373

374+
static inline xfs_rfsblock_t
375+
xfs_rtgs_to_rfsbs(
376+
struct xfs_mount *mp,
377+
uint32_t nr_groups)
378+
{
379+
return xfs_groups_to_rfsbs(mp, nr_groups, XG_TYPE_RTG);
380+
}
381+
374382
#endif /* __LIBXFS_RTGROUP_H */

fs/xfs/xfs_zone_gc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ xfs_zoned_need_gc(
181181
available = xfs_estimate_freecounter(mp, XC_FREE_RTAVAILABLE);
182182

183183
if (available <
184-
mp->m_groups[XG_TYPE_RTG].blocks *
185-
(mp->m_max_open_zones - XFS_OPEN_GC_ZONES))
184+
xfs_rtgs_to_rfsbs(mp, mp->m_max_open_zones - XFS_OPEN_GC_ZONES))
186185
return true;
187186

188187
free = xfs_estimate_freecounter(mp, XC_FREE_RTEXTENTS);

fs/xfs/xfs_zone_space_resv.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,10 @@ xfs_zoned_default_resblks(
5454
{
5555
switch (ctr) {
5656
case XC_FREE_RTEXTENTS:
57-
return (uint64_t)XFS_RESERVED_ZONES *
58-
mp->m_groups[XG_TYPE_RTG].blocks +
59-
mp->m_sb.sb_rtreserved;
57+
return xfs_rtgs_to_rfsbs(mp, XFS_RESERVED_ZONES) +
58+
mp->m_sb.sb_rtreserved;
6059
case XC_FREE_RTAVAILABLE:
61-
return (uint64_t)XFS_GC_ZONES *
62-
mp->m_groups[XG_TYPE_RTG].blocks;
60+
return xfs_rtgs_to_rfsbs(mp, XFS_GC_ZONES);
6361
default:
6462
ASSERT(0);
6563
return 0;

0 commit comments

Comments
 (0)