162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2014 Red Hat, Inc. 462306a36Sopenharmony_ci * All Rights Reserved. 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci#ifndef __XFS_RMAP_BTREE_H__ 762306a36Sopenharmony_ci#define __XFS_RMAP_BTREE_H__ 862306a36Sopenharmony_ci 962306a36Sopenharmony_cistruct xfs_buf; 1062306a36Sopenharmony_cistruct xfs_btree_cur; 1162306a36Sopenharmony_cistruct xfs_mount; 1262306a36Sopenharmony_cistruct xbtree_afakeroot; 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci/* rmaps only exist on crc enabled filesystems */ 1562306a36Sopenharmony_ci#define XFS_RMAP_BLOCK_LEN XFS_BTREE_SBLOCK_CRC_LEN 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci/* 1862306a36Sopenharmony_ci * Record, key, and pointer address macros for btree blocks. 1962306a36Sopenharmony_ci * 2062306a36Sopenharmony_ci * (note that some of these may appear unused, but they are used in userspace) 2162306a36Sopenharmony_ci */ 2262306a36Sopenharmony_ci#define XFS_RMAP_REC_ADDR(block, index) \ 2362306a36Sopenharmony_ci ((struct xfs_rmap_rec *) \ 2462306a36Sopenharmony_ci ((char *)(block) + XFS_RMAP_BLOCK_LEN + \ 2562306a36Sopenharmony_ci (((index) - 1) * sizeof(struct xfs_rmap_rec)))) 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci#define XFS_RMAP_KEY_ADDR(block, index) \ 2862306a36Sopenharmony_ci ((struct xfs_rmap_key *) \ 2962306a36Sopenharmony_ci ((char *)(block) + XFS_RMAP_BLOCK_LEN + \ 3062306a36Sopenharmony_ci ((index) - 1) * 2 * sizeof(struct xfs_rmap_key))) 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci#define XFS_RMAP_HIGH_KEY_ADDR(block, index) \ 3362306a36Sopenharmony_ci ((struct xfs_rmap_key *) \ 3462306a36Sopenharmony_ci ((char *)(block) + XFS_RMAP_BLOCK_LEN + \ 3562306a36Sopenharmony_ci sizeof(struct xfs_rmap_key) + \ 3662306a36Sopenharmony_ci ((index) - 1) * 2 * sizeof(struct xfs_rmap_key))) 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci#define XFS_RMAP_PTR_ADDR(block, index, maxrecs) \ 3962306a36Sopenharmony_ci ((xfs_rmap_ptr_t *) \ 4062306a36Sopenharmony_ci ((char *)(block) + XFS_RMAP_BLOCK_LEN + \ 4162306a36Sopenharmony_ci (maxrecs) * 2 * sizeof(struct xfs_rmap_key) + \ 4262306a36Sopenharmony_ci ((index) - 1) * sizeof(xfs_rmap_ptr_t))) 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_cistruct xfs_btree_cur *xfs_rmapbt_init_cursor(struct xfs_mount *mp, 4562306a36Sopenharmony_ci struct xfs_trans *tp, struct xfs_buf *bp, 4662306a36Sopenharmony_ci struct xfs_perag *pag); 4762306a36Sopenharmony_cistruct xfs_btree_cur *xfs_rmapbt_stage_cursor(struct xfs_mount *mp, 4862306a36Sopenharmony_ci struct xbtree_afakeroot *afake, struct xfs_perag *pag); 4962306a36Sopenharmony_civoid xfs_rmapbt_commit_staged_btree(struct xfs_btree_cur *cur, 5062306a36Sopenharmony_ci struct xfs_trans *tp, struct xfs_buf *agbp); 5162306a36Sopenharmony_ciint xfs_rmapbt_maxrecs(int blocklen, int leaf); 5262306a36Sopenharmony_ciextern void xfs_rmapbt_compute_maxlevels(struct xfs_mount *mp); 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ciextern xfs_extlen_t xfs_rmapbt_calc_size(struct xfs_mount *mp, 5562306a36Sopenharmony_ci unsigned long long len); 5662306a36Sopenharmony_ciextern xfs_extlen_t xfs_rmapbt_max_size(struct xfs_mount *mp, 5762306a36Sopenharmony_ci xfs_agblock_t agblocks); 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ciextern int xfs_rmapbt_calc_reserves(struct xfs_mount *mp, struct xfs_trans *tp, 6062306a36Sopenharmony_ci struct xfs_perag *pag, xfs_extlen_t *ask, xfs_extlen_t *used); 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ciunsigned int xfs_rmapbt_maxlevels_ondisk(void); 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ciint __init xfs_rmapbt_init_cur_cache(void); 6562306a36Sopenharmony_civoid xfs_rmapbt_destroy_cur_cache(void); 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci#endif /* __XFS_RMAP_BTREE_H__ */ 68