162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2016 Oracle. All Rights Reserved. 462306a36Sopenharmony_ci * Author: Darrick J. Wong <darrick.wong@oracle.com> 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci#ifndef __XFS_REFCOUNT_BTREE_H__ 762306a36Sopenharmony_ci#define __XFS_REFCOUNT_BTREE_H__ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci/* 1062306a36Sopenharmony_ci * Reference Count Btree on-disk structures 1162306a36Sopenharmony_ci */ 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_cistruct xfs_buf; 1462306a36Sopenharmony_cistruct xfs_btree_cur; 1562306a36Sopenharmony_cistruct xfs_mount; 1662306a36Sopenharmony_cistruct xfs_perag; 1762306a36Sopenharmony_cistruct xbtree_afakeroot; 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci/* 2062306a36Sopenharmony_ci * Btree block header size 2162306a36Sopenharmony_ci */ 2262306a36Sopenharmony_ci#define XFS_REFCOUNT_BLOCK_LEN XFS_BTREE_SBLOCK_CRC_LEN 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci/* 2562306a36Sopenharmony_ci * Record, key, and pointer address macros for btree blocks. 2662306a36Sopenharmony_ci * 2762306a36Sopenharmony_ci * (note that some of these may appear unused, but they are used in userspace) 2862306a36Sopenharmony_ci */ 2962306a36Sopenharmony_ci#define XFS_REFCOUNT_REC_ADDR(block, index) \ 3062306a36Sopenharmony_ci ((struct xfs_refcount_rec *) \ 3162306a36Sopenharmony_ci ((char *)(block) + \ 3262306a36Sopenharmony_ci XFS_REFCOUNT_BLOCK_LEN + \ 3362306a36Sopenharmony_ci (((index) - 1) * sizeof(struct xfs_refcount_rec)))) 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#define XFS_REFCOUNT_KEY_ADDR(block, index) \ 3662306a36Sopenharmony_ci ((struct xfs_refcount_key *) \ 3762306a36Sopenharmony_ci ((char *)(block) + \ 3862306a36Sopenharmony_ci XFS_REFCOUNT_BLOCK_LEN + \ 3962306a36Sopenharmony_ci ((index) - 1) * sizeof(struct xfs_refcount_key))) 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci#define XFS_REFCOUNT_PTR_ADDR(block, index, maxrecs) \ 4262306a36Sopenharmony_ci ((xfs_refcount_ptr_t *) \ 4362306a36Sopenharmony_ci ((char *)(block) + \ 4462306a36Sopenharmony_ci XFS_REFCOUNT_BLOCK_LEN + \ 4562306a36Sopenharmony_ci (maxrecs) * sizeof(struct xfs_refcount_key) + \ 4662306a36Sopenharmony_ci ((index) - 1) * sizeof(xfs_refcount_ptr_t))) 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ciextern struct xfs_btree_cur *xfs_refcountbt_init_cursor(struct xfs_mount *mp, 4962306a36Sopenharmony_ci struct xfs_trans *tp, struct xfs_buf *agbp, 5062306a36Sopenharmony_ci struct xfs_perag *pag); 5162306a36Sopenharmony_cistruct xfs_btree_cur *xfs_refcountbt_stage_cursor(struct xfs_mount *mp, 5262306a36Sopenharmony_ci struct xbtree_afakeroot *afake, struct xfs_perag *pag); 5362306a36Sopenharmony_ciextern int xfs_refcountbt_maxrecs(int blocklen, bool leaf); 5462306a36Sopenharmony_ciextern void xfs_refcountbt_compute_maxlevels(struct xfs_mount *mp); 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ciextern xfs_extlen_t xfs_refcountbt_calc_size(struct xfs_mount *mp, 5762306a36Sopenharmony_ci unsigned long long len); 5862306a36Sopenharmony_ciextern xfs_extlen_t xfs_refcountbt_max_size(struct xfs_mount *mp, 5962306a36Sopenharmony_ci xfs_agblock_t agblocks); 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ciextern int xfs_refcountbt_calc_reserves(struct xfs_mount *mp, 6262306a36Sopenharmony_ci struct xfs_trans *tp, struct xfs_perag *pag, xfs_extlen_t *ask, 6362306a36Sopenharmony_ci xfs_extlen_t *used); 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_civoid xfs_refcountbt_commit_staged_btree(struct xfs_btree_cur *cur, 6662306a36Sopenharmony_ci struct xfs_trans *tp, struct xfs_buf *agbp); 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ciunsigned int xfs_refcountbt_maxlevels_ondisk(void); 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ciint __init xfs_refcountbt_init_cur_cache(void); 7162306a36Sopenharmony_civoid xfs_refcountbt_destroy_cur_cache(void); 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci#endif /* __XFS_REFCOUNT_BTREE_H__ */ 74