From: Eric Sandeen <sandeen@redhat.com>
To: linux-xfs@vger.kernel.org
Cc: cem@kernel.org, hch@infradead.org, djwong@kernel.org,
Eric Sandeen <sandeen@redhat.com>
Subject: [PATCH 2/2] xfs: share the AG refcount btree with the rt refcount btree
Date: Tue, 22 Sep 2026 18:17:09 -0500 [thread overview]
Message-ID: <20260922231845.3266784-3-sandeen@redhat.com> (raw)
In-Reply-To: <20260922231845.3266784-1-sandeen@redhat.com>
The AG refcount btree and the realtime refcount btree have several
identical key and record ops. Share these to eliminate copied code.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
fs/xfs/libxfs/xfs_refcount_btree.c | 16 ++--
fs/xfs/libxfs/xfs_refcount_btree.h | 26 ++++++
fs/xfs/libxfs/xfs_rtrefcount_btree.c | 113 +++------------------------
3 files changed, 43 insertions(+), 112 deletions(-)
diff --git a/fs/xfs/libxfs/xfs_refcount_btree.c b/fs/xfs/libxfs/xfs_refcount_btree.c
index 7e5f92c1ac56..2c6148a97994 100644
--- a/fs/xfs/libxfs/xfs_refcount_btree.c
+++ b/fs/xfs/libxfs/xfs_refcount_btree.c
@@ -127,7 +127,7 @@ xfs_refcountbt_get_maxrecs(
return cur->bc_mp->m_refc_mxr[level != 0];
}
-STATIC void
+void
xfs_refcountbt_init_key_from_rec(
union xfs_btree_key *key,
const union xfs_btree_rec *rec)
@@ -135,7 +135,7 @@ xfs_refcountbt_init_key_from_rec(
key->refc.rc_startblock = rec->refc.rc_startblock;
}
-STATIC void
+void
xfs_refcountbt_init_high_key_from_rec(
union xfs_btree_key *key,
const union xfs_btree_rec *rec)
@@ -147,7 +147,7 @@ xfs_refcountbt_init_high_key_from_rec(
key->refc.rc_startblock = cpu_to_be32(x);
}
-STATIC void
+void
xfs_refcountbt_init_rec_from_cur(
struct xfs_btree_cur *cur,
union xfs_btree_rec *rec)
@@ -174,7 +174,7 @@ xfs_refcountbt_init_ptr_from_cur(
ptr->s = agf->agf_refcount_root;
}
-STATIC int
+int
xfs_refcountbt_cmp_key_with_cur(
struct xfs_btree_cur *cur,
const union xfs_btree_key *key)
@@ -188,7 +188,7 @@ xfs_refcountbt_cmp_key_with_cur(
return cmp_int(be32_to_cpu(kp->rc_startblock), start);
}
-STATIC int
+int
xfs_refcountbt_cmp_two_keys(
struct xfs_btree_cur *cur,
const union xfs_btree_key *k1,
@@ -283,7 +283,7 @@ const struct xfs_buf_ops xfs_refcountbt_buf_ops = {
.verify_struct = xfs_refcountbt_verify,
};
-STATIC int
+int
xfs_refcountbt_keys_inorder(
struct xfs_btree_cur *cur,
const union xfs_btree_key *k1,
@@ -293,7 +293,7 @@ xfs_refcountbt_keys_inorder(
be32_to_cpu(k2->refc.rc_startblock);
}
-STATIC int
+int
xfs_refcountbt_recs_inorder(
struct xfs_btree_cur *cur,
const union xfs_btree_rec *r1,
@@ -304,7 +304,7 @@ xfs_refcountbt_recs_inorder(
be32_to_cpu(r2->refc.rc_startblock);
}
-STATIC enum xbtree_key_contig
+enum xbtree_key_contig
xfs_refcountbt_keys_contiguous(
struct xfs_btree_cur *cur,
const union xfs_btree_key *key1,
diff --git a/fs/xfs/libxfs/xfs_refcount_btree.h b/fs/xfs/libxfs/xfs_refcount_btree.h
index beb93bef6a81..40eedfae6846 100644
--- a/fs/xfs/libxfs/xfs_refcount_btree.h
+++ b/fs/xfs/libxfs/xfs_refcount_btree.h
@@ -15,6 +15,8 @@ struct xfs_btree_cur;
struct xfs_mount;
struct xfs_perag;
struct xbtree_afakeroot;
+union xfs_btree_key;
+union xfs_btree_rec;
/*
* Btree block header size
@@ -69,4 +71,28 @@ unsigned int xfs_refcountbt_maxlevels_ondisk(void);
int __init xfs_refcountbt_init_cur_cache(void);
void xfs_refcountbt_destroy_cur_cache(void);
+/*
+ * Key and record btree ops. The refcount on-disk key/record format is
+ * identical for the AG refcount btree and the realtime refcount btree, so
+ * these are shared by both.
+ */
+void xfs_refcountbt_init_key_from_rec(union xfs_btree_key *key,
+ const union xfs_btree_rec *rec);
+void xfs_refcountbt_init_high_key_from_rec(union xfs_btree_key *key,
+ const union xfs_btree_rec *rec);
+void xfs_refcountbt_init_rec_from_cur(struct xfs_btree_cur *cur,
+ union xfs_btree_rec *rec);
+int xfs_refcountbt_cmp_key_with_cur(struct xfs_btree_cur *cur,
+ const union xfs_btree_key *key);
+int xfs_refcountbt_cmp_two_keys(struct xfs_btree_cur *cur,
+ const union xfs_btree_key *k1, const union xfs_btree_key *k2,
+ const union xfs_btree_key *mask);
+int xfs_refcountbt_keys_inorder(struct xfs_btree_cur *cur,
+ const union xfs_btree_key *k1, const union xfs_btree_key *k2);
+int xfs_refcountbt_recs_inorder(struct xfs_btree_cur *cur,
+ const union xfs_btree_rec *r1, const union xfs_btree_rec *r2);
+enum xbtree_key_contig xfs_refcountbt_keys_contiguous(struct xfs_btree_cur *cur,
+ const union xfs_btree_key *key1, const union xfs_btree_key *key2,
+ const union xfs_btree_key *mask);
+
#endif /* __XFS_REFCOUNT_BTREE_H__ */
diff --git a/fs/xfs/libxfs/xfs_rtrefcount_btree.c b/fs/xfs/libxfs/xfs_rtrefcount_btree.c
index e91ff14577f9..697f5e622685 100644
--- a/fs/xfs/libxfs/xfs_rtrefcount_btree.c
+++ b/fs/xfs/libxfs/xfs_rtrefcount_btree.c
@@ -20,6 +20,7 @@
#include "xfs_btree_staging.h"
#include "xfs_rtrefcount_btree.h"
#include "xfs_refcount.h"
+#include "xfs_refcount_btree.h"
#include "xfs_trace.h"
#include "xfs_cksum.h"
#include "xfs_error.h"
@@ -113,41 +114,6 @@ xfs_rtrefcountbt_get_dmaxrecs(
return xfs_rtrefcountbt_droot_maxrecs(cur->bc_ino.forksize, level == 0);
}
-STATIC void
-xfs_rtrefcountbt_init_key_from_rec(
- union xfs_btree_key *key,
- const union xfs_btree_rec *rec)
-{
- key->refc.rc_startblock = rec->refc.rc_startblock;
-}
-
-STATIC void
-xfs_rtrefcountbt_init_high_key_from_rec(
- union xfs_btree_key *key,
- const union xfs_btree_rec *rec)
-{
- __u32 x;
-
- x = be32_to_cpu(rec->refc.rc_startblock);
- x += be32_to_cpu(rec->refc.rc_blockcount) - 1;
- key->refc.rc_startblock = cpu_to_be32(x);
-}
-
-STATIC void
-xfs_rtrefcountbt_init_rec_from_cur(
- struct xfs_btree_cur *cur,
- union xfs_btree_rec *rec)
-{
- const struct xfs_refcount_irec *irec = &cur->bc_rec.rc;
- uint32_t start;
-
- start = xfs_refcount_encode_startblock(irec->rc_startblock,
- irec->rc_domain);
- rec->refc.rc_startblock = cpu_to_be32(start);
- rec->refc.rc_blockcount = cpu_to_be32(cur->bc_rec.rc.rc_blockcount);
- rec->refc.rc_refcount = cpu_to_be32(cur->bc_rec.rc.rc_refcount);
-}
-
STATIC void
xfs_rtrefcountbt_init_ptr_from_cur(
struct xfs_btree_cur *cur,
@@ -156,33 +122,6 @@ xfs_rtrefcountbt_init_ptr_from_cur(
ptr->l = 0;
}
-STATIC int
-xfs_rtrefcountbt_cmp_key_with_cur(
- struct xfs_btree_cur *cur,
- const union xfs_btree_key *key)
-{
- const struct xfs_refcount_key *kp = &key->refc;
- const struct xfs_refcount_irec *irec = &cur->bc_rec.rc;
- uint32_t start;
-
- start = xfs_refcount_encode_startblock(irec->rc_startblock,
- irec->rc_domain);
- return cmp_int(be32_to_cpu(kp->rc_startblock), start);
-}
-
-STATIC int
-xfs_rtrefcountbt_cmp_two_keys(
- struct xfs_btree_cur *cur,
- const union xfs_btree_key *k1,
- const union xfs_btree_key *k2,
- const union xfs_btree_key *mask)
-{
- ASSERT(!mask || mask->refc.rc_startblock);
-
- return cmp_int(be32_to_cpu(k1->refc.rc_startblock),
- be32_to_cpu(k2->refc.rc_startblock));
-}
-
static xfs_failaddr_t
xfs_rtrefcountbt_verify(
struct xfs_buf *bp)
@@ -249,40 +188,6 @@ const struct xfs_buf_ops xfs_rtrefcountbt_buf_ops = {
.verify_struct = xfs_rtrefcountbt_verify,
};
-STATIC int
-xfs_rtrefcountbt_keys_inorder(
- struct xfs_btree_cur *cur,
- const union xfs_btree_key *k1,
- const union xfs_btree_key *k2)
-{
- return be32_to_cpu(k1->refc.rc_startblock) <
- be32_to_cpu(k2->refc.rc_startblock);
-}
-
-STATIC int
-xfs_rtrefcountbt_recs_inorder(
- struct xfs_btree_cur *cur,
- const union xfs_btree_rec *r1,
- const union xfs_btree_rec *r2)
-{
- return be32_to_cpu(r1->refc.rc_startblock) +
- be32_to_cpu(r1->refc.rc_blockcount) <=
- be32_to_cpu(r2->refc.rc_startblock);
-}
-
-STATIC enum xbtree_key_contig
-xfs_rtrefcountbt_keys_contiguous(
- struct xfs_btree_cur *cur,
- const union xfs_btree_key *key1,
- const union xfs_btree_key *key2,
- const union xfs_btree_key *mask)
-{
- ASSERT(!mask || mask->refc.rc_startblock);
-
- return xbtree_key_contig(be32_to_cpu(key1->refc.rc_startblock),
- be32_to_cpu(key2->refc.rc_startblock));
-}
-
static inline void
xfs_rtrefcountbt_move_ptrs(
struct xfs_mount *mp,
@@ -383,16 +288,16 @@ const struct xfs_btree_ops xfs_rtrefcountbt_ops = {
.get_minrecs = xfs_rtrefcountbt_get_minrecs,
.get_maxrecs = xfs_rtrefcountbt_get_maxrecs,
.get_dmaxrecs = xfs_rtrefcountbt_get_dmaxrecs,
- .init_key_from_rec = xfs_rtrefcountbt_init_key_from_rec,
- .init_high_key_from_rec = xfs_rtrefcountbt_init_high_key_from_rec,
- .init_rec_from_cur = xfs_rtrefcountbt_init_rec_from_cur,
+ .init_key_from_rec = xfs_refcountbt_init_key_from_rec,
+ .init_high_key_from_rec = xfs_refcountbt_init_high_key_from_rec,
+ .init_rec_from_cur = xfs_refcountbt_init_rec_from_cur,
.init_ptr_from_cur = xfs_rtrefcountbt_init_ptr_from_cur,
- .cmp_key_with_cur = xfs_rtrefcountbt_cmp_key_with_cur,
+ .cmp_key_with_cur = xfs_refcountbt_cmp_key_with_cur,
.buf_ops = &xfs_rtrefcountbt_buf_ops,
- .cmp_two_keys = xfs_rtrefcountbt_cmp_two_keys,
- .keys_inorder = xfs_rtrefcountbt_keys_inorder,
- .recs_inorder = xfs_rtrefcountbt_recs_inorder,
- .keys_contiguous = xfs_rtrefcountbt_keys_contiguous,
+ .cmp_two_keys = xfs_refcountbt_cmp_two_keys,
+ .keys_inorder = xfs_refcountbt_keys_inorder,
+ .recs_inorder = xfs_refcountbt_recs_inorder,
+ .keys_contiguous = xfs_refcountbt_keys_contiguous,
.broot_realloc = xfs_rtrefcountbt_broot_realloc,
};
--
2.55.0
next prev parent reply other threads:[~2026-09-22 23:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 23:17 [PATCH 0/2] xfs: share rmap & refcount btree ops Eric Sandeen
2026-09-22 23:17 ` [PATCH 1/2] xfs: share the AG rmap btree with the rt rmap btree Eric Sandeen
2026-09-23 4:39 ` Christoph Hellwig
2026-09-22 23:17 ` Eric Sandeen [this message]
2026-09-23 4:39 ` [PATCH 2/2] xfs: share the AG refcount btree with the rt refcount btree Christoph Hellwig
2026-09-22 23:26 ` [PATCH 0/2] xfs: share rmap & refcount btree ops Darrick J. Wong
2026-10-05 18:06 ` Carlos Maiolino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260922231845.3266784-3-sandeen@redhat.com \
--to=sandeen@redhat.com \
--cc=cem@kernel.org \
--cc=djwong@kernel.org \
--cc=hch@infradead.org \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox