xfs: move lru refs to the btree ops structure
authorDarrick J. Wong <djwong@kernel.org>
Thu, 22 Feb 2024 20:35:20 +0000 (12:35 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Thu, 22 Feb 2024 20:35:20 +0000 (12:35 -0800)
Move the btree buffer LRU refcount to the btree ops structure so that we
can eliminate the last bc_btnum switch in the generic btree code.  We're
about to create repair-specific btree types, and we don't want that
stuff cluttering up libxfs.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/libxfs/xfs_alloc_btree.c
fs/xfs/libxfs/xfs_bmap_btree.c
fs/xfs/libxfs/xfs_btree.c
fs/xfs/libxfs/xfs_btree.h
fs/xfs/libxfs/xfs_ialloc_btree.c
fs/xfs/libxfs/xfs_refcount_btree.c
fs/xfs/libxfs/xfs_rmap_btree.c

index a983c4fe83902ec3655083725dc399a90556b60a..045c7954ef1b179fbf9ea80a0c134be0cd57260f 100644 (file)
@@ -458,6 +458,8 @@ const struct xfs_btree_ops xfs_bnobt_ops = {
        .rec_len                = sizeof(xfs_alloc_rec_t),
        .key_len                = sizeof(xfs_alloc_key_t),
 
+       .lru_refs               = XFS_ALLOC_BTREE_REF,
+
        .dup_cursor             = xfs_allocbt_dup_cursor,
        .set_root               = xfs_allocbt_set_root,
        .alloc_block            = xfs_allocbt_alloc_block,
@@ -483,6 +485,8 @@ const struct xfs_btree_ops xfs_cntbt_ops = {
        .rec_len                = sizeof(xfs_alloc_rec_t),
        .key_len                = sizeof(xfs_alloc_key_t),
 
+       .lru_refs               = XFS_ALLOC_BTREE_REF,
+
        .dup_cursor             = xfs_allocbt_dup_cursor,
        .set_root               = xfs_allocbt_set_root,
        .alloc_block            = xfs_allocbt_alloc_block,
index fa116c2d13aeff221fb5d88574f516b49c07e9b8..43dc9fa6b26f9b8e8e0e7e96a8b6b8c244a110a5 100644 (file)
@@ -530,6 +530,8 @@ const struct xfs_btree_ops xfs_bmbt_ops = {
        .rec_len                = sizeof(xfs_bmbt_rec_t),
        .key_len                = sizeof(xfs_bmbt_key_t),
 
+       .lru_refs               = XFS_BMAP_BTREE_REF,
+
        .dup_cursor             = xfs_bmbt_dup_cursor,
        .update_cursor          = xfs_bmbt_update_cursor,
        .alloc_block            = xfs_bmbt_alloc_block,
index e945620b22031619e24d9086cbd4a62285a9884c..e1e96f4f4052f3b8137840be92cc7f5c2cbf0fb1 100644 (file)
@@ -1284,32 +1284,12 @@ xfs_btree_buf_to_ptr(
        }
 }
 
-STATIC void
+static inline void
 xfs_btree_set_refs(
        struct xfs_btree_cur    *cur,
        struct xfs_buf          *bp)
 {
-       switch (cur->bc_btnum) {
-       case XFS_BTNUM_BNO:
-       case XFS_BTNUM_CNT:
-               xfs_buf_set_ref(bp, XFS_ALLOC_BTREE_REF);
-               break;
-       case XFS_BTNUM_INO:
-       case XFS_BTNUM_FINO:
-               xfs_buf_set_ref(bp, XFS_INO_BTREE_REF);
-               break;
-       case XFS_BTNUM_BMAP:
-               xfs_buf_set_ref(bp, XFS_BMAP_BTREE_REF);
-               break;
-       case XFS_BTNUM_RMAP:
-               xfs_buf_set_ref(bp, XFS_RMAP_BTREE_REF);
-               break;
-       case XFS_BTNUM_REFC:
-               xfs_buf_set_ref(bp, XFS_REFC_BTREE_REF);
-               break;
-       default:
-               ASSERT(0);
-       }
+       xfs_buf_set_ref(bp, cur->bc_ops->lru_refs);
 }
 
 int
index 80be40ca89547c363bc8362970dc0a155b956b55..39df108a32ef4d78137183735a5d84a296b7741f 100644 (file)
@@ -120,6 +120,9 @@ struct xfs_btree_ops {
        size_t  key_len;
        size_t  rec_len;
 
+       /* LRU refcount to set on each btree buffer created */
+       unsigned int            lru_refs;
+
        /* cursor operations */
        struct xfs_btree_cur *(*dup_cursor)(struct xfs_btree_cur *);
        void    (*update_cursor)(struct xfs_btree_cur *src,
index 69086fdc3be6ff200ce467fd32e7fadc10acfba2..a2a8c15a6c9e77a6cd9aafcc502d56334b4b646b 100644 (file)
@@ -402,6 +402,8 @@ const struct xfs_btree_ops xfs_inobt_ops = {
        .rec_len                = sizeof(xfs_inobt_rec_t),
        .key_len                = sizeof(xfs_inobt_key_t),
 
+       .lru_refs               = XFS_INO_BTREE_REF,
+
        .dup_cursor             = xfs_inobt_dup_cursor,
        .set_root               = xfs_inobt_set_root,
        .alloc_block            = xfs_inobt_alloc_block,
@@ -424,6 +426,8 @@ const struct xfs_btree_ops xfs_finobt_ops = {
        .rec_len                = sizeof(xfs_inobt_rec_t),
        .key_len                = sizeof(xfs_inobt_key_t),
 
+       .lru_refs               = XFS_INO_BTREE_REF,
+
        .dup_cursor             = xfs_inobt_dup_cursor,
        .set_root               = xfs_finobt_set_root,
        .alloc_block            = xfs_finobt_alloc_block,
index 36e7b26d5e3b21d3b7771cfd5fbe085e7a5cc564..eaed9517e7956eb03854931790210fc347e6cd7a 100644 (file)
@@ -321,6 +321,8 @@ const struct xfs_btree_ops xfs_refcountbt_ops = {
        .rec_len                = sizeof(struct xfs_refcount_rec),
        .key_len                = sizeof(struct xfs_refcount_key),
 
+       .lru_refs               = XFS_REFC_BTREE_REF,
+
        .dup_cursor             = xfs_refcountbt_dup_cursor,
        .set_root               = xfs_refcountbt_set_root,
        .alloc_block            = xfs_refcountbt_alloc_block,
index 086576626f5b994a4a4ac60ba4c62141b5760855..8abe90c25f71f14e60a2a6b1ac27e9e585757333 100644 (file)
@@ -478,6 +478,8 @@ const struct xfs_btree_ops xfs_rmapbt_ops = {
        .rec_len                = sizeof(struct xfs_rmap_rec),
        .key_len                = 2 * sizeof(struct xfs_rmap_key),
 
+       .lru_refs               = XFS_RMAP_BTREE_REF,
+
        .dup_cursor             = xfs_rmapbt_dup_cursor,
        .set_root               = xfs_rmapbt_set_root,
        .alloc_block            = xfs_rmapbt_alloc_block,