xref: /linux/fs/xfs/scrub/rcbag_btree.h (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2022-2024 Oracle.  All Rights Reserved.
4  * Author: Darrick J. Wong <djwong@kernel.org>
5  */
6 #ifndef __XFS_SCRUB_RCBAG_BTREE_H__
7 #define __XFS_SCRUB_RCBAG_BTREE_H__
8 
9 #ifdef CONFIG_XFS_BTREE_IN_MEM
10 
11 struct xfs_buf;
12 struct xfs_btree_cur;
13 struct xfs_mount;
14 
15 #define RCBAG_MAGIC	0x74826671	/* 'JRBG' */
16 
17 struct rcbag_key {
18 	uint32_t	rbg_startblock;
19 	uint32_t	rbg_blockcount;
20 };
21 
22 struct rcbag_rec {
23 	uint32_t	rbg_startblock;
24 	uint32_t	rbg_blockcount;
25 	uint64_t	rbg_refcount;
26 };
27 
28 typedef __be64 rcbag_ptr_t;
29 
30 /* reflinks only exist on crc enabled filesystems */
31 #define RCBAG_BLOCK_LEN	XFS_BTREE_LBLOCK_CRC_LEN
32 
33 /*
34  * Record, key, and pointer address macros for btree blocks.
35  *
36  * (note that some of these may appear unused, but they are used in userspace)
37  */
38 #define RCBAG_REC_ADDR(block, index) \
39 	((struct rcbag_rec *) \
40 		((char *)(block) + RCBAG_BLOCK_LEN + \
41 		 (((index) - 1) * sizeof(struct rcbag_rec))))
42 
43 #define RCBAG_KEY_ADDR(block, index) \
44 	((struct rcbag_key *) \
45 		((char *)(block) + RCBAG_BLOCK_LEN + \
46 		 ((index) - 1) * sizeof(struct rcbag_key)))
47 
48 #define RCBAG_PTR_ADDR(block, index, maxrecs) \
49 	((rcbag_ptr_t *) \
50 		((char *)(block) + RCBAG_BLOCK_LEN + \
51 		 (maxrecs) * sizeof(struct rcbag_key) + \
52 		 ((index) - 1) * sizeof(rcbag_ptr_t)))
53 
54 unsigned int rcbagbt_maxrecs(struct xfs_mount *mp, unsigned int blocklen,
55 		bool leaf);
56 
57 unsigned long long rcbagbt_calc_size(unsigned long long nr_records);
58 
59 unsigned int rcbagbt_maxlevels_possible(void);
60 
61 int __init rcbagbt_init_cur_cache(void);
62 void rcbagbt_destroy_cur_cache(void);
63 
64 struct xfs_btree_cur *rcbagbt_mem_cursor(struct xfs_mount *mp,
65 		struct xfs_trans *tp, struct xfbtree *xfbtree);
66 int rcbagbt_mem_init(struct xfs_mount *mp, struct xfbtree *xfbtree,
67 		struct xfs_buftarg *btp);
68 
69 int rcbagbt_lookup_eq(struct xfs_btree_cur *cur,
70 		const struct xfs_rmap_irec *rmap, int *success);
71 int rcbagbt_get_rec(struct xfs_btree_cur *cur, struct rcbag_rec *rec, int *has);
72 int rcbagbt_update(struct xfs_btree_cur *cur, const struct rcbag_rec *rec);
73 int rcbagbt_insert(struct xfs_btree_cur *cur, const struct rcbag_rec *rec,
74 		int *success);
75 
76 #else
77 # define rcbagbt_init_cur_cache()		0
78 # define rcbagbt_destroy_cur_cache()		((void)0)
79 #endif /* CONFIG_XFS_BTREE_IN_MEM */
80 
81 #endif /* __XFS_SCRUB_RCBAG_BTREE_H__ */
82