summaryrefslogtreecommitdiff
path: root/fs/xfs/libxfs/xfs_rtrefcount_btree.h
blob: 1f3f590c68e6bfaa342ace46d9d8b176adfab32a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2022 Oracle.  All Rights Reserved.
 * Author: Darrick J. Wong <djwong@kernel.org>
 */
#ifndef __XFS_RTREFCOUNT_BTREE_H__
#define __XFS_RTREFCOUNT_BTREE_H__

struct xfs_buf;
struct xfs_btree_cur;
struct xfs_mount;
struct xbtree_ifakeroot;
struct xfs_rtgroup;
struct xfs_imeta_path;

/* refcounts only exist on crc enabled filesystems */
#define XFS_RTREFCOUNT_BLOCK_LEN	XFS_BTREE_LBLOCK_CRC_LEN

struct xfs_btree_cur *xfs_rtrefcountbt_init_cursor(struct xfs_mount *mp,
		struct xfs_trans *tp, struct xfs_rtgroup *rtg,
		struct xfs_inode *ip);
struct xfs_btree_cur *xfs_rtrefcountbt_stage_cursor(struct xfs_mount *mp,
		struct xfs_rtgroup *rtg, struct xfs_inode *ip,
		struct xbtree_ifakeroot *ifake);
void xfs_rtrefcountbt_commit_staged_btree(struct xfs_btree_cur *cur,
		struct xfs_trans *tp);
unsigned int xfs_rtrefcountbt_maxrecs(struct xfs_mount *mp,
		unsigned int blocklen, bool leaf);
void xfs_rtrefcountbt_compute_maxlevels(struct xfs_mount *mp);

/*
 * Addresses of records, keys, and pointers within an incore rtrefcountbt block.
 *
 * (note that some of these may appear unused, but they are used in userspace)
 */
static inline struct xfs_refcount_rec *
xfs_rtrefcount_rec_addr(
	struct xfs_btree_block	*block,
	unsigned int		index)
{
	return (struct xfs_refcount_rec *)
		((char *)block + XFS_RTREFCOUNT_BLOCK_LEN +
		 (index - 1) * sizeof(struct xfs_refcount_rec));
}

static inline struct xfs_refcount_key *
xfs_rtrefcount_key_addr(
	struct xfs_btree_block	*block,
	unsigned int		index)
{
	return (struct xfs_refcount_key *)
		((char *)block + XFS_RTREFCOUNT_BLOCK_LEN +
		 (index - 1) * sizeof(struct xfs_refcount_key));
}

static inline xfs_rtrefcount_ptr_t *
xfs_rtrefcount_ptr_addr(
	struct xfs_btree_block	*block,
	unsigned int		index,
	unsigned int		maxrecs)
{
	return (xfs_rtrefcount_ptr_t *)
		((char *)block + XFS_RTREFCOUNT_BLOCK_LEN +
		 maxrecs * sizeof(struct xfs_refcount_key) +
		 (index - 1) * sizeof(xfs_rtrefcount_ptr_t));
}

unsigned int xfs_rtrefcountbt_maxlevels_ondisk(void);
int __init xfs_rtrefcountbt_init_cur_cache(void);
void xfs_rtrefcountbt_destroy_cur_cache(void);

int xfs_rtrefcountbt_create_path(struct xfs_mount *mp, xfs_rgnumber_t rgno,
		struct xfs_imeta_path **pathp);

#endif	/* __XFS_RTREFCOUNT_BTREE_H__ */