Skip to content

Commit 759cc19

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
xfs: add group based bno conversion helpers
Add/move the blocks, blklog and blkmask fields to the generic groups structure so that code can work with AGs and RTGs by just using the right index into the array. Then, add convenience helpers to convert block numbers based on the generic group. This will allow writing code that doesn't care if it is used on AGs or the upcoming realtime groups. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent 198febb commit 759cc19

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed

fs/xfs/libxfs/xfs_group.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,12 @@ xfs_group_insert(
214214
#endif
215215
return error;
216216
}
217+
218+
struct xfs_group *
219+
xfs_group_get_by_fsb(
220+
struct xfs_mount *mp,
221+
xfs_fsblock_t fsbno,
222+
enum xfs_group_type type)
223+
{
224+
return xfs_group_get(mp, xfs_fsb_to_gno(mp, fsbno, type), type);
225+
}

fs/xfs/libxfs/xfs_group.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ struct xfs_group {
4646

4747
struct xfs_group *xfs_group_get(struct xfs_mount *mp, uint32_t index,
4848
enum xfs_group_type type);
49+
struct xfs_group *xfs_group_get_by_fsb(struct xfs_mount *mp,
50+
xfs_fsblock_t fsbno, enum xfs_group_type type);
4951
struct xfs_group *xfs_group_hold(struct xfs_group *xg);
5052
void xfs_group_put(struct xfs_group *xg);
5153

@@ -72,4 +74,58 @@ int xfs_group_insert(struct xfs_mount *mp, struct xfs_group *xg,
7274
#define xfs_group_marked(_mp, _type, _mark) \
7375
xa_marked(&(_mp)->m_groups[(_type)].xa, (_mark))
7476

77+
static inline xfs_agblock_t
78+
xfs_group_max_blocks(
79+
struct xfs_group *xg)
80+
{
81+
return xg->xg_mount->m_groups[xg->xg_type].blocks;
82+
}
83+
84+
static inline xfs_fsblock_t
85+
xfs_group_start_fsb(
86+
struct xfs_group *xg)
87+
{
88+
return ((xfs_fsblock_t)xg->xg_gno) <<
89+
xg->xg_mount->m_groups[xg->xg_type].blklog;
90+
}
91+
92+
static inline xfs_fsblock_t
93+
xfs_gbno_to_fsb(
94+
struct xfs_group *xg,
95+
xfs_agblock_t gbno)
96+
{
97+
return xfs_group_start_fsb(xg) | gbno;
98+
}
99+
100+
static inline xfs_daddr_t
101+
xfs_gbno_to_daddr(
102+
struct xfs_group *xg,
103+
xfs_agblock_t gbno)
104+
{
105+
struct xfs_mount *mp = xg->xg_mount;
106+
uint32_t blocks = mp->m_groups[xg->xg_type].blocks;
107+
108+
return XFS_FSB_TO_BB(mp, (xfs_fsblock_t)xg->xg_gno * blocks + gbno);
109+
}
110+
111+
static inline uint32_t
112+
xfs_fsb_to_gno(
113+
struct xfs_mount *mp,
114+
xfs_fsblock_t fsbno,
115+
enum xfs_group_type type)
116+
{
117+
if (!mp->m_groups[type].blklog)
118+
return 0;
119+
return fsbno >> mp->m_groups[type].blklog;
120+
}
121+
122+
static inline xfs_agblock_t
123+
xfs_fsb_to_gbno(
124+
struct xfs_mount *mp,
125+
xfs_fsblock_t fsbno,
126+
enum xfs_group_type type)
127+
{
128+
return fsbno & mp->m_groups[type].blkmask;
129+
}
130+
75131
#endif /* __LIBXFS_GROUP_H */

fs/xfs/libxfs/xfs_sb.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,8 @@ xfs_sb_mount_common(
988988
struct xfs_mount *mp,
989989
struct xfs_sb *sbp)
990990
{
991+
struct xfs_groups *ags = &mp->m_groups[XG_TYPE_AG];
992+
991993
mp->m_agfrotor = 0;
992994
atomic_set(&mp->m_agirotor, 0);
993995
mp->m_maxagi = mp->m_sb.sb_agcount;
@@ -998,6 +1000,11 @@ xfs_sb_mount_common(
9981000
mp->m_blockmask = sbp->sb_blocksize - 1;
9991001
mp->m_blockwsize = sbp->sb_blocksize >> XFS_WORDLOG;
10001002
mp->m_blockwmask = mp->m_blockwsize - 1;
1003+
1004+
ags->blocks = mp->m_sb.sb_agblocks;
1005+
ags->blklog = mp->m_sb.sb_agblklog;
1006+
ags->blkmask = xfs_mask32lo(mp->m_sb.sb_agblklog);
1007+
10011008
xfs_mount_sb_set_rextsize(mp, sbp);
10021009

10031010
mp->m_alloc_mxr[0] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, true);

fs/xfs/xfs_mount.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,38 @@ struct xfs_inodegc {
7171
unsigned int cpu;
7272
};
7373

74+
/*
75+
* Container for each type of groups, used to look up individual groups and
76+
* describes the geometry.
77+
*/
7478
struct xfs_groups {
7579
struct xarray xa;
80+
81+
/*
82+
* Maximum capacity of the group in FSBs.
83+
*
84+
* Each group is laid out densely in the daddr space. For the
85+
* degenerate case of a pre-rtgroups filesystem, the incore rtgroup
86+
* pretends to have a zero-block and zero-blklog rtgroup.
87+
*/
88+
uint32_t blocks;
89+
90+
/*
91+
* Log(2) of the logical size of each group.
92+
*
93+
* Compared to the blocks field above this is rounded up to the next
94+
* power of two, and thus lays out the xfs_fsblock_t/xfs_rtblock_t
95+
* space sparsely with a hole from blocks to (1 << blklog) at the end
96+
* of each group.
97+
*/
98+
uint8_t blklog;
99+
100+
/*
101+
* Mask to extract the group-relative block number from a FSB.
102+
* For a pre-rtgroups filesystem we pretend to have one very large
103+
* rtgroup, so this mask must be 64-bit.
104+
*/
105+
uint64_t blkmask;
76106
};
77107

78108
/*

0 commit comments

Comments
 (0)