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 xfs_fsblock_t fsbno;
58 xfs_agnumber_t agno;
59 xfs_agblock_t agbno;
60 xfs_extlen_t minlen;
61 xfs_extlen_t maxlen;
62 xfs_extlen_t mod;
63 xfs_extlen_t prod;
64 xfs_extlen_t minleft;
65 xfs_extlen_t total;
66 xfs_extlen_t alignment;
67 xfs_extlen_t minalignslop;
68 xfs_agblock_t min_agbno;
69 xfs_agblock_t max_agbno;
70 xfs_extlen_t len;
71 xfs_alloctype_t type;
72 xfs_alloctype_t otype;
73 int datatype;
74 char wasdel;
75 char wasfromfl;
76 struct xfs_owner_info oinfo;
77 enum xfs_ag_resv_type resv;
78} xfs_alloc_arg_t;
79
80
81
82
83#define XFS_ALLOC_USERDATA (1 << 0)
84#define XFS_ALLOC_INITIAL_USER_DATA (1 << 1)
85#define XFS_ALLOC_NOBUSY (1 << 2)
86
87
88#define XFS_ALLOC_AGFL_RESERVE 4
89unsigned int xfs_alloc_set_aside(struct xfs_mount *mp);
90unsigned int xfs_alloc_ag_max_usable(struct xfs_mount *mp);
91
92xfs_extlen_t xfs_alloc_longest_free_extent(struct xfs_perag *pag,
93 xfs_extlen_t need, xfs_extlen_t reserved);
94unsigned int xfs_alloc_min_freelist(struct xfs_mount *mp,
95 struct xfs_perag *pag);
96
97
98
99
100void
101xfs_alloc_compute_maxlevels(
102 struct xfs_mount *mp);
103
104
105
106
107
108int
109xfs_alloc_get_freelist(
110 struct xfs_trans *tp,
111 struct xfs_buf *agbp,
112 xfs_agblock_t *bnop,
113 int btreeblk);
114
115
116
117
118void
119xfs_alloc_log_agf(
120 struct xfs_trans *tp,
121 struct xfs_buf *bp,
122 int fields);
123
124
125
126
127int
128xfs_alloc_pagf_init(
129 struct xfs_mount *mp,
130 struct xfs_trans *tp,
131 xfs_agnumber_t agno,
132 int flags);
133
134
135
136
137int
138xfs_alloc_put_freelist(
139 struct xfs_trans *tp,
140 struct xfs_buf *agbp,
141 struct xfs_buf *agflbp,
142 xfs_agblock_t bno,
143 int btreeblk);
144
145
146
147
148int
149xfs_alloc_read_agf(
150 struct xfs_mount *mp,
151 struct xfs_trans *tp,
152 xfs_agnumber_t agno,
153 int flags,
154 struct xfs_buf **bpp);
155
156
157
158
159int
160xfs_alloc_vextent(
161 xfs_alloc_arg_t *args);
162
163
164
165
166int
167__xfs_free_extent(
168 struct xfs_trans *tp,
169 xfs_fsblock_t bno,
170 xfs_extlen_t len,
171 const struct xfs_owner_info *oinfo,
172 enum xfs_ag_resv_type type,
173 bool skip_discard);
174
175static inline int
176xfs_free_extent(
177 struct xfs_trans *tp,
178 xfs_fsblock_t bno,
179 xfs_extlen_t len,
180 const struct xfs_owner_info *oinfo,
181 enum xfs_ag_resv_type type)
182{
183 return __xfs_free_extent(tp, bno, len, oinfo, type, false);
184}
185
186int
187xfs_alloc_lookup_le(
188 struct xfs_btree_cur *cur,
189 xfs_agblock_t bno,
190 xfs_extlen_t len,
191 int *stat);
192
193int
194xfs_alloc_lookup_ge(
195 struct xfs_btree_cur *cur,
196 xfs_agblock_t bno,
197 xfs_extlen_t len,
198 int *stat);
199
200int
201xfs_alloc_get_rec(
202 struct xfs_btree_cur *cur,
203 xfs_agblock_t *bno,
204 xfs_extlen_t *len,
205 int *stat);
206
207int xfs_read_agf(struct xfs_mount *mp, struct xfs_trans *tp,
208 xfs_agnumber_t agno, int flags, struct xfs_buf **bpp);
209int xfs_alloc_read_agfl(struct xfs_mount *mp, struct xfs_trans *tp,
210 xfs_agnumber_t agno, struct xfs_buf **bpp);
211int xfs_free_agfl_block(struct xfs_trans *, xfs_agnumber_t, xfs_agblock_t,
212 struct xfs_buf *, struct xfs_owner_info *);
213int xfs_alloc_fix_freelist(struct xfs_alloc_arg *args, int flags);
214int xfs_free_extent_fix_freelist(struct xfs_trans *tp, xfs_agnumber_t agno,
215 struct xfs_buf **agbp);
216
217xfs_extlen_t xfs_prealloc_blocks(struct xfs_mount *mp);
218
219typedef int (*xfs_alloc_query_range_fn)(
220 struct xfs_btree_cur *cur,
221 struct xfs_alloc_rec_incore *rec,
222 void *priv);
223
224int xfs_alloc_query_range(struct xfs_btree_cur *cur,
225 struct xfs_alloc_rec_incore *low_rec,
226 struct xfs_alloc_rec_incore *high_rec,
227 xfs_alloc_query_range_fn fn, void *priv);
228int xfs_alloc_query_all(struct xfs_btree_cur *cur, xfs_alloc_query_range_fn fn,
229 void *priv);
230
231int xfs_alloc_has_record(struct xfs_btree_cur *cur, xfs_agblock_t bno,
232 xfs_extlen_t len, bool *exist);
233
234typedef int (*xfs_agfl_walk_fn)(struct xfs_mount *mp, xfs_agblock_t bno,
235 void *priv);
236int xfs_agfl_walk(struct xfs_mount *mp, struct xfs_agf *agf,
237 struct xfs_buf *agflbp, xfs_agfl_walk_fn walk_fn, void *priv);
238
239static inline __be32 *
240xfs_buf_to_agfl_bno(
241 struct xfs_buf *bp)
242{
243 if (xfs_sb_version_hascrc(&bp->b_mount->m_sb))
244 return bp->b_addr + sizeof(struct xfs_agfl);
245 return bp->b_addr;
246}
247
248#endif
249