blob: 45df893ef6bb00d473f717061ac1ca417ed0a39f [file] [log] [blame]
Nishad Kamdar508578f2020-05-12 16:54:17 -07001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Nathan Scott7b718762005-11-02 14:58:39 +11003 * Copyright (c) 2000,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6#ifndef __XFS_ALLOC_BTREE_H__
7#define __XFS_ALLOC_BTREE_H__
8
9/*
10 * Freespace on-disk structures
11 */
12
13struct xfs_buf;
14struct xfs_btree_cur;
Linus Torvalds1da177e2005-04-16 15:20:36 -070015struct xfs_mount;
Dave Chinnerbe9fb172021-06-02 10:48:24 +100016struct xfs_perag;
Darrick J. Wonge6eb33d2020-03-11 10:52:49 -070017struct xbtree_afakeroot;
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19/*
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110020 * Btree block header size depends on a superblock flag.
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110021 */
Christoph Hellwigee1a47a2013-04-21 14:53:46 -050022#define XFS_ALLOC_BLOCK_LEN(mp) \
Dave Chinner38c26bf2021-08-18 18:46:37 -070023 (xfs_has_crc(((mp))) ? \
Christoph Hellwigee1a47a2013-04-21 14:53:46 -050024 XFS_BTREE_SBLOCK_CRC_LEN : XFS_BTREE_SBLOCK_LEN)
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110025
26/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 * Record, key, and pointer address macros for btree blocks.
Christoph Hellwig136341b2008-10-30 17:11:40 +110028 *
29 * (note that some of these may appear unused, but they are used in userspace)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 */
Christoph Hellwig136341b2008-10-30 17:11:40 +110031#define XFS_ALLOC_REC_ADDR(mp, block, index) \
32 ((xfs_alloc_rec_t *) \
33 ((char *)(block) + \
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110034 XFS_ALLOC_BLOCK_LEN(mp) + \
Christoph Hellwig136341b2008-10-30 17:11:40 +110035 (((index) - 1) * sizeof(xfs_alloc_rec_t))))
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Christoph Hellwig136341b2008-10-30 17:11:40 +110037#define XFS_ALLOC_KEY_ADDR(mp, block, index) \
38 ((xfs_alloc_key_t *) \
39 ((char *)(block) + \
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110040 XFS_ALLOC_BLOCK_LEN(mp) + \
Christoph Hellwig136341b2008-10-30 17:11:40 +110041 ((index) - 1) * sizeof(xfs_alloc_key_t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Christoph Hellwig136341b2008-10-30 17:11:40 +110043#define XFS_ALLOC_PTR_ADDR(mp, block, index, maxrecs) \
44 ((xfs_alloc_ptr_t *) \
45 ((char *)(block) + \
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110046 XFS_ALLOC_BLOCK_LEN(mp) + \
Christoph Hellwig136341b2008-10-30 17:11:40 +110047 (maxrecs) * sizeof(xfs_alloc_key_t) + \
48 ((index) - 1) * sizeof(xfs_alloc_ptr_t)))
Christoph Hellwig561f7d12008-10-30 16:53:59 +110049
Dave Chinner289d38d2021-06-02 10:48:24 +100050extern 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. Wonge6eb33d2020-03-11 10:52:49 -070053struct xfs_btree_cur *xfs_allocbt_stage_cursor(struct xfs_mount *mp,
Dave Chinner289d38d2021-06-02 10:48:24 +100054 struct xbtree_afakeroot *afake, struct xfs_perag *pag,
Darrick J. Wonge6eb33d2020-03-11 10:52:49 -070055 xfs_btnum_t btnum);
Christoph Hellwig60197e82008-10-30 17:11:19 +110056extern int xfs_allocbt_maxrecs(struct xfs_mount *, int, int);
Darrick J. Wong14861c42018-05-09 10:02:01 -070057extern xfs_extlen_t xfs_allocbt_calc_size(struct xfs_mount *mp,
58 unsigned long long len);
Christoph Hellwig561f7d12008-10-30 16:53:59 +110059
Darrick J. Wonge6eb33d2020-03-11 10:52:49 -070060void xfs_allocbt_commit_staged_btree(struct xfs_btree_cur *cur,
61 struct xfs_trans *tp, struct xfs_buf *agbp);
62
Darrick J. Wong0ed5f732021-09-23 10:32:06 -070063unsigned int xfs_allocbt_maxlevels_ondisk(void);
64
Darrick J. Wong9fa47bd2021-09-23 12:21:37 -070065int __init xfs_allocbt_init_cur_cache(void);
66void xfs_allocbt_destroy_cur_cache(void);
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#endif /* __XFS_ALLOC_BTREE_H__ */