xref: /linux/fs/xfs/libxfs/xfs_refcount_btree.h (revision 56e98164ffea2a9ee577e5e4f368c6d5182ed8eb)
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;
16*56e98164SDarrick J. Wong struct xbtree_afakeroot;
171946b91cSDarrick J. Wong 
181946b91cSDarrick J. Wong /*
191946b91cSDarrick J. Wong  * Btree block header size
201946b91cSDarrick J. Wong  */
211946b91cSDarrick J. Wong #define XFS_REFCOUNT_BLOCK_LEN	XFS_BTREE_SBLOCK_CRC_LEN
221946b91cSDarrick J. Wong 
231946b91cSDarrick J. Wong /*
241946b91cSDarrick J. Wong  * Record, key, and pointer address macros for btree blocks.
251946b91cSDarrick J. Wong  *
261946b91cSDarrick J. Wong  * (note that some of these may appear unused, but they are used in userspace)
271946b91cSDarrick J. Wong  */
281946b91cSDarrick J. Wong #define XFS_REFCOUNT_REC_ADDR(block, index) \
291946b91cSDarrick J. Wong 	((struct xfs_refcount_rec *) \
301946b91cSDarrick J. Wong 		((char *)(block) + \
311946b91cSDarrick J. Wong 		 XFS_REFCOUNT_BLOCK_LEN + \
321946b91cSDarrick J. Wong 		 (((index) - 1) * sizeof(struct xfs_refcount_rec))))
331946b91cSDarrick J. Wong 
341946b91cSDarrick J. Wong #define XFS_REFCOUNT_KEY_ADDR(block, index) \
351946b91cSDarrick J. Wong 	((struct xfs_refcount_key *) \
361946b91cSDarrick J. Wong 		((char *)(block) + \
371946b91cSDarrick J. Wong 		 XFS_REFCOUNT_BLOCK_LEN + \
381946b91cSDarrick J. Wong 		 ((index) - 1) * sizeof(struct xfs_refcount_key)))
391946b91cSDarrick J. Wong 
401946b91cSDarrick J. Wong #define XFS_REFCOUNT_PTR_ADDR(block, index, maxrecs) \
411946b91cSDarrick J. Wong 	((xfs_refcount_ptr_t *) \
421946b91cSDarrick J. Wong 		((char *)(block) + \
431946b91cSDarrick J. Wong 		 XFS_REFCOUNT_BLOCK_LEN + \
441946b91cSDarrick J. Wong 		 (maxrecs) * sizeof(struct xfs_refcount_key) + \
451946b91cSDarrick J. Wong 		 ((index) - 1) * sizeof(xfs_refcount_ptr_t)))
461946b91cSDarrick J. Wong 
471946b91cSDarrick J. Wong extern struct xfs_btree_cur *xfs_refcountbt_init_cursor(struct xfs_mount *mp,
48ed7ef8e5SBrian Foster 		struct xfs_trans *tp, struct xfs_buf *agbp,
49ed7ef8e5SBrian Foster 		xfs_agnumber_t agno);
50*56e98164SDarrick J. Wong struct xfs_btree_cur *xfs_refcountbt_stage_cursor(struct xfs_mount *mp,
51*56e98164SDarrick J. Wong 		struct xbtree_afakeroot *afake, xfs_agnumber_t agno);
52a1f69417SEric Sandeen extern int xfs_refcountbt_maxrecs(int blocklen, 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,
61ebcbef3aSDarrick J. Wong 		struct xfs_trans *tp, xfs_agnumber_t agno, xfs_extlen_t *ask,
62ebcbef3aSDarrick J. Wong 		xfs_extlen_t *used);
6384d69619SDarrick J. Wong 
64*56e98164SDarrick J. Wong void xfs_refcountbt_commit_staged_btree(struct xfs_btree_cur *cur,
65*56e98164SDarrick J. Wong 		struct xfs_trans *tp, struct xfs_buf *agbp);
66*56e98164SDarrick J. Wong 
671946b91cSDarrick J. Wong #endif	/* __XFS_REFCOUNT_BTREE_H__ */
68