]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: refactor btree cursor allocation function
authorDarrick J. Wong <djwong@kernel.org>
Thu, 28 Apr 2022 19:39:03 +0000 (15:39 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Thu, 28 Apr 2022 19:39:03 +0000 (15:39 -0400)
Source kernel commit: 56370ea6e5fe3e3d6e1ca2da58f95fb0d5e1779f

Refactor btree allocation to a common helper.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Chandan Babu R <chandan.babu@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/xfs_alloc_btree.c
libxfs/xfs_bmap_btree.c
libxfs/xfs_btree.h
libxfs/xfs_ialloc_btree.c
libxfs/xfs_refcount_btree.c
libxfs/xfs_rmap_btree.c

index 46d0f22918342324ca3085873a71552ce27f6230..7d7618c5435a533433a8f4306f3712e84118b4e9 100644 (file)
@@ -475,11 +475,7 @@ xfs_allocbt_init_common(
 
        ASSERT(btnum == XFS_BTNUM_BNO || btnum == XFS_BTNUM_CNT);
 
-       cur = kmem_cache_zalloc(xfs_btree_cur_zone, GFP_NOFS | __GFP_NOFAIL);
-
-       cur->bc_tp = tp;
-       cur->bc_mp = mp;
-       cur->bc_btnum = btnum;
+       cur = xfs_btree_alloc_cursor(mp, tp, btnum);
        cur->bc_ag.abt.active = false;
 
        if (btnum == XFS_BTNUM_CNT) {
index 565e8af7f14d4a4f0d066698c545b64ad27a1552..c4b34cdd06f26fa3fe839eb21f7e0483177d9882 100644 (file)
@@ -550,12 +550,8 @@ xfs_bmbt_init_cursor(
        struct xfs_btree_cur    *cur;
        ASSERT(whichfork != XFS_COW_FORK);
 
-       cur = kmem_cache_zalloc(xfs_btree_cur_zone, GFP_NOFS | __GFP_NOFAIL);
-
-       cur->bc_tp = tp;
-       cur->bc_mp = mp;
+       cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_BMAP);
        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_ops = &xfs_bmbt_ops;
index eaffd8223ce679172e747b220bc3b2ee0e352206..8e78ede87b1607ed552d9d22ac76ae51847a401a 100644 (file)
@@ -578,4 +578,20 @@ void xfs_btree_copy_keys(struct xfs_btree_cur *cur,
                union xfs_btree_key *dst_key,
                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__ */
index f1e03cfd2cb34ada659a23f67ff00309c50d27a8..87a54c07f86a5702bce221d3d7d12898eddbba9f 100644 (file)
@@ -431,10 +431,7 @@ xfs_inobt_init_common(
 {
        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;
+       cur = xfs_btree_alloc_cursor(mp, tp, btnum);
        if (btnum == XFS_BTNUM_INO) {
                cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_ibt_2);
                cur->bc_ops = &xfs_inobt_ops;
index f7f99cbd35dd02e364de8be5e29cb331c4848848..55e68613f73129e03f76360e4052f4dfd5163357 100644 (file)
@@ -321,10 +321,7 @@ xfs_refcountbt_init_common(
 
        ASSERT(pag->pag_agno < mp->m_sb.sb_agcount);
 
-       cur = kmem_cache_zalloc(xfs_btree_cur_zone, GFP_NOFS | __GFP_NOFAIL);
-       cur->bc_tp = tp;
-       cur->bc_mp = mp;
-       cur->bc_btnum = XFS_BTNUM_REFC;
+       cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_REFC);
        cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_refcbt_2);
 
        cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;
index bba29eeab2e6b1d1aa06f962effc1947aedd9e18..f6339a312d1cb75776c3608b338d804875d7f989 100644 (file)
@@ -449,11 +449,8 @@ xfs_rmapbt_init_common(
 {
        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. */
-       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_statoff = XFS_STATS_CALC_INDEX(xs_rmap_2);
        cur->bc_ops = &xfs_rmapbt_ops;