Nishad Kamdar | 508578f | 2020-05-12 16:54:17 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 3 | * Copyright (c) 2000,2005 Silicon Graphics, Inc. |
| 4 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
| 6 | #ifndef __XFS_ALLOC_BTREE_H__ |
| 7 | #define __XFS_ALLOC_BTREE_H__ |
| 8 | |
| 9 | /* |
| 10 | * Freespace on-disk structures |
| 11 | */ |
| 12 | |
| 13 | struct xfs_buf; |
| 14 | struct xfs_btree_cur; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | struct xfs_mount; |
Dave Chinner | be9fb17 | 2021-06-02 10:48:24 +1000 | [diff] [blame] | 16 | struct xfs_perag; |
Darrick J. Wong | e6eb33d | 2020-03-11 10:52:49 -0700 | [diff] [blame] | 17 | struct xbtree_afakeroot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | /* |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 20 | * Btree block header size depends on a superblock flag. |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 21 | */ |
Christoph Hellwig | ee1a47a | 2013-04-21 14:53:46 -0500 | [diff] [blame] | 22 | #define XFS_ALLOC_BLOCK_LEN(mp) \ |
Dave Chinner | 38c26bf | 2021-08-18 18:46:37 -0700 | [diff] [blame] | 23 | (xfs_has_crc(((mp))) ? \ |
Christoph Hellwig | ee1a47a | 2013-04-21 14:53:46 -0500 | [diff] [blame] | 24 | XFS_BTREE_SBLOCK_CRC_LEN : XFS_BTREE_SBLOCK_LEN) |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 25 | |
| 26 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | * Record, key, and pointer address macros for btree blocks. |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 28 | * |
| 29 | * (note that some of these may appear unused, but they are used in userspace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | */ |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 31 | #define XFS_ALLOC_REC_ADDR(mp, block, index) \ |
| 32 | ((xfs_alloc_rec_t *) \ |
| 33 | ((char *)(block) + \ |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 34 | XFS_ALLOC_BLOCK_LEN(mp) + \ |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 35 | (((index) - 1) * sizeof(xfs_alloc_rec_t)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 37 | #define XFS_ALLOC_KEY_ADDR(mp, block, index) \ |
| 38 | ((xfs_alloc_key_t *) \ |
| 39 | ((char *)(block) + \ |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 40 | XFS_ALLOC_BLOCK_LEN(mp) + \ |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 41 | ((index) - 1) * sizeof(xfs_alloc_key_t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 43 | #define XFS_ALLOC_PTR_ADDR(mp, block, index, maxrecs) \ |
| 44 | ((xfs_alloc_ptr_t *) \ |
| 45 | ((char *)(block) + \ |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 46 | XFS_ALLOC_BLOCK_LEN(mp) + \ |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 47 | (maxrecs) * sizeof(xfs_alloc_key_t) + \ |
| 48 | ((index) - 1) * sizeof(xfs_alloc_ptr_t))) |
Christoph Hellwig | 561f7d1 | 2008-10-30 16:53:59 +1100 | [diff] [blame] | 49 | |
Dave Chinner | 289d38d | 2021-06-02 10:48:24 +1000 | [diff] [blame] | 50 | extern struct xfs_btree_cur *xfs_allocbt_init_cursor(struct xfs_mount *mp, |
| 51 | struct xfs_trans *tp, struct xfs_buf *bp, |
| 52 | struct xfs_perag *pag, xfs_btnum_t btnum); |
Darrick J. Wong | e6eb33d | 2020-03-11 10:52:49 -0700 | [diff] [blame] | 53 | struct xfs_btree_cur *xfs_allocbt_stage_cursor(struct xfs_mount *mp, |
Dave Chinner | 289d38d | 2021-06-02 10:48:24 +1000 | [diff] [blame] | 54 | struct xbtree_afakeroot *afake, struct xfs_perag *pag, |
Darrick J. Wong | e6eb33d | 2020-03-11 10:52:49 -0700 | [diff] [blame] | 55 | xfs_btnum_t btnum); |
Christoph Hellwig | 60197e8 | 2008-10-30 17:11:19 +1100 | [diff] [blame] | 56 | extern int xfs_allocbt_maxrecs(struct xfs_mount *, int, int); |
Darrick J. Wong | 14861c4 | 2018-05-09 10:02:01 -0700 | [diff] [blame] | 57 | extern xfs_extlen_t xfs_allocbt_calc_size(struct xfs_mount *mp, |
| 58 | unsigned long long len); |
Christoph Hellwig | 561f7d1 | 2008-10-30 16:53:59 +1100 | [diff] [blame] | 59 | |
Darrick J. Wong | e6eb33d | 2020-03-11 10:52:49 -0700 | [diff] [blame] | 60 | void xfs_allocbt_commit_staged_btree(struct xfs_btree_cur *cur, |
| 61 | struct xfs_trans *tp, struct xfs_buf *agbp); |
| 62 | |
Darrick J. Wong | 0ed5f73 | 2021-09-23 10:32:06 -0700 | [diff] [blame] | 63 | unsigned int xfs_allocbt_maxlevels_ondisk(void); |
| 64 | |
Darrick J. Wong | 9fa47bd | 2021-09-23 12:21:37 -0700 | [diff] [blame^] | 65 | int __init xfs_allocbt_init_cur_cache(void); |
| 66 | void xfs_allocbt_destroy_cur_cache(void); |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #endif /* __XFS_ALLOC_BTREE_H__ */ |