Commit | Line | Data |
---|---|---|
13928113 DW |
1 | // SPDX-License-Identifier: GPL-2.0 |
2 | /* | |
3 | * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc. | |
4 | * All Rights Reserved. | |
5 | */ | |
6 | #ifndef __XFS_RTBITMAP_H__ | |
7 | #define __XFS_RTBITMAP_H__ | |
8 | ||
fa5a3872 DW |
9 | static inline xfs_rtblock_t |
10 | xfs_rtx_to_rtb( | |
11 | struct xfs_mount *mp, | |
12 | xfs_rtxnum_t rtx) | |
13 | { | |
14 | return rtx * mp->m_sb.sb_rextsize; | |
15 | } | |
16 | ||
17 | static inline xfs_extlen_t | |
18 | xfs_rtxlen_to_extlen( | |
19 | struct xfs_mount *mp, | |
20 | xfs_rtxlen_t rtxlen) | |
21 | { | |
22 | return rtxlen * mp->m_sb.sb_rextsize; | |
23 | } | |
24 | ||
68db60bf DW |
25 | /* Compute the misalignment between an extent length and a realtime extent .*/ |
26 | static inline unsigned int | |
27 | xfs_extlen_to_rtxmod( | |
28 | struct xfs_mount *mp, | |
29 | xfs_extlen_t len) | |
30 | { | |
31 | return len % mp->m_sb.sb_rextsize; | |
32 | } | |
33 | ||
2c2b981b DW |
34 | static inline xfs_rtxlen_t |
35 | xfs_extlen_to_rtxlen( | |
36 | struct xfs_mount *mp, | |
37 | xfs_extlen_t len) | |
38 | { | |
39 | return len / mp->m_sb.sb_rextsize; | |
40 | } | |
41 | ||
5dc3a80d DW |
42 | /* Convert an rt block number into an rt extent number. */ |
43 | static inline xfs_rtxnum_t | |
44 | xfs_rtb_to_rtx( | |
45 | struct xfs_mount *mp, | |
46 | xfs_rtblock_t rtbno) | |
47 | { | |
48 | return div_u64(rtbno, mp->m_sb.sb_rextsize); | |
49 | } | |
50 | ||
51 | /* Return the offset of an rt block number within an rt extent. */ | |
52 | static inline xfs_extlen_t | |
53 | xfs_rtb_to_rtxoff( | |
54 | struct xfs_mount *mp, | |
55 | xfs_rtblock_t rtbno) | |
56 | { | |
57 | return do_div(rtbno, mp->m_sb.sb_rextsize); | |
58 | } | |
59 | ||
60 | /* | |
61 | * Crack an rt block number into an rt extent number and an offset within that | |
62 | * rt extent. Returns the rt extent number directly and the offset in @off. | |
63 | */ | |
64 | static inline xfs_rtxnum_t | |
65 | xfs_rtb_to_rtxrem( | |
66 | struct xfs_mount *mp, | |
67 | xfs_rtblock_t rtbno, | |
68 | xfs_extlen_t *off) | |
69 | { | |
70 | return div_u64_rem(rtbno, mp->m_sb.sb_rextsize, off); | |
71 | } | |
72 | ||
13928113 | 73 | /* |
2d5f216b | 74 | * Functions for walking free space rtextents in the realtime bitmap. |
13928113 DW |
75 | */ |
76 | struct xfs_rtalloc_rec { | |
2d5f216b | 77 | xfs_rtxnum_t ar_startext; |
f29c3e74 | 78 | xfs_rtbxlen_t ar_extcount; |
13928113 DW |
79 | }; |
80 | ||
81 | typedef int (*xfs_rtalloc_query_range_fn)( | |
82 | struct xfs_mount *mp, | |
83 | struct xfs_trans *tp, | |
84 | const struct xfs_rtalloc_rec *rec, | |
85 | void *priv); | |
86 | ||
87 | #ifdef CONFIG_XFS_RT | |
88 | int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp, | |
03f4de33 | 89 | xfs_fileoff_t block, int issum, struct xfs_buf **bpp); |
13928113 | 90 | int xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp, |
2d5f216b DW |
91 | xfs_rtxnum_t start, xfs_rtxlen_t len, int val, |
92 | xfs_rtxnum_t *new, int *stat); | |
13928113 | 93 | int xfs_rtfind_back(struct xfs_mount *mp, struct xfs_trans *tp, |
2d5f216b DW |
94 | xfs_rtxnum_t start, xfs_rtxnum_t limit, |
95 | xfs_rtxnum_t *rtblock); | |
13928113 | 96 | int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp, |
2d5f216b DW |
97 | xfs_rtxnum_t start, xfs_rtxnum_t limit, |
98 | xfs_rtxnum_t *rtblock); | |
13928113 | 99 | int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp, |
2d5f216b | 100 | xfs_rtxnum_t start, xfs_rtxlen_t len, int val); |
13928113 | 101 | int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp, |
03f4de33 DW |
102 | int log, xfs_fileoff_t bbno, int delta, |
103 | struct xfs_buf **rbpp, xfs_fileoff_t *rsb, | |
13928113 DW |
104 | xfs_suminfo_t *sum); |
105 | int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log, | |
03f4de33 DW |
106 | xfs_fileoff_t bbno, int delta, struct xfs_buf **rbpp, |
107 | xfs_fileoff_t *rsb); | |
13928113 | 108 | int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp, |
2d5f216b | 109 | xfs_rtxnum_t start, xfs_rtxlen_t len, |
03f4de33 | 110 | struct xfs_buf **rbpp, xfs_fileoff_t *rsb); |
13928113 DW |
111 | int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp, |
112 | const struct xfs_rtalloc_rec *low_rec, | |
113 | const struct xfs_rtalloc_rec *high_rec, | |
114 | xfs_rtalloc_query_range_fn fn, void *priv); | |
115 | int xfs_rtalloc_query_all(struct xfs_mount *mp, struct xfs_trans *tp, | |
116 | xfs_rtalloc_query_range_fn fn, | |
117 | void *priv); | |
13928113 | 118 | int xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp, |
2d5f216b | 119 | xfs_rtxnum_t start, xfs_rtxlen_t len, |
13928113 DW |
120 | bool *is_free); |
121 | /* | |
122 | * Free an extent in the realtime subvolume. Length is expressed in | |
123 | * realtime extents, as is the block number. | |
124 | */ | |
125 | int /* error */ | |
126 | xfs_rtfree_extent( | |
127 | struct xfs_trans *tp, /* transaction pointer */ | |
2d5f216b | 128 | xfs_rtxnum_t start, /* starting rtext number to free */ |
a684c538 | 129 | xfs_rtxlen_t len); /* length of extent freed */ |
13928113 DW |
130 | |
131 | /* Same as above, but in units of rt blocks. */ | |
132 | int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno, | |
133 | xfs_filblks_t rtlen); | |
134 | #else /* CONFIG_XFS_RT */ | |
135 | # define xfs_rtfree_extent(t,b,l) (-ENOSYS) | |
136 | # define xfs_rtfree_blocks(t,rb,rl) (-ENOSYS) | |
137 | # define xfs_rtalloc_query_range(m,t,l,h,f,p) (-ENOSYS) | |
138 | # define xfs_rtalloc_query_all(m,t,f,p) (-ENOSYS) | |
139 | # define xfs_rtbuf_get(m,t,b,i,p) (-ENOSYS) | |
140 | # define xfs_rtalloc_extent_is_free(m,t,s,l,i) (-ENOSYS) | |
141 | #endif /* CONFIG_XFS_RT */ | |
142 | ||
143 | #endif /* __XFS_RTBITMAP_H__ */ |