]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxfs/xfs_rtbitmap.h
xfs: convert the rtbitmap block and bit macros to static inline functions
[thirdparty/xfsprogs-dev.git] / libxfs / xfs_rtbitmap.h
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
9 static inline xfs_rtblock_t
10 xfs_rtx_to_rtb(
11 struct xfs_mount *mp,
12 xfs_rtxnum_t rtx)
13 {
14 if (mp->m_rtxblklog >= 0)
15 return rtx << mp->m_rtxblklog;
16
17 return rtx * mp->m_sb.sb_rextsize;
18 }
19
20 static inline xfs_extlen_t
21 xfs_rtxlen_to_extlen(
22 struct xfs_mount *mp,
23 xfs_rtxlen_t rtxlen)
24 {
25 if (mp->m_rtxblklog >= 0)
26 return rtxlen << mp->m_rtxblklog;
27
28 return rtxlen * mp->m_sb.sb_rextsize;
29 }
30
31 /* Compute the misalignment between an extent length and a realtime extent .*/
32 static inline unsigned int
33 xfs_extlen_to_rtxmod(
34 struct xfs_mount *mp,
35 xfs_extlen_t len)
36 {
37 if (mp->m_rtxblklog >= 0)
38 return len & mp->m_rtxblkmask;
39
40 return len % mp->m_sb.sb_rextsize;
41 }
42
43 static inline xfs_rtxlen_t
44 xfs_extlen_to_rtxlen(
45 struct xfs_mount *mp,
46 xfs_extlen_t len)
47 {
48 if (mp->m_rtxblklog >= 0)
49 return len >> mp->m_rtxblklog;
50
51 return len / mp->m_sb.sb_rextsize;
52 }
53
54 /* Convert an rt block number into an rt extent number. */
55 static inline xfs_rtxnum_t
56 xfs_rtb_to_rtx(
57 struct xfs_mount *mp,
58 xfs_rtblock_t rtbno)
59 {
60 if (likely(mp->m_rtxblklog >= 0))
61 return rtbno >> mp->m_rtxblklog;
62
63 return div_u64(rtbno, mp->m_sb.sb_rextsize);
64 }
65
66 /* Return the offset of an rt block number within an rt extent. */
67 static inline xfs_extlen_t
68 xfs_rtb_to_rtxoff(
69 struct xfs_mount *mp,
70 xfs_rtblock_t rtbno)
71 {
72 if (likely(mp->m_rtxblklog >= 0))
73 return rtbno & mp->m_rtxblkmask;
74
75 return do_div(rtbno, mp->m_sb.sb_rextsize);
76 }
77
78 /*
79 * Crack an rt block number into an rt extent number and an offset within that
80 * rt extent. Returns the rt extent number directly and the offset in @off.
81 */
82 static inline xfs_rtxnum_t
83 xfs_rtb_to_rtxrem(
84 struct xfs_mount *mp,
85 xfs_rtblock_t rtbno,
86 xfs_extlen_t *off)
87 {
88 if (likely(mp->m_rtxblklog >= 0)) {
89 *off = rtbno & mp->m_rtxblkmask;
90 return rtbno >> mp->m_rtxblklog;
91 }
92
93 return div_u64_rem(rtbno, mp->m_sb.sb_rextsize, off);
94 }
95
96 /*
97 * Convert an rt block number into an rt extent number, rounding up to the next
98 * rt extent if the rt block is not aligned to an rt extent boundary.
99 */
100 static inline xfs_rtxnum_t
101 xfs_rtb_to_rtxup(
102 struct xfs_mount *mp,
103 xfs_rtblock_t rtbno)
104 {
105 if (likely(mp->m_rtxblklog >= 0)) {
106 if (rtbno & mp->m_rtxblkmask)
107 return (rtbno >> mp->m_rtxblklog) + 1;
108 return rtbno >> mp->m_rtxblklog;
109 }
110
111 if (do_div(rtbno, mp->m_sb.sb_rextsize))
112 rtbno++;
113 return rtbno;
114 }
115
116 /* Round this rtblock up to the nearest rt extent size. */
117 static inline xfs_rtblock_t
118 xfs_rtb_roundup_rtx(
119 struct xfs_mount *mp,
120 xfs_rtblock_t rtbno)
121 {
122 return roundup_64(rtbno, mp->m_sb.sb_rextsize);
123 }
124
125 /* Round this rtblock down to the nearest rt extent size. */
126 static inline xfs_rtblock_t
127 xfs_rtb_rounddown_rtx(
128 struct xfs_mount *mp,
129 xfs_rtblock_t rtbno)
130 {
131 return rounddown_64(rtbno, mp->m_sb.sb_rextsize);
132 }
133
134 /* Convert an rt extent number to a file block offset in the rt bitmap file. */
135 static inline xfs_fileoff_t
136 xfs_rtx_to_rbmblock(
137 struct xfs_mount *mp,
138 xfs_rtxnum_t rtx)
139 {
140 return rtx >> mp->m_blkbit_log;
141 }
142
143 /* Convert an rt extent number to a word offset within an rt bitmap block. */
144 static inline unsigned int
145 xfs_rtx_to_rbmword(
146 struct xfs_mount *mp,
147 xfs_rtxnum_t rtx)
148 {
149 return (rtx >> XFS_NBWORDLOG) & XFS_BLOCKWMASK(mp);
150 }
151
152 /* Convert a file block offset in the rt bitmap file to an rt extent number. */
153 static inline xfs_rtxnum_t
154 xfs_rbmblock_to_rtx(
155 struct xfs_mount *mp,
156 xfs_fileoff_t rbmoff)
157 {
158 return rbmoff << mp->m_blkbit_log;
159 }
160
161 /*
162 * Functions for walking free space rtextents in the realtime bitmap.
163 */
164 struct xfs_rtalloc_rec {
165 xfs_rtxnum_t ar_startext;
166 xfs_rtbxlen_t ar_extcount;
167 };
168
169 typedef int (*xfs_rtalloc_query_range_fn)(
170 struct xfs_mount *mp,
171 struct xfs_trans *tp,
172 const struct xfs_rtalloc_rec *rec,
173 void *priv);
174
175 #ifdef CONFIG_XFS_RT
176 int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp,
177 xfs_fileoff_t block, int issum, struct xfs_buf **bpp);
178 int xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp,
179 xfs_rtxnum_t start, xfs_rtxlen_t len, int val,
180 xfs_rtxnum_t *new, int *stat);
181 int xfs_rtfind_back(struct xfs_mount *mp, struct xfs_trans *tp,
182 xfs_rtxnum_t start, xfs_rtxnum_t limit,
183 xfs_rtxnum_t *rtblock);
184 int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp,
185 xfs_rtxnum_t start, xfs_rtxnum_t limit,
186 xfs_rtxnum_t *rtblock);
187 int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp,
188 xfs_rtxnum_t start, xfs_rtxlen_t len, int val);
189 int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp,
190 int log, xfs_fileoff_t bbno, int delta,
191 struct xfs_buf **rbpp, xfs_fileoff_t *rsb,
192 xfs_suminfo_t *sum);
193 int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log,
194 xfs_fileoff_t bbno, int delta, struct xfs_buf **rbpp,
195 xfs_fileoff_t *rsb);
196 int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
197 xfs_rtxnum_t start, xfs_rtxlen_t len,
198 struct xfs_buf **rbpp, xfs_fileoff_t *rsb);
199 int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp,
200 const struct xfs_rtalloc_rec *low_rec,
201 const struct xfs_rtalloc_rec *high_rec,
202 xfs_rtalloc_query_range_fn fn, void *priv);
203 int xfs_rtalloc_query_all(struct xfs_mount *mp, struct xfs_trans *tp,
204 xfs_rtalloc_query_range_fn fn,
205 void *priv);
206 int xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp,
207 xfs_rtxnum_t start, xfs_rtxlen_t len,
208 bool *is_free);
209 /*
210 * Free an extent in the realtime subvolume. Length is expressed in
211 * realtime extents, as is the block number.
212 */
213 int /* error */
214 xfs_rtfree_extent(
215 struct xfs_trans *tp, /* transaction pointer */
216 xfs_rtxnum_t start, /* starting rtext number to free */
217 xfs_rtxlen_t len); /* length of extent freed */
218
219 /* Same as above, but in units of rt blocks. */
220 int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno,
221 xfs_filblks_t rtlen);
222 #else /* CONFIG_XFS_RT */
223 # define xfs_rtfree_extent(t,b,l) (-ENOSYS)
224 # define xfs_rtfree_blocks(t,rb,rl) (-ENOSYS)
225 # define xfs_rtalloc_query_range(m,t,l,h,f,p) (-ENOSYS)
226 # define xfs_rtalloc_query_all(m,t,f,p) (-ENOSYS)
227 # define xfs_rtbuf_get(m,t,b,i,p) (-ENOSYS)
228 # define xfs_rtalloc_extent_is_free(m,t,s,l,i) (-ENOSYS)
229 #endif /* CONFIG_XFS_RT */
230
231 #endif /* __XFS_RTBITMAP_H__ */