xref: /OK3568_Linux_fs/kernel/fs/xfs/xfs_rtalloc.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
4*4882a593Smuzhiyun  * All Rights Reserved.
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun #ifndef __XFS_RTALLOC_H__
7*4882a593Smuzhiyun #define	__XFS_RTALLOC_H__
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun /* kernel only definitions and functions */
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun struct xfs_mount;
12*4882a593Smuzhiyun struct xfs_trans;
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun /*
15*4882a593Smuzhiyun  * XXX: Most of the realtime allocation functions deal in units of realtime
16*4882a593Smuzhiyun  * extents, not realtime blocks.  This looks funny when paired with the type
17*4882a593Smuzhiyun  * name and screams for a larger cleanup.
18*4882a593Smuzhiyun  */
19*4882a593Smuzhiyun struct xfs_rtalloc_rec {
20*4882a593Smuzhiyun 	xfs_rtblock_t		ar_startext;
21*4882a593Smuzhiyun 	xfs_rtblock_t		ar_extcount;
22*4882a593Smuzhiyun };
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun typedef int (*xfs_rtalloc_query_range_fn)(
25*4882a593Smuzhiyun 	struct xfs_trans	*tp,
26*4882a593Smuzhiyun 	struct xfs_rtalloc_rec	*rec,
27*4882a593Smuzhiyun 	void			*priv);
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun #ifdef CONFIG_XFS_RT
30*4882a593Smuzhiyun /*
31*4882a593Smuzhiyun  * Function prototypes for exported functions.
32*4882a593Smuzhiyun  */
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun /*
35*4882a593Smuzhiyun  * Allocate an extent in the realtime subvolume, with the usual allocation
36*4882a593Smuzhiyun  * parameters.  The length units are all in realtime extents, as is the
37*4882a593Smuzhiyun  * result block number.
38*4882a593Smuzhiyun  */
39*4882a593Smuzhiyun int					/* error */
40*4882a593Smuzhiyun xfs_rtallocate_extent(
41*4882a593Smuzhiyun 	struct xfs_trans	*tp,	/* transaction pointer */
42*4882a593Smuzhiyun 	xfs_rtblock_t		bno,	/* starting block number to allocate */
43*4882a593Smuzhiyun 	xfs_extlen_t		minlen,	/* minimum length to allocate */
44*4882a593Smuzhiyun 	xfs_extlen_t		maxlen,	/* maximum length to allocate */
45*4882a593Smuzhiyun 	xfs_extlen_t		*len,	/* out: actual length allocated */
46*4882a593Smuzhiyun 	int			wasdel,	/* was a delayed allocation extent */
47*4882a593Smuzhiyun 	xfs_extlen_t		prod,	/* extent product factor */
48*4882a593Smuzhiyun 	xfs_rtblock_t		*rtblock); /* out: start block allocated */
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun /*
51*4882a593Smuzhiyun  * Free an extent in the realtime subvolume.  Length is expressed in
52*4882a593Smuzhiyun  * realtime extents, as is the block number.
53*4882a593Smuzhiyun  */
54*4882a593Smuzhiyun int					/* error */
55*4882a593Smuzhiyun xfs_rtfree_extent(
56*4882a593Smuzhiyun 	struct xfs_trans	*tp,	/* transaction pointer */
57*4882a593Smuzhiyun 	xfs_rtblock_t		bno,	/* starting block number to free */
58*4882a593Smuzhiyun 	xfs_extlen_t		len);	/* length of extent freed */
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun /*
61*4882a593Smuzhiyun  * Initialize realtime fields in the mount structure.
62*4882a593Smuzhiyun  */
63*4882a593Smuzhiyun int					/* error */
64*4882a593Smuzhiyun xfs_rtmount_init(
65*4882a593Smuzhiyun 	struct xfs_mount	*mp);	/* file system mount structure */
66*4882a593Smuzhiyun void
67*4882a593Smuzhiyun xfs_rtunmount_inodes(
68*4882a593Smuzhiyun 	struct xfs_mount	*mp);
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun /*
71*4882a593Smuzhiyun  * Get the bitmap and summary inodes into the mount structure
72*4882a593Smuzhiyun  * at mount time.
73*4882a593Smuzhiyun  */
74*4882a593Smuzhiyun int					/* error */
75*4882a593Smuzhiyun xfs_rtmount_inodes(
76*4882a593Smuzhiyun 	struct xfs_mount	*mp);	/* file system mount structure */
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun /*
79*4882a593Smuzhiyun  * Pick an extent for allocation at the start of a new realtime file.
80*4882a593Smuzhiyun  * Use the sequence number stored in the atime field of the bitmap inode.
81*4882a593Smuzhiyun  * Translate this to a fraction of the rtextents, and return the product
82*4882a593Smuzhiyun  * of rtextents and the fraction.
83*4882a593Smuzhiyun  * The fraction sequence is 0, 1/2, 1/4, 3/4, 1/8, ..., 7/8, 1/16, ...
84*4882a593Smuzhiyun  */
85*4882a593Smuzhiyun int					/* error */
86*4882a593Smuzhiyun xfs_rtpick_extent(
87*4882a593Smuzhiyun 	struct xfs_mount	*mp,	/* file system mount point */
88*4882a593Smuzhiyun 	struct xfs_trans	*tp,	/* transaction pointer */
89*4882a593Smuzhiyun 	xfs_extlen_t		len,	/* allocation length (rtextents) */
90*4882a593Smuzhiyun 	xfs_rtblock_t		*pick);	/* result rt extent */
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun /*
93*4882a593Smuzhiyun  * Grow the realtime area of the filesystem.
94*4882a593Smuzhiyun  */
95*4882a593Smuzhiyun int
96*4882a593Smuzhiyun xfs_growfs_rt(
97*4882a593Smuzhiyun 	struct xfs_mount	*mp,	/* file system mount structure */
98*4882a593Smuzhiyun 	xfs_growfs_rt_t		*in);	/* user supplied growfs struct */
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun /*
101*4882a593Smuzhiyun  * From xfs_rtbitmap.c
102*4882a593Smuzhiyun  */
103*4882a593Smuzhiyun int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp,
104*4882a593Smuzhiyun 		  xfs_rtblock_t block, int issum, struct xfs_buf **bpp);
105*4882a593Smuzhiyun int xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp,
106*4882a593Smuzhiyun 		      xfs_rtblock_t start, xfs_extlen_t len, int val,
107*4882a593Smuzhiyun 		      xfs_rtblock_t *new, int *stat);
108*4882a593Smuzhiyun int xfs_rtfind_back(struct xfs_mount *mp, struct xfs_trans *tp,
109*4882a593Smuzhiyun 		    xfs_rtblock_t start, xfs_rtblock_t limit,
110*4882a593Smuzhiyun 		    xfs_rtblock_t *rtblock);
111*4882a593Smuzhiyun int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp,
112*4882a593Smuzhiyun 		    xfs_rtblock_t start, xfs_rtblock_t limit,
113*4882a593Smuzhiyun 		    xfs_rtblock_t *rtblock);
114*4882a593Smuzhiyun int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp,
115*4882a593Smuzhiyun 		       xfs_rtblock_t start, xfs_extlen_t len, int val);
116*4882a593Smuzhiyun int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp,
117*4882a593Smuzhiyun 			     int log, xfs_rtblock_t bbno, int delta,
118*4882a593Smuzhiyun 			     xfs_buf_t **rbpp, xfs_fsblock_t *rsb,
119*4882a593Smuzhiyun 			     xfs_suminfo_t *sum);
120*4882a593Smuzhiyun int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log,
121*4882a593Smuzhiyun 			 xfs_rtblock_t bbno, int delta, xfs_buf_t **rbpp,
122*4882a593Smuzhiyun 			 xfs_fsblock_t *rsb);
123*4882a593Smuzhiyun int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
124*4882a593Smuzhiyun 		     xfs_rtblock_t start, xfs_extlen_t len,
125*4882a593Smuzhiyun 		     struct xfs_buf **rbpp, xfs_fsblock_t *rsb);
126*4882a593Smuzhiyun int xfs_rtalloc_query_range(struct xfs_trans *tp,
127*4882a593Smuzhiyun 			    struct xfs_rtalloc_rec *low_rec,
128*4882a593Smuzhiyun 			    struct xfs_rtalloc_rec *high_rec,
129*4882a593Smuzhiyun 			    xfs_rtalloc_query_range_fn fn,
130*4882a593Smuzhiyun 			    void *priv);
131*4882a593Smuzhiyun int xfs_rtalloc_query_all(struct xfs_trans *tp,
132*4882a593Smuzhiyun 			  xfs_rtalloc_query_range_fn fn,
133*4882a593Smuzhiyun 			  void *priv);
134*4882a593Smuzhiyun bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
135*4882a593Smuzhiyun int xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp,
136*4882a593Smuzhiyun 			       xfs_rtblock_t start, xfs_extlen_t len,
137*4882a593Smuzhiyun 			       bool *is_free);
138*4882a593Smuzhiyun #else
139*4882a593Smuzhiyun # define xfs_rtallocate_extent(t,b,min,max,l,f,p,rb)    (ENOSYS)
140*4882a593Smuzhiyun # define xfs_rtfree_extent(t,b,l)                       (ENOSYS)
141*4882a593Smuzhiyun # define xfs_rtpick_extent(m,t,l,rb)                    (ENOSYS)
142*4882a593Smuzhiyun # define xfs_growfs_rt(mp,in)                           (ENOSYS)
143*4882a593Smuzhiyun # define xfs_rtalloc_query_range(t,l,h,f,p)             (ENOSYS)
144*4882a593Smuzhiyun # define xfs_rtalloc_query_all(t,f,p)                   (ENOSYS)
145*4882a593Smuzhiyun # define xfs_rtbuf_get(m,t,b,i,p)                       (ENOSYS)
146*4882a593Smuzhiyun # define xfs_verify_rtbno(m, r)			(false)
147*4882a593Smuzhiyun # define xfs_rtalloc_extent_is_free(m,t,s,l,i)          (ENOSYS)
148*4882a593Smuzhiyun static inline int		/* error */
xfs_rtmount_init(xfs_mount_t * mp)149*4882a593Smuzhiyun xfs_rtmount_init(
150*4882a593Smuzhiyun 	xfs_mount_t	*mp)	/* file system mount structure */
151*4882a593Smuzhiyun {
152*4882a593Smuzhiyun 	if (mp->m_sb.sb_rblocks == 0)
153*4882a593Smuzhiyun 		return 0;
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun 	xfs_warn(mp, "Not built with CONFIG_XFS_RT");
156*4882a593Smuzhiyun 	return -ENOSYS;
157*4882a593Smuzhiyun }
158*4882a593Smuzhiyun # define xfs_rtmount_inodes(m)  (((mp)->m_sb.sb_rblocks == 0)? 0 : (ENOSYS))
159*4882a593Smuzhiyun # define xfs_rtunmount_inodes(m)
160*4882a593Smuzhiyun #endif	/* CONFIG_XFS_RT */
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun #endif	/* __XFS_RTALLOC_H__ */
163