xref: /linux/fs/xfs/libxfs/xfs_refcount_btree.h (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
10b61f8a4SDave Chinner // SPDX-License-Identifier: GPL-2.0+
21946b91cSDarrick J. Wong /*
31946b91cSDarrick J. Wong  * Copyright (C) 2016 Oracle.  All Rights Reserved.
41946b91cSDarrick J. Wong  * Author: Darrick J. Wong <darrick.wong@oracle.com>
51946b91cSDarrick J. Wong  */
61946b91cSDarrick J. Wong #ifndef __XFS_REFCOUNT_BTREE_H__
71946b91cSDarrick J. Wong #define	__XFS_REFCOUNT_BTREE_H__
81946b91cSDarrick J. Wong 
91946b91cSDarrick J. Wong /*
101946b91cSDarrick J. Wong  * Reference Count Btree on-disk structures
111946b91cSDarrick J. Wong  */
121946b91cSDarrick J. Wong 
131946b91cSDarrick J. Wong struct xfs_buf;
141946b91cSDarrick J. Wong struct xfs_btree_cur;
151946b91cSDarrick J. Wong struct xfs_mount;
1630933120SDave Chinner struct xfs_perag;
1756e98164SDarrick J. Wong struct xbtree_afakeroot;
181946b91cSDarrick J. Wong 
191946b91cSDarrick J. Wong /*
201946b91cSDarrick J. Wong  * Btree block header size
211946b91cSDarrick J. Wong  */
221946b91cSDarrick J. Wong #define XFS_REFCOUNT_BLOCK_LEN	XFS_BTREE_SBLOCK_CRC_LEN
231946b91cSDarrick J. Wong 
241946b91cSDarrick J. Wong /*
251946b91cSDarrick J. Wong  * Record, key, and pointer address macros for btree blocks.
261946b91cSDarrick J. Wong  *
271946b91cSDarrick J. Wong  * (note that some of these may appear unused, but they are used in userspace)
281946b91cSDarrick J. Wong  */
291946b91cSDarrick J. Wong #define XFS_REFCOUNT_REC_ADDR(block, index) \
301946b91cSDarrick J. Wong 	((struct xfs_refcount_rec *) \
311946b91cSDarrick J. Wong 		((char *)(block) + \
321946b91cSDarrick J. Wong 		 XFS_REFCOUNT_BLOCK_LEN + \
331946b91cSDarrick J. Wong 		 (((index) - 1) * sizeof(struct xfs_refcount_rec))))
341946b91cSDarrick J. Wong 
351946b91cSDarrick J. Wong #define XFS_REFCOUNT_KEY_ADDR(block, index) \
361946b91cSDarrick J. Wong 	((struct xfs_refcount_key *) \
371946b91cSDarrick J. Wong 		((char *)(block) + \
381946b91cSDarrick J. Wong 		 XFS_REFCOUNT_BLOCK_LEN + \
391946b91cSDarrick J. Wong 		 ((index) - 1) * sizeof(struct xfs_refcount_key)))
401946b91cSDarrick J. Wong 
411946b91cSDarrick J. Wong #define XFS_REFCOUNT_PTR_ADDR(block, index, maxrecs) \
421946b91cSDarrick J. Wong 	((xfs_refcount_ptr_t *) \
431946b91cSDarrick J. Wong 		((char *)(block) + \
441946b91cSDarrick J. Wong 		 XFS_REFCOUNT_BLOCK_LEN + \
451946b91cSDarrick J. Wong 		 (maxrecs) * sizeof(struct xfs_refcount_key) + \
461946b91cSDarrick J. Wong 		 ((index) - 1) * sizeof(xfs_refcount_ptr_t)))
471946b91cSDarrick J. Wong 
481946b91cSDarrick J. Wong extern struct xfs_btree_cur *xfs_refcountbt_init_cursor(struct xfs_mount *mp,
49ed7ef8e5SBrian Foster 		struct xfs_trans *tp, struct xfs_buf *agbp,
50a81a0621SDave Chinner 		struct xfs_perag *pag);
51*411a7125SDarrick J. Wong unsigned int xfs_refcountbt_maxrecs(struct xfs_mount *mp, unsigned int blocklen,
52*411a7125SDarrick J. Wong 		bool leaf);
531946b91cSDarrick J. Wong extern void xfs_refcountbt_compute_maxlevels(struct xfs_mount *mp);
541946b91cSDarrick J. Wong 
5584d69619SDarrick J. Wong extern xfs_extlen_t xfs_refcountbt_calc_size(struct xfs_mount *mp,
5684d69619SDarrick J. Wong 		unsigned long long len);
5720e73b00SDarrick J. Wong extern xfs_extlen_t xfs_refcountbt_max_size(struct xfs_mount *mp,
5820e73b00SDarrick J. Wong 		xfs_agblock_t agblocks);
5984d69619SDarrick J. Wong 
6084d69619SDarrick J. Wong extern int xfs_refcountbt_calc_reserves(struct xfs_mount *mp,
6130933120SDave Chinner 		struct xfs_trans *tp, struct xfs_perag *pag, xfs_extlen_t *ask,
62ebcbef3aSDarrick J. Wong 		xfs_extlen_t *used);
6384d69619SDarrick J. Wong 
6456e98164SDarrick J. Wong void xfs_refcountbt_commit_staged_btree(struct xfs_btree_cur *cur,
6556e98164SDarrick J. Wong 		struct xfs_trans *tp, struct xfs_buf *agbp);
6656e98164SDarrick J. Wong 
670ed5f735SDarrick J. Wong unsigned int xfs_refcountbt_maxlevels_ondisk(void);
680ed5f735SDarrick J. Wong 
699fa47bdcSDarrick J. Wong int __init xfs_refcountbt_init_cur_cache(void);
709fa47bdcSDarrick J. Wong void xfs_refcountbt_destroy_cur_cache(void);
719fa47bdcSDarrick J. Wong 
721946b91cSDarrick J. Wong #endif	/* __XFS_REFCOUNT_BTREE_H__ */
73