Dave Chinner | 0b61f8a | 2018-06-05 19:42:14 -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_IALLOC_BTREE_H__ |
| 7 | #define __XFS_IALLOC_BTREE_H__ |
| 8 | |
| 9 | /* |
| 10 | * Inode map 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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | /* |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 19 | * Btree block header size depends on a superblock flag. |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 20 | */ |
Christoph Hellwig | ee1a47a | 2013-04-21 14:53:46 -0500 | [diff] [blame] | 21 | #define XFS_INOBT_BLOCK_LEN(mp) \ |
Dave Chinner | 38c26bf | 2021-08-18 18:46:37 -0700 | [diff] [blame] | 22 | (xfs_has_crc(((mp))) ? \ |
Christoph Hellwig | ee1a47a | 2013-04-21 14:53:46 -0500 | [diff] [blame] | 23 | XFS_BTREE_SBLOCK_CRC_LEN : XFS_BTREE_SBLOCK_LEN) |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 24 | |
| 25 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | * Record, key, and pointer address macros for btree blocks. |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 27 | * |
| 28 | * (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] | 29 | */ |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 30 | #define XFS_INOBT_REC_ADDR(mp, block, index) \ |
| 31 | ((xfs_inobt_rec_t *) \ |
| 32 | ((char *)(block) + \ |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 33 | XFS_INOBT_BLOCK_LEN(mp) + \ |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 34 | (((index) - 1) * sizeof(xfs_inobt_rec_t)))) |
Eric Sandeen | 2c36dde | 2007-02-10 18:37:33 +1100 | [diff] [blame] | 35 | |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 36 | #define XFS_INOBT_KEY_ADDR(mp, block, index) \ |
| 37 | ((xfs_inobt_key_t *) \ |
| 38 | ((char *)(block) + \ |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 39 | XFS_INOBT_BLOCK_LEN(mp) + \ |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 40 | ((index) - 1) * sizeof(xfs_inobt_key_t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 42 | #define XFS_INOBT_PTR_ADDR(mp, block, index, maxrecs) \ |
| 43 | ((xfs_inobt_ptr_t *) \ |
| 44 | ((char *)(block) + \ |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 45 | XFS_INOBT_BLOCK_LEN(mp) + \ |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 46 | (maxrecs) * sizeof(xfs_inobt_key_t) + \ |
| 47 | ((index) - 1) * sizeof(xfs_inobt_ptr_t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Dave Chinner | be9fb17 | 2021-06-02 10:48:24 +1000 | [diff] [blame] | 49 | extern struct xfs_btree_cur *xfs_inobt_init_cursor(struct xfs_mount *mp, |
Dave Chinner | 7b13c51 | 2021-06-02 10:48:24 +1000 | [diff] [blame] | 50 | struct xfs_trans *tp, struct xfs_buf *agbp, |
Dave Chinner | be9fb17 | 2021-06-02 10:48:24 +1000 | [diff] [blame] | 51 | struct xfs_perag *pag, xfs_btnum_t btnum); |
Darrick J. Wong | c29ce8f | 2020-03-11 11:01:04 -0700 | [diff] [blame] | 52 | struct xfs_btree_cur *xfs_inobt_stage_cursor(struct xfs_mount *mp, |
Dave Chinner | 7b13c51 | 2021-06-02 10:48:24 +1000 | [diff] [blame] | 53 | struct xbtree_afakeroot *afake, struct xfs_perag *pag, |
Darrick J. Wong | c29ce8f | 2020-03-11 11:01:04 -0700 | [diff] [blame] | 54 | xfs_btnum_t btnum); |
Christoph Hellwig | 60197e8 | 2008-10-30 17:11:19 +1100 | [diff] [blame] | 55 | extern int xfs_inobt_maxrecs(struct xfs_mount *, int, int); |
Christoph Hellwig | 561f7d1 | 2008-10-30 16:53:59 +1100 | [diff] [blame] | 56 | |
Brian Foster | 4148c34 | 2015-05-29 09:09:05 +1000 | [diff] [blame] | 57 | /* ir_holemask to inode allocation bitmap conversion */ |
| 58 | uint64_t xfs_inobt_irec_to_allocmask(struct xfs_inobt_rec_incore *); |
| 59 | |
Brian Foster | 56d1115 | 2015-05-29 09:18:32 +1000 | [diff] [blame] | 60 | #if defined(DEBUG) || defined(XFS_WARN) |
| 61 | int xfs_inobt_rec_check_count(struct xfs_mount *, |
| 62 | struct xfs_inobt_rec_incore *); |
| 63 | #else |
| 64 | #define xfs_inobt_rec_check_count(mp, rec) 0 |
| 65 | #endif /* DEBUG */ |
| 66 | |
Darrick J. Wong | ebcbef3 | 2018-07-29 22:37:08 -0700 | [diff] [blame] | 67 | int xfs_finobt_calc_reserves(struct xfs_mount *mp, struct xfs_trans *tp, |
Dave Chinner | 3093312 | 2021-06-02 10:48:24 +1000 | [diff] [blame] | 68 | struct xfs_perag *pag, xfs_extlen_t *ask, xfs_extlen_t *used); |
Darrick J. Wong | 14861c4 | 2018-05-09 10:02:01 -0700 | [diff] [blame] | 69 | extern xfs_extlen_t xfs_iallocbt_calc_size(struct xfs_mount *mp, |
| 70 | unsigned long long len); |
Darrick J. Wong | a211432 | 2019-07-02 09:39:38 -0700 | [diff] [blame] | 71 | int xfs_inobt_cur(struct xfs_mount *mp, struct xfs_trans *tp, |
Dave Chinner | 7b13c51 | 2021-06-02 10:48:24 +1000 | [diff] [blame] | 72 | struct xfs_perag *pag, xfs_btnum_t btnum, |
Darrick J. Wong | a211432 | 2019-07-02 09:39:38 -0700 | [diff] [blame] | 73 | struct xfs_btree_cur **curpp, struct xfs_buf **agi_bpp); |
Christoph Hellwig | 76d771b | 2017-01-25 07:49:35 -0800 | [diff] [blame] | 74 | |
Darrick J. Wong | c29ce8f | 2020-03-11 11:01:04 -0700 | [diff] [blame] | 75 | void xfs_inobt_commit_staged_btree(struct xfs_btree_cur *cur, |
| 76 | struct xfs_trans *tp, struct xfs_buf *agbp); |
| 77 | |
Darrick J. Wong | 0ed5f73 | 2021-09-23 10:32:06 -0700 | [diff] [blame] | 78 | unsigned int xfs_iallocbt_maxlevels_ondisk(void); |
| 79 | |
Darrick J. Wong | 9fa47bd | 2021-09-23 12:21:37 -0700 | [diff] [blame] | 80 | int __init xfs_inobt_init_cur_cache(void); |
| 81 | void xfs_inobt_destroy_cur_cache(void); |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | #endif /* __XFS_IALLOC_BTREE_H__ */ |