1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
6 #ifndef __XFS_RTBITMAP_H__
7 #define __XFS_RTBITMAP_H__
9 static inline xfs_rtblock_t
14 if (mp
->m_rtxblklog
>= 0)
15 return rtx
<< mp
->m_rtxblklog
;
17 return rtx
* mp
->m_sb
.sb_rextsize
;
20 static inline xfs_extlen_t
25 if (mp
->m_rtxblklog
>= 0)
26 return rtxlen
<< mp
->m_rtxblklog
;
28 return rtxlen
* mp
->m_sb
.sb_rextsize
;
31 /* Compute the misalignment between an extent length and a realtime extent .*/
32 static inline unsigned int
37 if (mp
->m_rtxblklog
>= 0)
38 return len
& mp
->m_rtxblkmask
;
40 return len
% mp
->m_sb
.sb_rextsize
;
43 static inline xfs_rtxlen_t
48 if (mp
->m_rtxblklog
>= 0)
49 return len
>> mp
->m_rtxblklog
;
51 return len
/ mp
->m_sb
.sb_rextsize
;
54 /* Convert an rt block number into an rt extent number. */
55 static inline xfs_rtxnum_t
60 if (likely(mp
->m_rtxblklog
>= 0))
61 return rtbno
>> mp
->m_rtxblklog
;
63 return div_u64(rtbno
, mp
->m_sb
.sb_rextsize
);
66 /* Return the offset of an rt block number within an rt extent. */
67 static inline xfs_extlen_t
72 if (likely(mp
->m_rtxblklog
>= 0))
73 return rtbno
& mp
->m_rtxblkmask
;
75 return do_div(rtbno
, mp
->m_sb
.sb_rextsize
);
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.
82 static inline xfs_rtxnum_t
88 if (likely(mp
->m_rtxblklog
>= 0)) {
89 *off
= rtbno
& mp
->m_rtxblkmask
;
90 return rtbno
>> mp
->m_rtxblklog
;
93 return div_u64_rem(rtbno
, mp
->m_sb
.sb_rextsize
, off
);
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.
100 static inline xfs_rtxnum_t
102 struct xfs_mount
*mp
,
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
;
111 if (do_div(rtbno
, mp
->m_sb
.sb_rextsize
))
116 /* Round this rtblock up to the nearest rt extent size. */
117 static inline xfs_rtblock_t
119 struct xfs_mount
*mp
,
122 return roundup_64(rtbno
, mp
->m_sb
.sb_rextsize
);
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
,
131 return rounddown_64(rtbno
, mp
->m_sb
.sb_rextsize
);
134 /* Convert an rt extent number to a file block offset in the rt bitmap file. */
135 static inline xfs_fileoff_t
137 struct xfs_mount
*mp
,
140 return rtx
>> mp
->m_blkbit_log
;
143 /* Convert an rt extent number to a word offset within an rt bitmap block. */
144 static inline unsigned int
146 struct xfs_mount
*mp
,
149 return (rtx
>> XFS_NBWORDLOG
) & XFS_BLOCKWMASK(mp
);
152 /* Convert a file block offset in the rt bitmap file to an rt extent number. */
153 static inline xfs_rtxnum_t
155 struct xfs_mount
*mp
,
156 xfs_fileoff_t rbmoff
)
158 return rbmoff
<< mp
->m_blkbit_log
;
162 * Functions for walking free space rtextents in the realtime bitmap.
164 struct xfs_rtalloc_rec
{
165 xfs_rtxnum_t ar_startext
;
166 xfs_rtbxlen_t ar_extcount
;
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
,
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
,
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
,
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
,
206 int xfs_rtalloc_extent_is_free(struct xfs_mount
*mp
, struct xfs_trans
*tp
,
207 xfs_rtxnum_t start
, xfs_rtxlen_t len
,
210 * Free an extent in the realtime subvolume. Length is expressed in
211 * realtime extents, as is the block number.
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 */
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 */
231 #endif /* __XFS_RTBITMAP_H__ */