1
2
3
4
5
6#ifndef __XFS_ALLOC_H__
7#define __XFS_ALLOC_H__
8
9struct xfs_buf;
10struct xfs_btree_cur;
11struct xfs_mount;
12struct xfs_perag;
13struct xfs_trans;
14
15extern struct workqueue_struct *xfs_alloc_wq;
16
17unsigned int xfs_agfl_size(struct xfs_mount *mp);
18
19
20
21
22#define XFS_ALLOCTYPE_FIRST_AG 0x02
23#define XFS_ALLOCTYPE_THIS_AG 0x08
24#define XFS_ALLOCTYPE_START_BNO 0x10
25#define XFS_ALLOCTYPE_NEAR_BNO 0x20
26#define XFS_ALLOCTYPE_THIS_BNO 0x40
27
28
29typedef unsigned int xfs_alloctype_t;
30
31#define XFS_ALLOC_TYPES \
32 { XFS_ALLOCTYPE_FIRST_AG, "FIRST_AG" }, \
33 { XFS_ALLOCTYPE_THIS_AG, "THIS_AG" }, \
34 { XFS_ALLOCTYPE_START_BNO, "START_BNO" }, \
35 { XFS_ALLOCTYPE_NEAR_BNO, "NEAR_BNO" }, \
36 { XFS_ALLOCTYPE_THIS_BNO, "THIS_BNO" }
37
38
39
40
41#define XFS_ALLOC_FLAG_TRYLOCK 0x00000001
42#define XFS_ALLOC_FLAG_FREEING 0x00000002
43#define XFS_ALLOC_FLAG_NORMAP 0x00000004
44#define XFS_ALLOC_FLAG_NOSHRINK 0x00000008
45#define XFS_ALLOC_FLAG_CHECK 0x00000010
46
47
48
49
50
51
52typedef struct xfs_alloc_arg {
53 struct xfs_trans *tp;
54 struct xfs_mount *mp;
55 struct xfs_buf *agbp;
56 struct xfs_perag *pag;
57 struct xfs_inode *ip;
58 xfs_fsblock_t fsbno;
59 xfs_agnumber_t agno;
60 xfs_agblock_t agbno;
61 xfs_extlen_t minlen;
62 xfs_extlen_t maxlen;
63 xfs_extlen_t mod;
64 xfs_extlen_t prod;
65 xfs_extlen_t minleft;
66 xfs_extlen_t total;
67 xfs_extlen_t alignment;
68 xfs_extlen_t minalignslop;
69 xfs_agblock_t min_agbno;
70 xfs_agblock_t max_agbno;
71 xfs_extlen_t len;
72 xfs_alloctype_t type;
73 xfs_alloctype_t otype;
74 int datatype;
75 char wasdel;
76 char wasfromfl;
77 struct xfs_owner_info oinfo;
78 enum xfs_ag_resv_type resv;
79} xfs_alloc_arg_t;
80
81
82
83
84#define XFS_ALLOC_USERDATA (1 << 0)
85#define XFS_ALLOC_INITIAL_USER_DATA (1 << 1)
86#define XFS_ALLOC_USERDATA_ZERO (1 << 2)
87#define XFS_ALLOC_NOBUSY (1 << 3)
88
89static inline bool
90xfs_alloc_is_userdata(int datatype)
91{
92 return (datatype & ~XFS_ALLOC_NOBUSY) != 0;
93}
94
95static inline bool
96xfs_alloc_allow_busy_reuse(int datatype)
97{
98 return (datatype & XFS_ALLOC_NOBUSY) == 0;
99}
100
101
102#define XFS_ALLOC_AGFL_RESERVE 4
103unsigned int xfs_alloc_set_aside(struct xfs_mount *mp);
104unsigned int xfs_alloc_ag_max_usable(struct xfs_mount *mp);
105
106xfs_extlen_t xfs_alloc_longest_free_extent(struct xfs_perag *pag,
107 xfs_extlen_t need, xfs_extlen_t reserved);
108unsigned int xfs_alloc_min_freelist(struct xfs_mount *mp,
109 struct xfs_perag *pag);
110
111
112
113
114void
115xfs_alloc_compute_maxlevels(
116 struct xfs_mount *mp);
117
118
119
120
121
122int
123xfs_alloc_get_freelist(
124 struct xfs_trans *tp,
125 struct xfs_buf *agbp,
126 xfs_agblock_t *bnop,
127 int btreeblk);
128
129
130
131
132void
133xfs_alloc_log_agf(
134 struct xfs_trans *tp,
135 struct xfs_buf *bp,
136 int fields);
137
138
139
140
141int
142xfs_alloc_pagf_init(
143 struct xfs_mount *mp,
144 struct xfs_trans *tp,
145 xfs_agnumber_t agno,
146 int flags);
147
148
149
150
151int
152xfs_alloc_put_freelist(
153 struct xfs_trans *tp,
154 struct xfs_buf *agbp,
155 struct xfs_buf *agflbp,
156 xfs_agblock_t bno,
157 int btreeblk);
158
159
160
161
162int
163xfs_alloc_read_agf(
164 struct xfs_mount *mp,
165 struct xfs_trans *tp,
166 xfs_agnumber_t agno,
167 int flags,
168 struct xfs_buf **bpp);
169
170
171
172
173int
174xfs_alloc_vextent(
175 xfs_alloc_arg_t *args);
176
177
178
179
180int
181__xfs_free_extent(
182 struct xfs_trans *tp,
183 xfs_fsblock_t bno,
184 xfs_extlen_t len,
185 struct xfs_owner_info *oinfo,
186 enum xfs_ag_resv_type type,
187 bool skip_discard);
188
189static inline int
190xfs_free_extent(
191 struct xfs_trans *tp,
192 xfs_fsblock_t bno,
193 xfs_extlen_t len,
194 struct xfs_owner_info *oinfo,
195 enum xfs_ag_resv_type type)
196{
197 return __xfs_free_extent(tp, bno, len, oinfo, type, false);
198}
199
200int
201xfs_alloc_lookup_le(
202 struct xfs_btree_cur *cur,
203 xfs_agblock_t bno,
204 xfs_extlen_t len,
205 int *stat);
206
207int
208xfs_alloc_lookup_ge(
209 struct xfs_btree_cur *cur,
210 xfs_agblock_t bno,
211 xfs_extlen_t len,
212 int *stat);
213
214int
215xfs_alloc_get_rec(
216 struct xfs_btree_cur *cur,
217 xfs_agblock_t *bno,
218 xfs_extlen_t *len,
219 int *stat);
220
221int xfs_read_agf(struct xfs_mount *mp, struct xfs_trans *tp,
222 xfs_agnumber_t agno, int flags, struct xfs_buf **bpp);
223int xfs_alloc_read_agfl(struct xfs_mount *mp, struct xfs_trans *tp,
224 xfs_agnumber_t agno, struct xfs_buf **bpp);
225int xfs_free_agfl_block(struct xfs_trans *, xfs_agnumber_t, xfs_agblock_t,
226 struct xfs_buf *, struct xfs_owner_info *);
227int xfs_alloc_fix_freelist(struct xfs_alloc_arg *args, int flags);
228int xfs_free_extent_fix_freelist(struct xfs_trans *tp, xfs_agnumber_t agno,
229 struct xfs_buf **agbp);
230
231xfs_extlen_t xfs_prealloc_blocks(struct xfs_mount *mp);
232
233typedef int (*xfs_alloc_query_range_fn)(
234 struct xfs_btree_cur *cur,
235 struct xfs_alloc_rec_incore *rec,
236 void *priv);
237
238int xfs_alloc_query_range(struct xfs_btree_cur *cur,
239 struct xfs_alloc_rec_incore *low_rec,
240 struct xfs_alloc_rec_incore *high_rec,
241 xfs_alloc_query_range_fn fn, void *priv);
242int xfs_alloc_query_all(struct xfs_btree_cur *cur, xfs_alloc_query_range_fn fn,
243 void *priv);
244
245int xfs_alloc_has_record(struct xfs_btree_cur *cur, xfs_agblock_t bno,
246 xfs_extlen_t len, bool *exist);
247
248typedef int (*xfs_agfl_walk_fn)(struct xfs_mount *mp, xfs_agblock_t bno,
249 void *priv);
250int xfs_agfl_walk(struct xfs_mount *mp, struct xfs_agf *agf,
251 struct xfs_buf *agflbp, xfs_agfl_walk_fn walk_fn, void *priv);
252
253#endif
254