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, 50*a81a0621SDave Chinner struct xfs_perag *pag); 5156e98164SDarrick J. Wong struct xfs_btree_cur *xfs_refcountbt_stage_cursor(struct xfs_mount *mp, 52*a81a0621SDave Chinner struct xbtree_afakeroot *afake, struct xfs_perag *pag); 53a1f69417SEric Sandeen extern int xfs_refcountbt_maxrecs(int blocklen, bool leaf); 541946b91cSDarrick J. Wong extern void xfs_refcountbt_compute_maxlevels(struct xfs_mount *mp); 551946b91cSDarrick J. Wong 5684d69619SDarrick J. Wong extern xfs_extlen_t xfs_refcountbt_calc_size(struct xfs_mount *mp, 5784d69619SDarrick J. Wong unsigned long long len); 5820e73b00SDarrick J. Wong extern xfs_extlen_t xfs_refcountbt_max_size(struct xfs_mount *mp, 5920e73b00SDarrick J. Wong xfs_agblock_t agblocks); 6084d69619SDarrick J. Wong 6184d69619SDarrick J. Wong extern int xfs_refcountbt_calc_reserves(struct xfs_mount *mp, 6230933120SDave Chinner struct xfs_trans *tp, struct xfs_perag *pag, xfs_extlen_t *ask, 63ebcbef3aSDarrick J. Wong xfs_extlen_t *used); 6484d69619SDarrick J. Wong 6556e98164SDarrick J. Wong void xfs_refcountbt_commit_staged_btree(struct xfs_btree_cur *cur, 6656e98164SDarrick J. Wong struct xfs_trans *tp, struct xfs_buf *agbp); 6756e98164SDarrick J. Wong 681946b91cSDarrick J. Wong #endif /* __XFS_REFCOUNT_BTREE_H__ */ 69