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