Commit 56370ea6 authored by Darrick J. Wong's avatar Darrick J. Wong

xfs: refactor btree cursor allocation function

Refactor btree allocation to a common helper.
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
Reviewed-by: default avatarChandan Babu R <chandan.babu@oracle.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
parent 69724d92
...@@ -477,11 +477,7 @@ xfs_allocbt_init_common( ...@@ -477,11 +477,7 @@ xfs_allocbt_init_common(
ASSERT(btnum == XFS_BTNUM_BNO || btnum == XFS_BTNUM_CNT); ASSERT(btnum == XFS_BTNUM_BNO || btnum == XFS_BTNUM_CNT);
cur = kmem_cache_zalloc(xfs_btree_cur_zone, GFP_NOFS | __GFP_NOFAIL); cur = xfs_btree_alloc_cursor(mp, tp, btnum);
cur->bc_tp = tp;
cur->bc_mp = mp;
cur->bc_btnum = btnum;
cur->bc_ag.abt.active = false; cur->bc_ag.abt.active = false;
if (btnum == XFS_BTNUM_CNT) { if (btnum == XFS_BTNUM_CNT) {
......
...@@ -552,12 +552,8 @@ xfs_bmbt_init_cursor( ...@@ -552,12 +552,8 @@ xfs_bmbt_init_cursor(
struct xfs_btree_cur *cur; struct xfs_btree_cur *cur;
ASSERT(whichfork != XFS_COW_FORK); ASSERT(whichfork != XFS_COW_FORK);
cur = kmem_cache_zalloc(xfs_btree_cur_zone, GFP_NOFS | __GFP_NOFAIL); cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_BMAP);
cur->bc_tp = tp;
cur->bc_mp = mp;
cur->bc_nlevels = be16_to_cpu(ifp->if_broot->bb_level) + 1; cur->bc_nlevels = be16_to_cpu(ifp->if_broot->bb_level) + 1;
cur->bc_btnum = XFS_BTNUM_BMAP;
cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_bmbt_2); cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_bmbt_2);
cur->bc_ops = &xfs_bmbt_ops; cur->bc_ops = &xfs_bmbt_ops;
......
...@@ -578,4 +578,20 @@ void xfs_btree_copy_keys(struct xfs_btree_cur *cur, ...@@ -578,4 +578,20 @@ void xfs_btree_copy_keys(struct xfs_btree_cur *cur,
union xfs_btree_key *dst_key, union xfs_btree_key *dst_key,
const union xfs_btree_key *src_key, int numkeys); const union xfs_btree_key *src_key, int numkeys);
static inline struct xfs_btree_cur *
xfs_btree_alloc_cursor(
struct xfs_mount *mp,
struct xfs_trans *tp,
xfs_btnum_t btnum)
{
struct xfs_btree_cur *cur;
cur = kmem_cache_zalloc(xfs_btree_cur_zone, GFP_NOFS | __GFP_NOFAIL);
cur->bc_tp = tp;
cur->bc_mp = mp;
cur->bc_btnum = btnum;
return cur;
}
#endif /* __XFS_BTREE_H__ */ #endif /* __XFS_BTREE_H__ */
...@@ -432,10 +432,7 @@ xfs_inobt_init_common( ...@@ -432,10 +432,7 @@ xfs_inobt_init_common(
{ {
struct xfs_btree_cur *cur; struct xfs_btree_cur *cur;
cur = kmem_cache_zalloc(xfs_btree_cur_zone, GFP_NOFS | __GFP_NOFAIL); cur = xfs_btree_alloc_cursor(mp, tp, btnum);
cur->bc_tp = tp;
cur->bc_mp = mp;
cur->bc_btnum = btnum;
if (btnum == XFS_BTNUM_INO) { if (btnum == XFS_BTNUM_INO) {
cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_ibt_2); cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_ibt_2);
cur->bc_ops = &xfs_inobt_ops; cur->bc_ops = &xfs_inobt_ops;
......
...@@ -322,10 +322,7 @@ xfs_refcountbt_init_common( ...@@ -322,10 +322,7 @@ xfs_refcountbt_init_common(
ASSERT(pag->pag_agno < mp->m_sb.sb_agcount); ASSERT(pag->pag_agno < mp->m_sb.sb_agcount);
cur = kmem_cache_zalloc(xfs_btree_cur_zone, GFP_NOFS | __GFP_NOFAIL); cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_REFC);
cur->bc_tp = tp;
cur->bc_mp = mp;
cur->bc_btnum = XFS_BTNUM_REFC;
cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_refcbt_2); cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_refcbt_2);
cur->bc_flags |= XFS_BTREE_CRC_BLOCKS; cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;
......
...@@ -451,11 +451,8 @@ xfs_rmapbt_init_common( ...@@ -451,11 +451,8 @@ xfs_rmapbt_init_common(
{ {
struct xfs_btree_cur *cur; struct xfs_btree_cur *cur;
cur = kmem_cache_zalloc(xfs_btree_cur_zone, GFP_NOFS | __GFP_NOFAIL);
cur->bc_tp = tp;
cur->bc_mp = mp;
/* Overlapping btree; 2 keys per pointer. */ /* Overlapping btree; 2 keys per pointer. */
cur->bc_btnum = XFS_BTNUM_RMAP; cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_RMAP);
cur->bc_flags = XFS_BTREE_CRC_BLOCKS | XFS_BTREE_OVERLAPPING; cur->bc_flags = XFS_BTREE_CRC_BLOCKS | XFS_BTREE_OVERLAPPING;
cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_rmap_2); cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_rmap_2);
cur->bc_ops = &xfs_rmapbt_ops; cur->bc_ops = &xfs_rmapbt_ops;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment