Skip to contentSkip to conversation

xfs: share rmap & refcount btree ops

PATCH Applied Eric Sandeen 4 participants 7 messages Sep 22 – Oct 5 XFS filesystem

lore
Share & tools
lore
#0 lore raw

cover xfs: share rmap & refcount btree ops

The first patch should be what I sent before, just combinediff'd.

The second patch does the same for the refcount btrees as suggested.

I didn't keep prior RVBs since it's not the same patch any more...

This elimiates almost 250 LOC.

#1 lore raw

PATCH 1/2 xfs: share the AG rmap btree with the rt rmap btree

The AG rmap btree and the realtime rmap btree have several identical key and record ops. Share these to eliminate copied code.

---
 fs/xfs/libxfs/xfs_rmap_btree.c   |  16 +--
 fs/xfs/libxfs/xfs_rmap_btree.h   |  26 ++++
 fs/xfs/libxfs/xfs_rtrmap_btree.c | 230 +++----------------------------
 3 files changed, 51 insertions(+), 221 deletions(-)
fs/xfs/libxfs/xfs_rmap_btree.c +8 -8
index 10b3272238eb..5b283a5ddd13 100644
@@ -170,7 +170,7 @@ static inline __be64 ondisk_rec_offset_to_key(const union xfs_btree_rec *rec)
 	return rec->rmap.rm_offset & ~cpu_to_be64(XFS_RMAP_OFF_UNWRITTEN);
 }
 
-STATIC void
+void
 xfs_rmapbt_init_key_from_rec(
 	union xfs_btree_key		*key,
 	const union xfs_btree_rec	*rec)
@@ -187,7 +187,7 @@ xfs_rmapbt_init_key_from_rec(
  * the startblock for all records, and if the record is for a data/attr
  * fork mapping, we add blockcount-1 to the offset too.
  */
-STATIC void
+void
 xfs_rmapbt_init_high_key_from_rec(
 	union xfs_btree_key		*key,
 	const union xfs_btree_rec	*rec)
@@ -209,7 +209,7 @@ xfs_rmapbt_init_high_key_from_rec(
 	key->rmap.rm_offset = cpu_to_be64(off);
 }
 
-STATIC void
+void
 xfs_rmapbt_init_rec_from_cur(
 	struct xfs_btree_cur	*cur,
 	union xfs_btree_rec	*rec)
@@ -243,7 +243,7 @@ static inline uint64_t offset_keymask(uint64_t offset)
 	return offset & ~XFS_RMAP_OFF_UNWRITTEN;
 }
 
-STATIC int
+int
 xfs_rmapbt_cmp_key_with_cur(
 	struct xfs_btree_cur		*cur,
 	const union xfs_btree_key	*key)
@@ -257,7 +257,7 @@ xfs_rmapbt_cmp_key_with_cur(
 		       offset_keymask(xfs_rmap_irec_offset_pack(rec)));
 }
 
-STATIC int
+int
 xfs_rmapbt_cmp_two_keys(
 	struct xfs_btree_cur		*cur,
 	const union xfs_btree_key	*k1,
@@ -390,7 +390,7 @@ const struct xfs_buf_ops xfs_rmapbt_buf_ops = {
 	.verify_struct		= xfs_rmapbt_verify,
 };
 
-STATIC int
+int
 xfs_rmapbt_keys_inorder(
 	struct xfs_btree_cur		*cur,
 	const union xfs_btree_key	*k1,
@@ -420,7 +420,7 @@ xfs_rmapbt_keys_inorder(
 	return 0;
 }
 
-STATIC int
+int
 xfs_rmapbt_recs_inorder(
 	struct xfs_btree_cur		*cur,
 	const union xfs_btree_rec	*r1,
@@ -450,7 +450,7 @@ xfs_rmapbt_recs_inorder(
 	return 0;
 }
 
-STATIC enum xbtree_key_contig
+enum xbtree_key_contig
 xfs_rmapbt_keys_contiguous(
 	struct xfs_btree_cur		*cur,
 	const union xfs_btree_key	*key1,
fs/xfs/libxfs/xfs_rmap_btree.h +26 -0
index 119b1567cd0e..7071dac745e1 100644
@@ -11,6 +11,8 @@ struct xfs_btree_cur;
 struct xfs_mount;
 struct xbtree_afakeroot;
 struct xfbtree;
+union xfs_btree_key;
+union xfs_btree_rec;
 
 /* rmaps only exist on crc enabled filesystems */
 #define XFS_RMAP_BLOCK_LEN	XFS_BTREE_SBLOCK_CRC_LEN
@@ -69,4 +71,28 @@ struct xfs_btree_cur *xfs_rmapbt_mem_cursor(struct xfs_perag *pag,
 int xfs_rmapbt_mem_init(struct xfs_mount *mp, struct xfbtree *xfbtree,
 		struct xfs_buftarg *btp, xfs_agnumber_t agno);
 
+/*
+ * Key and record btree ops.  The rmap on-disk key/record format is identical
+ * for the AG rmap btree and the realtime rmap btree, so these are shared by
+ * both.
+ */
+void xfs_rmapbt_init_key_from_rec(union xfs_btree_key *key,
+		const union xfs_btree_rec *rec);
+void xfs_rmapbt_init_high_key_from_rec(union xfs_btree_key *key,
+		const union xfs_btree_rec *rec);
+void xfs_rmapbt_init_rec_from_cur(struct xfs_btree_cur *cur,
+		union xfs_btree_rec *rec);
+int xfs_rmapbt_cmp_key_with_cur(struct xfs_btree_cur *cur,
+		const union xfs_btree_key *key);
+int xfs_rmapbt_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_rmapbt_keys_inorder(struct xfs_btree_cur *cur,
+		const union xfs_btree_key *k1, const union xfs_btree_key *k2);
+int xfs_rmapbt_recs_inorder(struct xfs_btree_cur *cur,
+		const union xfs_btree_rec *r1, const union xfs_btree_rec *r2);
+enum xbtree_key_contig xfs_rmapbt_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_RMAP_BTREE_H__ */
fs/xfs/libxfs/xfs_rtrmap_btree.c +17 -213

270 lines not on this page · raw message

Signature · 1 line
2.55.0
#3 lore raw

PATCH 2/2 xfs: share the AG refcount btree with the rt refcount btree

In reply to Eric Sandeen

The AG refcount btree and the realtime refcount btree have several identical key and record ops. Share these to eliminate copied code.

---
 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(-)
fs/xfs/libxfs/xfs_refcount_btree.c +8 -8
index 7e5f92c1ac56..2c6148a97994 100644
@@ -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,
fs/xfs/libxfs/xfs_refcount_btree.h +26 -0
index beb93bef6a81..40eedfae6846 100644
@@ -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__ */
fs/xfs/libxfs/xfs_rtrefcount_btree.c +9 -104

145 lines not on this page · raw message

Signature · 1 line
2.55.0
Reviewed-by on the v1 series
#5 lore raw
In reply to Eric Sandeen
Quoted 7 lines · Eric Sandeen

The first patch should be what I sent before, just combinediff'd.

The second patch does the same for the refcount btrees as suggested.

I didn't keep prior RVBs since it's not the same patch any more...

This elimiates almost 250 LOC.

Offhand that looks fine to me!

--D

maintainer Applied
#6 lore raw
In reply to Eric Sandeen
Quoted 9 lines · Eric Sandeen

The first patch should be what I sent before, just combinediff'd.

The second patch does the same for the refcount btrees as suggested.

I didn't keep prior RVBs since it's not the same patch any more...

This elimiates almost 250 LOC.

[...]

Applied to for-next, thanks!

[1/2] xfs: share the AG rmap btree with the rt rmap btree

      commit: 81caec1321282a29b40742c76188df9f31a00f7f
[2/2] xfs: share the AG refcount btree with the rt refcount btree
      commit: 8439f269aae2b37830b2a6af45f9b111a7856b17

Best regards,

Signature · 1 line
Carlos Maiolino <[email protected]>