xref: /linux/fs/xfs/libxfs/xfs_rtbitmap.h (revision fa5a387230861116c2434c20d29fc4b3fd077d24)
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 	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 
25 /*
26  * Functions for walking free space rtextents in the realtime bitmap.
27  */
28 struct xfs_rtalloc_rec {
29 	xfs_rtxnum_t		ar_startext;
30 	xfs_rtbxlen_t		ar_extcount;
31 };
32 
33 typedef int (*xfs_rtalloc_query_range_fn)(
34 	struct xfs_mount		*mp,
35 	struct xfs_trans		*tp,
36 	const struct xfs_rtalloc_rec	*rec,
37 	void				*priv);
38 
39 #ifdef CONFIG_XFS_RT
40 int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp,
41 		  xfs_fileoff_t block, int issum, struct xfs_buf **bpp);
42 int xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp,
43 		      xfs_rtxnum_t start, xfs_rtxlen_t len, int val,
44 		      xfs_rtxnum_t *new, int *stat);
45 int xfs_rtfind_back(struct xfs_mount *mp, struct xfs_trans *tp,
46 		    xfs_rtxnum_t start, xfs_rtxnum_t limit,
47 		    xfs_rtxnum_t *rtblock);
48 int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp,
49 		    xfs_rtxnum_t start, xfs_rtxnum_t limit,
50 		    xfs_rtxnum_t *rtblock);
51 int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp,
52 		       xfs_rtxnum_t start, xfs_rtxlen_t len, int val);
53 int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp,
54 			     int log, xfs_fileoff_t bbno, int delta,
55 			     struct xfs_buf **rbpp, xfs_fileoff_t *rsb,
56 			     xfs_suminfo_t *sum);
57 int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log,
58 			 xfs_fileoff_t bbno, int delta, struct xfs_buf **rbpp,
59 			 xfs_fileoff_t *rsb);
60 int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
61 		     xfs_rtxnum_t start, xfs_rtxlen_t len,
62 		     struct xfs_buf **rbpp, xfs_fileoff_t *rsb);
63 int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp,
64 		const struct xfs_rtalloc_rec *low_rec,
65 		const struct xfs_rtalloc_rec *high_rec,
66 		xfs_rtalloc_query_range_fn fn, void *priv);
67 int xfs_rtalloc_query_all(struct xfs_mount *mp, struct xfs_trans *tp,
68 			  xfs_rtalloc_query_range_fn fn,
69 			  void *priv);
70 int xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp,
71 			       xfs_rtxnum_t start, xfs_rtxlen_t len,
72 			       bool *is_free);
73 /*
74  * Free an extent in the realtime subvolume.  Length is expressed in
75  * realtime extents, as is the block number.
76  */
77 int					/* error */
78 xfs_rtfree_extent(
79 	struct xfs_trans	*tp,	/* transaction pointer */
80 	xfs_rtxnum_t		start,	/* starting rtext number to free */
81 	xfs_rtxlen_t		len);	/* length of extent freed */
82 
83 /* Same as above, but in units of rt blocks. */
84 int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno,
85 		xfs_filblks_t rtlen);
86 #else /* CONFIG_XFS_RT */
87 # define xfs_rtfree_extent(t,b,l)			(-ENOSYS)
88 # define xfs_rtfree_blocks(t,rb,rl)			(-ENOSYS)
89 # define xfs_rtalloc_query_range(m,t,l,h,f,p)		(-ENOSYS)
90 # define xfs_rtalloc_query_all(m,t,f,p)			(-ENOSYS)
91 # define xfs_rtbuf_get(m,t,b,i,p)			(-ENOSYS)
92 # define xfs_rtalloc_extent_is_free(m,t,s,l,i)		(-ENOSYS)
93 #endif /* CONFIG_XFS_RT */
94 
95 #endif /* __XFS_RTBITMAP_H__ */
96