Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
7b718769 NS |
2 | * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
1da177e4 | 4 | * |
7b718769 NS |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as | |
1da177e4 LT |
7 | * published by the Free Software Foundation. |
8 | * | |
7b718769 NS |
9 | * This program is distributed in the hope that it would be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
1da177e4 | 13 | * |
7b718769 NS |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write the Free Software Foundation, | |
16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
1da177e4 | 17 | */ |
1da177e4 | 18 | #include "xfs.h" |
a844f451 | 19 | #include "xfs_fs.h" |
1da177e4 | 20 | #include "xfs_types.h" |
a844f451 | 21 | #include "xfs_bit.h" |
1da177e4 | 22 | #include "xfs_log.h" |
a844f451 | 23 | #include "xfs_inum.h" |
1da177e4 LT |
24 | #include "xfs_trans.h" |
25 | #include "xfs_sb.h" | |
26 | #include "xfs_ag.h" | |
1da177e4 LT |
27 | #include "xfs_dir2.h" |
28 | #include "xfs_dmapi.h" | |
29 | #include "xfs_mount.h" | |
1da177e4 | 30 | #include "xfs_bmap_btree.h" |
a844f451 | 31 | #include "xfs_alloc_btree.h" |
1da177e4 | 32 | #include "xfs_ialloc_btree.h" |
1da177e4 | 33 | #include "xfs_dir2_sf.h" |
a844f451 | 34 | #include "xfs_attr_sf.h" |
1da177e4 LT |
35 | #include "xfs_dinode.h" |
36 | #include "xfs_inode.h" | |
a844f451 NS |
37 | #include "xfs_btree.h" |
38 | #include "xfs_ialloc.h" | |
1da177e4 | 39 | #include "xfs_alloc.h" |
1da177e4 LT |
40 | #include "xfs_rtalloc.h" |
41 | #include "xfs_error.h" | |
42 | #include "xfs_bmap.h" | |
43 | ||
44 | /* | |
45 | * Log specified fields for the inode given by bp and off. | |
46 | */ | |
47 | STATIC void | |
48 | xfs_ialloc_log_di( | |
49 | xfs_trans_t *tp, /* transaction pointer */ | |
50 | xfs_buf_t *bp, /* inode buffer */ | |
51 | int off, /* index of inode in buffer */ | |
52 | int fields) /* bitmask of fields to log */ | |
53 | { | |
54 | int first; /* first byte number */ | |
55 | int ioffset; /* off in bytes */ | |
56 | int last; /* last byte number */ | |
57 | xfs_mount_t *mp; /* mount point structure */ | |
58 | static const short offsets[] = { /* field offsets */ | |
59 | /* keep in sync with bits */ | |
60 | offsetof(xfs_dinode_core_t, di_magic), | |
61 | offsetof(xfs_dinode_core_t, di_mode), | |
62 | offsetof(xfs_dinode_core_t, di_version), | |
63 | offsetof(xfs_dinode_core_t, di_format), | |
64 | offsetof(xfs_dinode_core_t, di_onlink), | |
65 | offsetof(xfs_dinode_core_t, di_uid), | |
66 | offsetof(xfs_dinode_core_t, di_gid), | |
67 | offsetof(xfs_dinode_core_t, di_nlink), | |
68 | offsetof(xfs_dinode_core_t, di_projid), | |
69 | offsetof(xfs_dinode_core_t, di_pad), | |
70 | offsetof(xfs_dinode_core_t, di_atime), | |
71 | offsetof(xfs_dinode_core_t, di_mtime), | |
72 | offsetof(xfs_dinode_core_t, di_ctime), | |
73 | offsetof(xfs_dinode_core_t, di_size), | |
74 | offsetof(xfs_dinode_core_t, di_nblocks), | |
75 | offsetof(xfs_dinode_core_t, di_extsize), | |
76 | offsetof(xfs_dinode_core_t, di_nextents), | |
77 | offsetof(xfs_dinode_core_t, di_anextents), | |
78 | offsetof(xfs_dinode_core_t, di_forkoff), | |
79 | offsetof(xfs_dinode_core_t, di_aformat), | |
80 | offsetof(xfs_dinode_core_t, di_dmevmask), | |
81 | offsetof(xfs_dinode_core_t, di_dmstate), | |
82 | offsetof(xfs_dinode_core_t, di_flags), | |
83 | offsetof(xfs_dinode_core_t, di_gen), | |
84 | offsetof(xfs_dinode_t, di_next_unlinked), | |
85 | offsetof(xfs_dinode_t, di_u), | |
86 | offsetof(xfs_dinode_t, di_a), | |
87 | sizeof(xfs_dinode_t) | |
88 | }; | |
89 | ||
90 | ||
91 | ASSERT(offsetof(xfs_dinode_t, di_core) == 0); | |
92 | ASSERT((fields & (XFS_DI_U|XFS_DI_A)) == 0); | |
93 | mp = tp->t_mountp; | |
94 | /* | |
95 | * Get the inode-relative first and last bytes for these fields | |
96 | */ | |
97 | xfs_btree_offsets(fields, offsets, XFS_DI_NUM_BITS, &first, &last); | |
98 | /* | |
99 | * Convert to buffer offsets and log it. | |
100 | */ | |
101 | ioffset = off << mp->m_sb.sb_inodelog; | |
102 | first += ioffset; | |
103 | last += ioffset; | |
104 | xfs_trans_log_buf(tp, bp, first, last); | |
105 | } | |
106 | ||
107 | /* | |
108 | * Allocation group level functions. | |
109 | */ | |
75de2a91 DC |
110 | static inline int |
111 | xfs_ialloc_cluster_alignment( | |
112 | xfs_alloc_arg_t *args) | |
113 | { | |
114 | if (xfs_sb_version_hasalign(&args->mp->m_sb) && | |
115 | args->mp->m_sb.sb_inoalignmt >= | |
116 | XFS_B_TO_FSBT(args->mp, XFS_INODE_CLUSTER_SIZE(args->mp))) | |
117 | return args->mp->m_sb.sb_inoalignmt; | |
118 | return 1; | |
119 | } | |
1da177e4 LT |
120 | |
121 | /* | |
122 | * Allocate new inodes in the allocation group specified by agbp. | |
123 | * Return 0 for success, else error code. | |
124 | */ | |
125 | STATIC int /* error code or 0 */ | |
126 | xfs_ialloc_ag_alloc( | |
127 | xfs_trans_t *tp, /* transaction pointer */ | |
128 | xfs_buf_t *agbp, /* alloc group buffer */ | |
129 | int *alloc) | |
130 | { | |
131 | xfs_agi_t *agi; /* allocation group header */ | |
132 | xfs_alloc_arg_t args; /* allocation argument structure */ | |
133 | int blks_per_cluster; /* fs blocks per inode cluster */ | |
134 | xfs_btree_cur_t *cur; /* inode btree cursor */ | |
135 | xfs_daddr_t d; /* disk addr of buffer */ | |
92821e2b | 136 | xfs_agnumber_t agno; |
1da177e4 LT |
137 | int error; |
138 | xfs_buf_t *fbuf; /* new free inodes' buffer */ | |
139 | xfs_dinode_t *free; /* new free inode structure */ | |
140 | int i; /* inode counter */ | |
141 | int j; /* block counter */ | |
142 | int nbufs; /* num bufs of new inodes */ | |
143 | xfs_agino_t newino; /* new first inode's number */ | |
144 | xfs_agino_t newlen; /* new number of inodes */ | |
145 | int ninodes; /* num inodes per buf */ | |
146 | xfs_agino_t thisino; /* current inode number, for loop */ | |
147 | int version; /* inode version number to use */ | |
3ccb8b5f | 148 | int isaligned = 0; /* inode allocation at stripe unit */ |
1da177e4 | 149 | /* boundary */ |
359346a9 | 150 | unsigned int gen; |
1da177e4 LT |
151 | |
152 | args.tp = tp; | |
153 | args.mp = tp->t_mountp; | |
154 | ||
155 | /* | |
156 | * Locking will ensure that we don't have two callers in here | |
157 | * at one time. | |
158 | */ | |
159 | newlen = XFS_IALLOC_INODES(args.mp); | |
160 | if (args.mp->m_maxicount && | |
161 | args.mp->m_sb.sb_icount + newlen > args.mp->m_maxicount) | |
162 | return XFS_ERROR(ENOSPC); | |
163 | args.minlen = args.maxlen = XFS_IALLOC_BLOCKS(args.mp); | |
164 | /* | |
3ccb8b5f GO |
165 | * First try to allocate inodes contiguous with the last-allocated |
166 | * chunk of inodes. If the filesystem is striped, this will fill | |
167 | * an entire stripe unit with inodes. | |
168 | */ | |
1da177e4 | 169 | agi = XFS_BUF_TO_AGI(agbp); |
3ccb8b5f | 170 | newino = be32_to_cpu(agi->agi_newino); |
019ff2d5 NS |
171 | args.agbno = XFS_AGINO_TO_AGBNO(args.mp, newino) + |
172 | XFS_IALLOC_BLOCKS(args.mp); | |
173 | if (likely(newino != NULLAGINO && | |
174 | (args.agbno < be32_to_cpu(agi->agi_length)))) { | |
3ccb8b5f GO |
175 | args.fsbno = XFS_AGB_TO_FSB(args.mp, |
176 | be32_to_cpu(agi->agi_seqno), args.agbno); | |
177 | args.type = XFS_ALLOCTYPE_THIS_BNO; | |
178 | args.mod = args.total = args.wasdel = args.isfl = | |
179 | args.userdata = args.minalignslop = 0; | |
180 | args.prod = 1; | |
75de2a91 | 181 | |
3ccb8b5f | 182 | /* |
75de2a91 DC |
183 | * We need to take into account alignment here to ensure that |
184 | * we don't modify the free list if we fail to have an exact | |
185 | * block. If we don't have an exact match, and every oher | |
186 | * attempt allocation attempt fails, we'll end up cancelling | |
187 | * a dirty transaction and shutting down. | |
188 | * | |
189 | * For an exact allocation, alignment must be 1, | |
190 | * however we need to take cluster alignment into account when | |
191 | * fixing up the freelist. Use the minalignslop field to | |
192 | * indicate that extra blocks might be required for alignment, | |
193 | * but not to use them in the actual exact allocation. | |
3ccb8b5f | 194 | */ |
75de2a91 DC |
195 | args.alignment = 1; |
196 | args.minalignslop = xfs_ialloc_cluster_alignment(&args) - 1; | |
197 | ||
198 | /* Allow space for the inode btree to split. */ | |
3ccb8b5f GO |
199 | args.minleft = XFS_IN_MAXLEVELS(args.mp) - 1; |
200 | if ((error = xfs_alloc_vextent(&args))) | |
201 | return error; | |
202 | } else | |
203 | args.fsbno = NULLFSBLOCK; | |
1da177e4 | 204 | |
3ccb8b5f GO |
205 | if (unlikely(args.fsbno == NULLFSBLOCK)) { |
206 | /* | |
207 | * Set the alignment for the allocation. | |
208 | * If stripe alignment is turned on then align at stripe unit | |
209 | * boundary. | |
019ff2d5 NS |
210 | * If the cluster size is smaller than a filesystem block |
211 | * then we're doing I/O for inodes in filesystem block size | |
3ccb8b5f GO |
212 | * pieces, so don't need alignment anyway. |
213 | */ | |
214 | isaligned = 0; | |
215 | if (args.mp->m_sinoalign) { | |
216 | ASSERT(!(args.mp->m_flags & XFS_MOUNT_NOALIGN)); | |
217 | args.alignment = args.mp->m_dalign; | |
218 | isaligned = 1; | |
75de2a91 DC |
219 | } else |
220 | args.alignment = xfs_ialloc_cluster_alignment(&args); | |
3ccb8b5f GO |
221 | /* |
222 | * Need to figure out where to allocate the inode blocks. | |
223 | * Ideally they should be spaced out through the a.g. | |
224 | * For now, just allocate blocks up front. | |
225 | */ | |
226 | args.agbno = be32_to_cpu(agi->agi_root); | |
227 | args.fsbno = XFS_AGB_TO_FSB(args.mp, | |
228 | be32_to_cpu(agi->agi_seqno), args.agbno); | |
229 | /* | |
230 | * Allocate a fixed-size extent of inodes. | |
231 | */ | |
232 | args.type = XFS_ALLOCTYPE_NEAR_BNO; | |
233 | args.mod = args.total = args.wasdel = args.isfl = | |
234 | args.userdata = args.minalignslop = 0; | |
235 | args.prod = 1; | |
236 | /* | |
237 | * Allow space for the inode btree to split. | |
238 | */ | |
239 | args.minleft = XFS_IN_MAXLEVELS(args.mp) - 1; | |
240 | if ((error = xfs_alloc_vextent(&args))) | |
241 | return error; | |
242 | } | |
019ff2d5 | 243 | |
1da177e4 LT |
244 | /* |
245 | * If stripe alignment is turned on, then try again with cluster | |
246 | * alignment. | |
247 | */ | |
248 | if (isaligned && args.fsbno == NULLFSBLOCK) { | |
249 | args.type = XFS_ALLOCTYPE_NEAR_BNO; | |
16259e7d | 250 | args.agbno = be32_to_cpu(agi->agi_root); |
1da177e4 | 251 | args.fsbno = XFS_AGB_TO_FSB(args.mp, |
16259e7d | 252 | be32_to_cpu(agi->agi_seqno), args.agbno); |
75de2a91 | 253 | args.alignment = xfs_ialloc_cluster_alignment(&args); |
1da177e4 LT |
254 | if ((error = xfs_alloc_vextent(&args))) |
255 | return error; | |
256 | } | |
257 | ||
258 | if (args.fsbno == NULLFSBLOCK) { | |
259 | *alloc = 0; | |
260 | return 0; | |
261 | } | |
262 | ASSERT(args.len == args.minlen); | |
263 | /* | |
264 | * Convert the results. | |
265 | */ | |
266 | newino = XFS_OFFBNO_TO_AGINO(args.mp, args.agbno, 0); | |
267 | /* | |
268 | * Loop over the new block(s), filling in the inodes. | |
269 | * For small block sizes, manipulate the inodes in buffers | |
270 | * which are multiples of the blocks size. | |
271 | */ | |
272 | if (args.mp->m_sb.sb_blocksize >= XFS_INODE_CLUSTER_SIZE(args.mp)) { | |
273 | blks_per_cluster = 1; | |
274 | nbufs = (int)args.len; | |
275 | ninodes = args.mp->m_sb.sb_inopblock; | |
276 | } else { | |
277 | blks_per_cluster = XFS_INODE_CLUSTER_SIZE(args.mp) / | |
278 | args.mp->m_sb.sb_blocksize; | |
279 | nbufs = (int)args.len / blks_per_cluster; | |
280 | ninodes = blks_per_cluster * args.mp->m_sb.sb_inopblock; | |
281 | } | |
282 | /* | |
283 | * Figure out what version number to use in the inodes we create. | |
284 | * If the superblock version has caught up to the one that supports | |
285 | * the new inode format, then use the new inode version. Otherwise | |
286 | * use the old version so that old kernels will continue to be | |
287 | * able to use the file system. | |
288 | */ | |
62118709 | 289 | if (xfs_sb_version_hasnlink(&args.mp->m_sb)) |
1da177e4 LT |
290 | version = XFS_DINODE_VERSION_2; |
291 | else | |
292 | version = XFS_DINODE_VERSION_1; | |
293 | ||
359346a9 DC |
294 | /* |
295 | * Seed the new inode cluster with a random generation number. This | |
296 | * prevents short-term reuse of generation numbers if a chunk is | |
297 | * freed and then immediately reallocated. We use random numbers | |
298 | * rather than a linear progression to prevent the next generation | |
299 | * number from being easily guessable. | |
300 | */ | |
301 | gen = random32(); | |
1da177e4 LT |
302 | for (j = 0; j < nbufs; j++) { |
303 | /* | |
304 | * Get the block. | |
305 | */ | |
16259e7d | 306 | d = XFS_AGB_TO_DADDR(args.mp, be32_to_cpu(agi->agi_seqno), |
1da177e4 LT |
307 | args.agbno + (j * blks_per_cluster)); |
308 | fbuf = xfs_trans_get_buf(tp, args.mp->m_ddev_targp, d, | |
309 | args.mp->m_bsize * blks_per_cluster, | |
310 | XFS_BUF_LOCK); | |
311 | ASSERT(fbuf); | |
312 | ASSERT(!XFS_BUF_GETERROR(fbuf)); | |
313 | /* | |
f30a1211 | 314 | * Set initial values for the inodes in this buffer. |
1da177e4 | 315 | */ |
f30a1211 | 316 | xfs_biozero(fbuf, 0, ninodes << args.mp->m_sb.sb_inodelog); |
1da177e4 LT |
317 | for (i = 0; i < ninodes; i++) { |
318 | free = XFS_MAKE_IPTR(args.mp, fbuf, i); | |
347d1c01 CH |
319 | free->di_core.di_magic = cpu_to_be16(XFS_DINODE_MAGIC); |
320 | free->di_core.di_version = version; | |
359346a9 | 321 | free->di_core.di_gen = cpu_to_be32(gen); |
347d1c01 | 322 | free->di_next_unlinked = cpu_to_be32(NULLAGINO); |
1da177e4 LT |
323 | xfs_ialloc_log_di(tp, fbuf, i, |
324 | XFS_DI_CORE_BITS | XFS_DI_NEXT_UNLINKED); | |
325 | } | |
326 | xfs_trans_inode_alloc_buf(tp, fbuf); | |
327 | } | |
413d57c9 MS |
328 | be32_add_cpu(&agi->agi_count, newlen); |
329 | be32_add_cpu(&agi->agi_freecount, newlen); | |
92821e2b | 330 | agno = be32_to_cpu(agi->agi_seqno); |
1da177e4 | 331 | down_read(&args.mp->m_peraglock); |
92821e2b | 332 | args.mp->m_perag[agno].pagi_freecount += newlen; |
1da177e4 | 333 | up_read(&args.mp->m_peraglock); |
16259e7d | 334 | agi->agi_newino = cpu_to_be32(newino); |
1da177e4 LT |
335 | /* |
336 | * Insert records describing the new inode chunk into the btree. | |
337 | */ | |
561f7d17 | 338 | cur = xfs_inobt_init_cursor(args.mp, tp, agbp, agno); |
1da177e4 LT |
339 | for (thisino = newino; |
340 | thisino < newino + newlen; | |
341 | thisino += XFS_INODES_PER_CHUNK) { | |
342 | if ((error = xfs_inobt_lookup_eq(cur, thisino, | |
343 | XFS_INODES_PER_CHUNK, XFS_INOBT_ALL_FREE, &i))) { | |
344 | xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); | |
345 | return error; | |
346 | } | |
347 | ASSERT(i == 0); | |
348 | if ((error = xfs_inobt_insert(cur, &i))) { | |
349 | xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); | |
350 | return error; | |
351 | } | |
352 | ASSERT(i == 1); | |
353 | } | |
354 | xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); | |
355 | /* | |
356 | * Log allocation group header fields | |
357 | */ | |
358 | xfs_ialloc_log_agi(tp, agbp, | |
359 | XFS_AGI_COUNT | XFS_AGI_FREECOUNT | XFS_AGI_NEWINO); | |
360 | /* | |
361 | * Modify/log superblock values for inode count and inode free count. | |
362 | */ | |
363 | xfs_trans_mod_sb(tp, XFS_TRANS_SB_ICOUNT, (long)newlen); | |
364 | xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, (long)newlen); | |
365 | *alloc = 1; | |
366 | return 0; | |
367 | } | |
368 | ||
7989cb8e | 369 | STATIC_INLINE xfs_agnumber_t |
1da177e4 LT |
370 | xfs_ialloc_next_ag( |
371 | xfs_mount_t *mp) | |
372 | { | |
373 | xfs_agnumber_t agno; | |
374 | ||
375 | spin_lock(&mp->m_agirotor_lock); | |
376 | agno = mp->m_agirotor; | |
377 | if (++mp->m_agirotor == mp->m_maxagi) | |
378 | mp->m_agirotor = 0; | |
379 | spin_unlock(&mp->m_agirotor_lock); | |
380 | ||
381 | return agno; | |
382 | } | |
383 | ||
384 | /* | |
385 | * Select an allocation group to look for a free inode in, based on the parent | |
386 | * inode and then mode. Return the allocation group buffer. | |
387 | */ | |
388 | STATIC xfs_buf_t * /* allocation group buffer */ | |
389 | xfs_ialloc_ag_select( | |
390 | xfs_trans_t *tp, /* transaction pointer */ | |
391 | xfs_ino_t parent, /* parent directory inode number */ | |
392 | mode_t mode, /* bits set to indicate file type */ | |
393 | int okalloc) /* ok to allocate more space */ | |
394 | { | |
395 | xfs_buf_t *agbp; /* allocation group header buffer */ | |
396 | xfs_agnumber_t agcount; /* number of ag's in the filesystem */ | |
397 | xfs_agnumber_t agno; /* current ag number */ | |
398 | int flags; /* alloc buffer locking flags */ | |
399 | xfs_extlen_t ineed; /* blocks needed for inode allocation */ | |
400 | xfs_extlen_t longest = 0; /* longest extent available */ | |
401 | xfs_mount_t *mp; /* mount point structure */ | |
402 | int needspace; /* file mode implies space allocated */ | |
403 | xfs_perag_t *pag; /* per allocation group data */ | |
404 | xfs_agnumber_t pagno; /* parent (starting) ag number */ | |
405 | ||
406 | /* | |
407 | * Files of these types need at least one block if length > 0 | |
408 | * (and they won't fit in the inode, but that's hard to figure out). | |
409 | */ | |
410 | needspace = S_ISDIR(mode) || S_ISREG(mode) || S_ISLNK(mode); | |
411 | mp = tp->t_mountp; | |
412 | agcount = mp->m_maxagi; | |
413 | if (S_ISDIR(mode)) | |
414 | pagno = xfs_ialloc_next_ag(mp); | |
415 | else { | |
416 | pagno = XFS_INO_TO_AGNO(mp, parent); | |
417 | if (pagno >= agcount) | |
418 | pagno = 0; | |
419 | } | |
420 | ASSERT(pagno < agcount); | |
421 | /* | |
422 | * Loop through allocation groups, looking for one with a little | |
423 | * free space in it. Note we don't look for free inodes, exactly. | |
424 | * Instead, we include whether there is a need to allocate inodes | |
425 | * to mean that blocks must be allocated for them, | |
426 | * if none are currently free. | |
427 | */ | |
428 | agno = pagno; | |
429 | flags = XFS_ALLOC_FLAG_TRYLOCK; | |
430 | down_read(&mp->m_peraglock); | |
431 | for (;;) { | |
432 | pag = &mp->m_perag[agno]; | |
433 | if (!pag->pagi_init) { | |
434 | if (xfs_ialloc_read_agi(mp, tp, agno, &agbp)) { | |
435 | agbp = NULL; | |
436 | goto nextag; | |
437 | } | |
438 | } else | |
439 | agbp = NULL; | |
440 | ||
441 | if (!pag->pagi_inodeok) { | |
442 | xfs_ialloc_next_ag(mp); | |
443 | goto unlock_nextag; | |
444 | } | |
445 | ||
446 | /* | |
447 | * Is there enough free space for the file plus a block | |
448 | * of inodes (if we need to allocate some)? | |
449 | */ | |
450 | ineed = pag->pagi_freecount ? 0 : XFS_IALLOC_BLOCKS(mp); | |
451 | if (ineed && !pag->pagf_init) { | |
452 | if (agbp == NULL && | |
453 | xfs_ialloc_read_agi(mp, tp, agno, &agbp)) { | |
454 | agbp = NULL; | |
455 | goto nextag; | |
456 | } | |
457 | (void)xfs_alloc_pagf_init(mp, tp, agno, flags); | |
458 | } | |
459 | if (!ineed || pag->pagf_init) { | |
460 | if (ineed && !(longest = pag->pagf_longest)) | |
461 | longest = pag->pagf_flcount > 0; | |
462 | if (!ineed || | |
463 | (pag->pagf_freeblks >= needspace + ineed && | |
464 | longest >= ineed && | |
465 | okalloc)) { | |
466 | if (agbp == NULL && | |
467 | xfs_ialloc_read_agi(mp, tp, agno, &agbp)) { | |
468 | agbp = NULL; | |
469 | goto nextag; | |
470 | } | |
471 | up_read(&mp->m_peraglock); | |
472 | return agbp; | |
473 | } | |
474 | } | |
475 | unlock_nextag: | |
476 | if (agbp) | |
477 | xfs_trans_brelse(tp, agbp); | |
478 | nextag: | |
479 | /* | |
480 | * No point in iterating over the rest, if we're shutting | |
481 | * down. | |
482 | */ | |
483 | if (XFS_FORCED_SHUTDOWN(mp)) { | |
484 | up_read(&mp->m_peraglock); | |
1121b219 | 485 | return NULL; |
1da177e4 LT |
486 | } |
487 | agno++; | |
488 | if (agno >= agcount) | |
489 | agno = 0; | |
490 | if (agno == pagno) { | |
491 | if (flags == 0) { | |
492 | up_read(&mp->m_peraglock); | |
1121b219 | 493 | return NULL; |
1da177e4 LT |
494 | } |
495 | flags = 0; | |
496 | } | |
497 | } | |
498 | } | |
499 | ||
500 | /* | |
501 | * Visible inode allocation functions. | |
502 | */ | |
503 | ||
504 | /* | |
505 | * Allocate an inode on disk. | |
506 | * Mode is used to tell whether the new inode will need space, and whether | |
507 | * it is a directory. | |
508 | * | |
509 | * The arguments IO_agbp and alloc_done are defined to work within | |
510 | * the constraint of one allocation per transaction. | |
511 | * xfs_dialloc() is designed to be called twice if it has to do an | |
512 | * allocation to make more free inodes. On the first call, | |
513 | * IO_agbp should be set to NULL. If an inode is available, | |
514 | * i.e., xfs_dialloc() did not need to do an allocation, an inode | |
515 | * number is returned. In this case, IO_agbp would be set to the | |
516 | * current ag_buf and alloc_done set to false. | |
517 | * If an allocation needed to be done, xfs_dialloc would return | |
518 | * the current ag_buf in IO_agbp and set alloc_done to true. | |
519 | * The caller should then commit the current transaction, allocate a new | |
520 | * transaction, and call xfs_dialloc() again, passing in the previous | |
521 | * value of IO_agbp. IO_agbp should be held across the transactions. | |
522 | * Since the agbp is locked across the two calls, the second call is | |
523 | * guaranteed to have a free inode available. | |
524 | * | |
525 | * Once we successfully pick an inode its number is returned and the | |
526 | * on-disk data structures are updated. The inode itself is not read | |
527 | * in, since doing so would break ordering constraints with xfs_reclaim. | |
528 | */ | |
529 | int | |
530 | xfs_dialloc( | |
531 | xfs_trans_t *tp, /* transaction pointer */ | |
532 | xfs_ino_t parent, /* parent inode (directory) */ | |
533 | mode_t mode, /* mode bits for new inode */ | |
534 | int okalloc, /* ok to allocate more space */ | |
535 | xfs_buf_t **IO_agbp, /* in/out ag header's buffer */ | |
536 | boolean_t *alloc_done, /* true if we needed to replenish | |
537 | inode freelist */ | |
538 | xfs_ino_t *inop) /* inode number allocated */ | |
539 | { | |
540 | xfs_agnumber_t agcount; /* number of allocation groups */ | |
541 | xfs_buf_t *agbp; /* allocation group header's buffer */ | |
542 | xfs_agnumber_t agno; /* allocation group number */ | |
543 | xfs_agi_t *agi; /* allocation group header structure */ | |
544 | xfs_btree_cur_t *cur; /* inode allocation btree cursor */ | |
545 | int error; /* error return value */ | |
546 | int i; /* result code */ | |
547 | int ialloced; /* inode allocation status */ | |
548 | int noroom = 0; /* no space for inode blk allocation */ | |
549 | xfs_ino_t ino; /* fs-relative inode to be returned */ | |
550 | /* REFERENCED */ | |
551 | int j; /* result code */ | |
552 | xfs_mount_t *mp; /* file system mount structure */ | |
553 | int offset; /* index of inode in chunk */ | |
554 | xfs_agino_t pagino; /* parent's a.g. relative inode # */ | |
555 | xfs_agnumber_t pagno; /* parent's allocation group number */ | |
61a25848 | 556 | xfs_inobt_rec_incore_t rec; /* inode allocation record */ |
1da177e4 LT |
557 | xfs_agnumber_t tagno; /* testing allocation group number */ |
558 | xfs_btree_cur_t *tcur; /* temp cursor */ | |
61a25848 | 559 | xfs_inobt_rec_incore_t trec; /* temp inode allocation record */ |
1da177e4 LT |
560 | |
561 | ||
562 | if (*IO_agbp == NULL) { | |
563 | /* | |
564 | * We do not have an agbp, so select an initial allocation | |
565 | * group for inode allocation. | |
566 | */ | |
567 | agbp = xfs_ialloc_ag_select(tp, parent, mode, okalloc); | |
568 | /* | |
569 | * Couldn't find an allocation group satisfying the | |
570 | * criteria, give up. | |
571 | */ | |
572 | if (!agbp) { | |
573 | *inop = NULLFSINO; | |
574 | return 0; | |
575 | } | |
576 | agi = XFS_BUF_TO_AGI(agbp); | |
16259e7d | 577 | ASSERT(be32_to_cpu(agi->agi_magicnum) == XFS_AGI_MAGIC); |
1da177e4 LT |
578 | } else { |
579 | /* | |
580 | * Continue where we left off before. In this case, we | |
581 | * know that the allocation group has free inodes. | |
582 | */ | |
583 | agbp = *IO_agbp; | |
584 | agi = XFS_BUF_TO_AGI(agbp); | |
16259e7d CH |
585 | ASSERT(be32_to_cpu(agi->agi_magicnum) == XFS_AGI_MAGIC); |
586 | ASSERT(be32_to_cpu(agi->agi_freecount) > 0); | |
1da177e4 LT |
587 | } |
588 | mp = tp->t_mountp; | |
589 | agcount = mp->m_sb.sb_agcount; | |
16259e7d | 590 | agno = be32_to_cpu(agi->agi_seqno); |
1da177e4 LT |
591 | tagno = agno; |
592 | pagno = XFS_INO_TO_AGNO(mp, parent); | |
593 | pagino = XFS_INO_TO_AGINO(mp, parent); | |
594 | ||
595 | /* | |
596 | * If we have already hit the ceiling of inode blocks then clear | |
597 | * okalloc so we scan all available agi structures for a free | |
598 | * inode. | |
599 | */ | |
600 | ||
601 | if (mp->m_maxicount && | |
602 | mp->m_sb.sb_icount + XFS_IALLOC_INODES(mp) > mp->m_maxicount) { | |
603 | noroom = 1; | |
604 | okalloc = 0; | |
605 | } | |
606 | ||
607 | /* | |
608 | * Loop until we find an allocation group that either has free inodes | |
609 | * or in which we can allocate some inodes. Iterate through the | |
610 | * allocation groups upward, wrapping at the end. | |
611 | */ | |
612 | *alloc_done = B_FALSE; | |
613 | while (!agi->agi_freecount) { | |
614 | /* | |
615 | * Don't do anything if we're not supposed to allocate | |
616 | * any blocks, just go on to the next ag. | |
617 | */ | |
618 | if (okalloc) { | |
619 | /* | |
620 | * Try to allocate some new inodes in the allocation | |
621 | * group. | |
622 | */ | |
623 | if ((error = xfs_ialloc_ag_alloc(tp, agbp, &ialloced))) { | |
624 | xfs_trans_brelse(tp, agbp); | |
625 | if (error == ENOSPC) { | |
626 | *inop = NULLFSINO; | |
627 | return 0; | |
628 | } else | |
629 | return error; | |
630 | } | |
631 | if (ialloced) { | |
632 | /* | |
633 | * We successfully allocated some inodes, return | |
634 | * the current context to the caller so that it | |
635 | * can commit the current transaction and call | |
636 | * us again where we left off. | |
637 | */ | |
16259e7d | 638 | ASSERT(be32_to_cpu(agi->agi_freecount) > 0); |
1da177e4 LT |
639 | *alloc_done = B_TRUE; |
640 | *IO_agbp = agbp; | |
641 | *inop = NULLFSINO; | |
642 | return 0; | |
643 | } | |
644 | } | |
645 | /* | |
646 | * If it failed, give up on this ag. | |
647 | */ | |
648 | xfs_trans_brelse(tp, agbp); | |
649 | /* | |
650 | * Go on to the next ag: get its ag header. | |
651 | */ | |
652 | nextag: | |
653 | if (++tagno == agcount) | |
654 | tagno = 0; | |
655 | if (tagno == agno) { | |
656 | *inop = NULLFSINO; | |
657 | return noroom ? ENOSPC : 0; | |
658 | } | |
659 | down_read(&mp->m_peraglock); | |
660 | if (mp->m_perag[tagno].pagi_inodeok == 0) { | |
661 | up_read(&mp->m_peraglock); | |
662 | goto nextag; | |
663 | } | |
664 | error = xfs_ialloc_read_agi(mp, tp, tagno, &agbp); | |
665 | up_read(&mp->m_peraglock); | |
666 | if (error) | |
667 | goto nextag; | |
668 | agi = XFS_BUF_TO_AGI(agbp); | |
16259e7d | 669 | ASSERT(be32_to_cpu(agi->agi_magicnum) == XFS_AGI_MAGIC); |
1da177e4 LT |
670 | } |
671 | /* | |
672 | * Here with an allocation group that has a free inode. | |
673 | * Reset agno since we may have chosen a new ag in the | |
674 | * loop above. | |
675 | */ | |
676 | agno = tagno; | |
677 | *IO_agbp = NULL; | |
561f7d17 | 678 | cur = xfs_inobt_init_cursor(mp, tp, agbp, be32_to_cpu(agi->agi_seqno)); |
1da177e4 LT |
679 | /* |
680 | * If pagino is 0 (this is the root inode allocation) use newino. | |
681 | * This must work because we've just allocated some. | |
682 | */ | |
683 | if (!pagino) | |
16259e7d | 684 | pagino = be32_to_cpu(agi->agi_newino); |
1da177e4 LT |
685 | #ifdef DEBUG |
686 | if (cur->bc_nlevels == 1) { | |
687 | int freecount = 0; | |
688 | ||
689 | if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i))) | |
690 | goto error0; | |
691 | XFS_WANT_CORRUPTED_GOTO(i == 1, error0); | |
692 | do { | |
693 | if ((error = xfs_inobt_get_rec(cur, &rec.ir_startino, | |
694 | &rec.ir_freecount, &rec.ir_free, &i))) | |
695 | goto error0; | |
696 | XFS_WANT_CORRUPTED_GOTO(i == 1, error0); | |
697 | freecount += rec.ir_freecount; | |
637aa50f | 698 | if ((error = xfs_btree_increment(cur, 0, &i))) |
1da177e4 LT |
699 | goto error0; |
700 | } while (i == 1); | |
701 | ||
16259e7d | 702 | ASSERT(freecount == be32_to_cpu(agi->agi_freecount) || |
1da177e4 LT |
703 | XFS_FORCED_SHUTDOWN(mp)); |
704 | } | |
705 | #endif | |
706 | /* | |
707 | * If in the same a.g. as the parent, try to get near the parent. | |
708 | */ | |
709 | if (pagno == agno) { | |
710 | if ((error = xfs_inobt_lookup_le(cur, pagino, 0, 0, &i))) | |
711 | goto error0; | |
712 | if (i != 0 && | |
713 | (error = xfs_inobt_get_rec(cur, &rec.ir_startino, | |
714 | &rec.ir_freecount, &rec.ir_free, &j)) == 0 && | |
715 | j == 1 && | |
716 | rec.ir_freecount > 0) { | |
717 | /* | |
718 | * Found a free inode in the same chunk | |
719 | * as parent, done. | |
720 | */ | |
721 | } | |
722 | /* | |
723 | * In the same a.g. as parent, but parent's chunk is full. | |
724 | */ | |
725 | else { | |
726 | int doneleft; /* done, to the left */ | |
727 | int doneright; /* done, to the right */ | |
728 | ||
729 | if (error) | |
730 | goto error0; | |
731 | ASSERT(i == 1); | |
732 | ASSERT(j == 1); | |
733 | /* | |
734 | * Duplicate the cursor, search left & right | |
735 | * simultaneously. | |
736 | */ | |
737 | if ((error = xfs_btree_dup_cursor(cur, &tcur))) | |
738 | goto error0; | |
739 | /* | |
740 | * Search left with tcur, back up 1 record. | |
741 | */ | |
742 | if ((error = xfs_inobt_decrement(tcur, 0, &i))) | |
743 | goto error1; | |
744 | doneleft = !i; | |
745 | if (!doneleft) { | |
746 | if ((error = xfs_inobt_get_rec(tcur, | |
747 | &trec.ir_startino, | |
748 | &trec.ir_freecount, | |
749 | &trec.ir_free, &i))) | |
750 | goto error1; | |
751 | XFS_WANT_CORRUPTED_GOTO(i == 1, error1); | |
752 | } | |
753 | /* | |
754 | * Search right with cur, go forward 1 record. | |
755 | */ | |
637aa50f | 756 | if ((error = xfs_btree_increment(cur, 0, &i))) |
1da177e4 LT |
757 | goto error1; |
758 | doneright = !i; | |
759 | if (!doneright) { | |
760 | if ((error = xfs_inobt_get_rec(cur, | |
761 | &rec.ir_startino, | |
762 | &rec.ir_freecount, | |
763 | &rec.ir_free, &i))) | |
764 | goto error1; | |
765 | XFS_WANT_CORRUPTED_GOTO(i == 1, error1); | |
766 | } | |
767 | /* | |
768 | * Loop until we find the closest inode chunk | |
769 | * with a free one. | |
770 | */ | |
771 | while (!doneleft || !doneright) { | |
772 | int useleft; /* using left inode | |
773 | chunk this time */ | |
774 | ||
775 | /* | |
776 | * Figure out which block is closer, | |
777 | * if both are valid. | |
778 | */ | |
779 | if (!doneleft && !doneright) | |
780 | useleft = | |
781 | pagino - | |
782 | (trec.ir_startino + | |
783 | XFS_INODES_PER_CHUNK - 1) < | |
784 | rec.ir_startino - pagino; | |
785 | else | |
786 | useleft = !doneleft; | |
787 | /* | |
788 | * If checking the left, does it have | |
789 | * free inodes? | |
790 | */ | |
791 | if (useleft && trec.ir_freecount) { | |
792 | /* | |
793 | * Yes, set it up as the chunk to use. | |
794 | */ | |
795 | rec = trec; | |
796 | xfs_btree_del_cursor(cur, | |
797 | XFS_BTREE_NOERROR); | |
798 | cur = tcur; | |
799 | break; | |
800 | } | |
801 | /* | |
802 | * If checking the right, does it have | |
803 | * free inodes? | |
804 | */ | |
805 | if (!useleft && rec.ir_freecount) { | |
806 | /* | |
807 | * Yes, it's already set up. | |
808 | */ | |
809 | xfs_btree_del_cursor(tcur, | |
810 | XFS_BTREE_NOERROR); | |
811 | break; | |
812 | } | |
813 | /* | |
814 | * If used the left, get another one | |
815 | * further left. | |
816 | */ | |
817 | if (useleft) { | |
818 | if ((error = xfs_inobt_decrement(tcur, 0, | |
819 | &i))) | |
820 | goto error1; | |
821 | doneleft = !i; | |
822 | if (!doneleft) { | |
823 | if ((error = xfs_inobt_get_rec( | |
824 | tcur, | |
825 | &trec.ir_startino, | |
826 | &trec.ir_freecount, | |
827 | &trec.ir_free, &i))) | |
828 | goto error1; | |
829 | XFS_WANT_CORRUPTED_GOTO(i == 1, | |
830 | error1); | |
831 | } | |
832 | } | |
833 | /* | |
834 | * If used the right, get another one | |
835 | * further right. | |
836 | */ | |
837 | else { | |
637aa50f | 838 | if ((error = xfs_btree_increment(cur, 0, |
1da177e4 LT |
839 | &i))) |
840 | goto error1; | |
841 | doneright = !i; | |
842 | if (!doneright) { | |
843 | if ((error = xfs_inobt_get_rec( | |
844 | cur, | |
845 | &rec.ir_startino, | |
846 | &rec.ir_freecount, | |
847 | &rec.ir_free, &i))) | |
848 | goto error1; | |
849 | XFS_WANT_CORRUPTED_GOTO(i == 1, | |
850 | error1); | |
851 | } | |
852 | } | |
853 | } | |
854 | ASSERT(!doneleft || !doneright); | |
855 | } | |
856 | } | |
857 | /* | |
858 | * In a different a.g. from the parent. | |
859 | * See if the most recently allocated block has any free. | |
860 | */ | |
16259e7d | 861 | else if (be32_to_cpu(agi->agi_newino) != NULLAGINO) { |
1da177e4 | 862 | if ((error = xfs_inobt_lookup_eq(cur, |
16259e7d | 863 | be32_to_cpu(agi->agi_newino), 0, 0, &i))) |
1da177e4 LT |
864 | goto error0; |
865 | if (i == 1 && | |
866 | (error = xfs_inobt_get_rec(cur, &rec.ir_startino, | |
867 | &rec.ir_freecount, &rec.ir_free, &j)) == 0 && | |
868 | j == 1 && | |
869 | rec.ir_freecount > 0) { | |
870 | /* | |
871 | * The last chunk allocated in the group still has | |
872 | * a free inode. | |
873 | */ | |
874 | } | |
875 | /* | |
876 | * None left in the last group, search the whole a.g. | |
877 | */ | |
878 | else { | |
879 | if (error) | |
880 | goto error0; | |
881 | if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i))) | |
882 | goto error0; | |
883 | ASSERT(i == 1); | |
884 | for (;;) { | |
885 | if ((error = xfs_inobt_get_rec(cur, | |
886 | &rec.ir_startino, | |
887 | &rec.ir_freecount, &rec.ir_free, | |
888 | &i))) | |
889 | goto error0; | |
890 | XFS_WANT_CORRUPTED_GOTO(i == 1, error0); | |
891 | if (rec.ir_freecount > 0) | |
892 | break; | |
637aa50f | 893 | if ((error = xfs_btree_increment(cur, 0, &i))) |
1da177e4 LT |
894 | goto error0; |
895 | XFS_WANT_CORRUPTED_GOTO(i == 1, error0); | |
896 | } | |
897 | } | |
898 | } | |
899 | offset = XFS_IALLOC_FIND_FREE(&rec.ir_free); | |
900 | ASSERT(offset >= 0); | |
901 | ASSERT(offset < XFS_INODES_PER_CHUNK); | |
902 | ASSERT((XFS_AGINO_TO_OFFSET(mp, rec.ir_startino) % | |
903 | XFS_INODES_PER_CHUNK) == 0); | |
904 | ino = XFS_AGINO_TO_INO(mp, agno, rec.ir_startino + offset); | |
905 | XFS_INOBT_CLR_FREE(&rec, offset); | |
906 | rec.ir_freecount--; | |
907 | if ((error = xfs_inobt_update(cur, rec.ir_startino, rec.ir_freecount, | |
908 | rec.ir_free))) | |
909 | goto error0; | |
413d57c9 | 910 | be32_add_cpu(&agi->agi_freecount, -1); |
1da177e4 LT |
911 | xfs_ialloc_log_agi(tp, agbp, XFS_AGI_FREECOUNT); |
912 | down_read(&mp->m_peraglock); | |
913 | mp->m_perag[tagno].pagi_freecount--; | |
914 | up_read(&mp->m_peraglock); | |
915 | #ifdef DEBUG | |
916 | if (cur->bc_nlevels == 1) { | |
917 | int freecount = 0; | |
918 | ||
919 | if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i))) | |
920 | goto error0; | |
921 | do { | |
922 | if ((error = xfs_inobt_get_rec(cur, &rec.ir_startino, | |
923 | &rec.ir_freecount, &rec.ir_free, &i))) | |
924 | goto error0; | |
925 | XFS_WANT_CORRUPTED_GOTO(i == 1, error0); | |
926 | freecount += rec.ir_freecount; | |
637aa50f | 927 | if ((error = xfs_btree_increment(cur, 0, &i))) |
1da177e4 LT |
928 | goto error0; |
929 | } while (i == 1); | |
16259e7d | 930 | ASSERT(freecount == be32_to_cpu(agi->agi_freecount) || |
1da177e4 LT |
931 | XFS_FORCED_SHUTDOWN(mp)); |
932 | } | |
933 | #endif | |
934 | xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); | |
935 | xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, -1); | |
936 | *inop = ino; | |
937 | return 0; | |
938 | error1: | |
939 | xfs_btree_del_cursor(tcur, XFS_BTREE_ERROR); | |
940 | error0: | |
941 | xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); | |
942 | return error; | |
943 | } | |
944 | ||
945 | /* | |
946 | * Free disk inode. Carefully avoids touching the incore inode, all | |
947 | * manipulations incore are the caller's responsibility. | |
948 | * The on-disk inode is not changed by this operation, only the | |
949 | * btree (free inode mask) is changed. | |
950 | */ | |
951 | int | |
952 | xfs_difree( | |
953 | xfs_trans_t *tp, /* transaction pointer */ | |
954 | xfs_ino_t inode, /* inode to be freed */ | |
955 | xfs_bmap_free_t *flist, /* extents to free */ | |
956 | int *delete, /* set if inode cluster was deleted */ | |
957 | xfs_ino_t *first_ino) /* first inode in deleted cluster */ | |
958 | { | |
959 | /* REFERENCED */ | |
960 | xfs_agblock_t agbno; /* block number containing inode */ | |
961 | xfs_buf_t *agbp; /* buffer containing allocation group header */ | |
962 | xfs_agino_t agino; /* inode number relative to allocation group */ | |
963 | xfs_agnumber_t agno; /* allocation group number */ | |
964 | xfs_agi_t *agi; /* allocation group header */ | |
965 | xfs_btree_cur_t *cur; /* inode btree cursor */ | |
966 | int error; /* error return value */ | |
967 | int i; /* result code */ | |
968 | int ilen; /* inodes in an inode cluster */ | |
969 | xfs_mount_t *mp; /* mount structure for filesystem */ | |
970 | int off; /* offset of inode in inode chunk */ | |
61a25848 | 971 | xfs_inobt_rec_incore_t rec; /* btree record */ |
1da177e4 LT |
972 | |
973 | mp = tp->t_mountp; | |
974 | ||
975 | /* | |
976 | * Break up inode number into its components. | |
977 | */ | |
978 | agno = XFS_INO_TO_AGNO(mp, inode); | |
979 | if (agno >= mp->m_sb.sb_agcount) { | |
980 | cmn_err(CE_WARN, | |
981 | "xfs_difree: agno >= mp->m_sb.sb_agcount (%d >= %d) on %s. Returning EINVAL.", | |
982 | agno, mp->m_sb.sb_agcount, mp->m_fsname); | |
983 | ASSERT(0); | |
984 | return XFS_ERROR(EINVAL); | |
985 | } | |
986 | agino = XFS_INO_TO_AGINO(mp, inode); | |
987 | if (inode != XFS_AGINO_TO_INO(mp, agno, agino)) { | |
988 | cmn_err(CE_WARN, | |
da1650a5 CH |
989 | "xfs_difree: inode != XFS_AGINO_TO_INO() " |
990 | "(%llu != %llu) on %s. Returning EINVAL.", | |
991 | (unsigned long long)inode, | |
992 | (unsigned long long)XFS_AGINO_TO_INO(mp, agno, agino), | |
993 | mp->m_fsname); | |
1da177e4 LT |
994 | ASSERT(0); |
995 | return XFS_ERROR(EINVAL); | |
996 | } | |
997 | agbno = XFS_AGINO_TO_AGBNO(mp, agino); | |
998 | if (agbno >= mp->m_sb.sb_agblocks) { | |
999 | cmn_err(CE_WARN, | |
1000 | "xfs_difree: agbno >= mp->m_sb.sb_agblocks (%d >= %d) on %s. Returning EINVAL.", | |
1001 | agbno, mp->m_sb.sb_agblocks, mp->m_fsname); | |
1002 | ASSERT(0); | |
1003 | return XFS_ERROR(EINVAL); | |
1004 | } | |
1005 | /* | |
1006 | * Get the allocation group header. | |
1007 | */ | |
1008 | down_read(&mp->m_peraglock); | |
1009 | error = xfs_ialloc_read_agi(mp, tp, agno, &agbp); | |
1010 | up_read(&mp->m_peraglock); | |
1011 | if (error) { | |
1012 | cmn_err(CE_WARN, | |
1013 | "xfs_difree: xfs_ialloc_read_agi() returned an error %d on %s. Returning error.", | |
1014 | error, mp->m_fsname); | |
1015 | return error; | |
1016 | } | |
1017 | agi = XFS_BUF_TO_AGI(agbp); | |
16259e7d CH |
1018 | ASSERT(be32_to_cpu(agi->agi_magicnum) == XFS_AGI_MAGIC); |
1019 | ASSERT(agbno < be32_to_cpu(agi->agi_length)); | |
1da177e4 LT |
1020 | /* |
1021 | * Initialize the cursor. | |
1022 | */ | |
561f7d17 | 1023 | cur = xfs_inobt_init_cursor(mp, tp, agbp, agno); |
1da177e4 LT |
1024 | #ifdef DEBUG |
1025 | if (cur->bc_nlevels == 1) { | |
1026 | int freecount = 0; | |
1027 | ||
1028 | if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i))) | |
1029 | goto error0; | |
1030 | do { | |
1031 | if ((error = xfs_inobt_get_rec(cur, &rec.ir_startino, | |
1032 | &rec.ir_freecount, &rec.ir_free, &i))) | |
1033 | goto error0; | |
1034 | if (i) { | |
1035 | freecount += rec.ir_freecount; | |
637aa50f | 1036 | if ((error = xfs_btree_increment(cur, 0, &i))) |
1da177e4 LT |
1037 | goto error0; |
1038 | } | |
1039 | } while (i == 1); | |
16259e7d | 1040 | ASSERT(freecount == be32_to_cpu(agi->agi_freecount) || |
1da177e4 LT |
1041 | XFS_FORCED_SHUTDOWN(mp)); |
1042 | } | |
1043 | #endif | |
1044 | /* | |
1045 | * Look for the entry describing this inode. | |
1046 | */ | |
1047 | if ((error = xfs_inobt_lookup_le(cur, agino, 0, 0, &i))) { | |
1048 | cmn_err(CE_WARN, | |
1049 | "xfs_difree: xfs_inobt_lookup_le returned() an error %d on %s. Returning error.", | |
1050 | error, mp->m_fsname); | |
1051 | goto error0; | |
1052 | } | |
1053 | XFS_WANT_CORRUPTED_GOTO(i == 1, error0); | |
1054 | if ((error = xfs_inobt_get_rec(cur, &rec.ir_startino, &rec.ir_freecount, | |
1055 | &rec.ir_free, &i))) { | |
1056 | cmn_err(CE_WARN, | |
1057 | "xfs_difree: xfs_inobt_get_rec() returned an error %d on %s. Returning error.", | |
1058 | error, mp->m_fsname); | |
1059 | goto error0; | |
1060 | } | |
1061 | XFS_WANT_CORRUPTED_GOTO(i == 1, error0); | |
1062 | /* | |
1063 | * Get the offset in the inode chunk. | |
1064 | */ | |
1065 | off = agino - rec.ir_startino; | |
1066 | ASSERT(off >= 0 && off < XFS_INODES_PER_CHUNK); | |
1067 | ASSERT(!XFS_INOBT_IS_FREE(&rec, off)); | |
1068 | /* | |
1069 | * Mark the inode free & increment the count. | |
1070 | */ | |
1071 | XFS_INOBT_SET_FREE(&rec, off); | |
1072 | rec.ir_freecount++; | |
1073 | ||
1074 | /* | |
c41564b5 | 1075 | * When an inode cluster is free, it becomes eligible for removal |
1da177e4 | 1076 | */ |
1bd960ee | 1077 | if (!(mp->m_flags & XFS_MOUNT_IKEEP) && |
1da177e4 LT |
1078 | (rec.ir_freecount == XFS_IALLOC_INODES(mp))) { |
1079 | ||
1080 | *delete = 1; | |
1081 | *first_ino = XFS_AGINO_TO_INO(mp, agno, rec.ir_startino); | |
1082 | ||
1083 | /* | |
1084 | * Remove the inode cluster from the AGI B+Tree, adjust the | |
1085 | * AGI and Superblock inode counts, and mark the disk space | |
1086 | * to be freed when the transaction is committed. | |
1087 | */ | |
1088 | ilen = XFS_IALLOC_INODES(mp); | |
413d57c9 MS |
1089 | be32_add_cpu(&agi->agi_count, -ilen); |
1090 | be32_add_cpu(&agi->agi_freecount, -(ilen - 1)); | |
1da177e4 LT |
1091 | xfs_ialloc_log_agi(tp, agbp, XFS_AGI_COUNT | XFS_AGI_FREECOUNT); |
1092 | down_read(&mp->m_peraglock); | |
1093 | mp->m_perag[agno].pagi_freecount -= ilen - 1; | |
1094 | up_read(&mp->m_peraglock); | |
1095 | xfs_trans_mod_sb(tp, XFS_TRANS_SB_ICOUNT, -ilen); | |
1096 | xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, -(ilen - 1)); | |
1097 | ||
1098 | if ((error = xfs_inobt_delete(cur, &i))) { | |
1099 | cmn_err(CE_WARN, "xfs_difree: xfs_inobt_delete returned an error %d on %s.\n", | |
1100 | error, mp->m_fsname); | |
1101 | goto error0; | |
1102 | } | |
1103 | ||
1104 | xfs_bmap_add_free(XFS_AGB_TO_FSB(mp, | |
1105 | agno, XFS_INO_TO_AGBNO(mp,rec.ir_startino)), | |
1106 | XFS_IALLOC_BLOCKS(mp), flist, mp); | |
1107 | } else { | |
1108 | *delete = 0; | |
1109 | ||
1110 | if ((error = xfs_inobt_update(cur, rec.ir_startino, rec.ir_freecount, rec.ir_free))) { | |
1111 | cmn_err(CE_WARN, | |
1112 | "xfs_difree: xfs_inobt_update() returned an error %d on %s. Returning error.", | |
1113 | error, mp->m_fsname); | |
1114 | goto error0; | |
1115 | } | |
1116 | /* | |
1117 | * Change the inode free counts and log the ag/sb changes. | |
1118 | */ | |
413d57c9 | 1119 | be32_add_cpu(&agi->agi_freecount, 1); |
1da177e4 LT |
1120 | xfs_ialloc_log_agi(tp, agbp, XFS_AGI_FREECOUNT); |
1121 | down_read(&mp->m_peraglock); | |
1122 | mp->m_perag[agno].pagi_freecount++; | |
1123 | up_read(&mp->m_peraglock); | |
1124 | xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, 1); | |
1125 | } | |
1126 | ||
1127 | #ifdef DEBUG | |
1128 | if (cur->bc_nlevels == 1) { | |
1129 | int freecount = 0; | |
1130 | ||
1131 | if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i))) | |
1132 | goto error0; | |
1133 | do { | |
1134 | if ((error = xfs_inobt_get_rec(cur, | |
1135 | &rec.ir_startino, | |
1136 | &rec.ir_freecount, | |
1137 | &rec.ir_free, &i))) | |
1138 | goto error0; | |
1139 | if (i) { | |
1140 | freecount += rec.ir_freecount; | |
637aa50f | 1141 | if ((error = xfs_btree_increment(cur, 0, &i))) |
1da177e4 LT |
1142 | goto error0; |
1143 | } | |
1144 | } while (i == 1); | |
16259e7d | 1145 | ASSERT(freecount == be32_to_cpu(agi->agi_freecount) || |
1da177e4 LT |
1146 | XFS_FORCED_SHUTDOWN(mp)); |
1147 | } | |
1148 | #endif | |
1149 | xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); | |
1150 | return 0; | |
1151 | ||
1152 | error0: | |
1153 | xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); | |
1154 | return error; | |
1155 | } | |
1156 | ||
1157 | /* | |
1158 | * Return the location of the inode in bno/off, for mapping it into a buffer. | |
1159 | */ | |
1160 | /*ARGSUSED*/ | |
1161 | int | |
1162 | xfs_dilocate( | |
1163 | xfs_mount_t *mp, /* file system mount structure */ | |
1164 | xfs_trans_t *tp, /* transaction pointer */ | |
1165 | xfs_ino_t ino, /* inode to locate */ | |
1166 | xfs_fsblock_t *bno, /* output: block containing inode */ | |
1167 | int *len, /* output: num blocks in inode cluster */ | |
1168 | int *off, /* output: index in block of inode */ | |
1169 | uint flags) /* flags concerning inode lookup */ | |
1170 | { | |
1171 | xfs_agblock_t agbno; /* block number of inode in the alloc group */ | |
1172 | xfs_buf_t *agbp; /* agi buffer */ | |
1173 | xfs_agino_t agino; /* inode number within alloc group */ | |
1174 | xfs_agnumber_t agno; /* allocation group number */ | |
1175 | int blks_per_cluster; /* num blocks per inode cluster */ | |
1176 | xfs_agblock_t chunk_agbno; /* first block in inode chunk */ | |
1177 | xfs_agino_t chunk_agino; /* first agino in inode chunk */ | |
1178 | __int32_t chunk_cnt; /* count of free inodes in chunk */ | |
1179 | xfs_inofree_t chunk_free; /* mask of free inodes in chunk */ | |
1180 | xfs_agblock_t cluster_agbno; /* first block in inode cluster */ | |
1181 | xfs_btree_cur_t *cur; /* inode btree cursor */ | |
1182 | int error; /* error code */ | |
1183 | int i; /* temp state */ | |
1184 | int offset; /* index of inode in its buffer */ | |
1185 | int offset_agbno; /* blks from chunk start to inode */ | |
1186 | ||
1187 | ASSERT(ino != NULLFSINO); | |
1188 | /* | |
1189 | * Split up the inode number into its parts. | |
1190 | */ | |
1191 | agno = XFS_INO_TO_AGNO(mp, ino); | |
1192 | agino = XFS_INO_TO_AGINO(mp, ino); | |
1193 | agbno = XFS_AGINO_TO_AGBNO(mp, agino); | |
1194 | if (agno >= mp->m_sb.sb_agcount || agbno >= mp->m_sb.sb_agblocks || | |
1195 | ino != XFS_AGINO_TO_INO(mp, agno, agino)) { | |
1196 | #ifdef DEBUG | |
4d1a2ed3 NS |
1197 | /* no diagnostics for bulkstat, ino comes from userspace */ |
1198 | if (flags & XFS_IMAP_BULKSTAT) | |
1199 | return XFS_ERROR(EINVAL); | |
1da177e4 LT |
1200 | if (agno >= mp->m_sb.sb_agcount) { |
1201 | xfs_fs_cmn_err(CE_ALERT, mp, | |
1202 | "xfs_dilocate: agno (%d) >= " | |
1203 | "mp->m_sb.sb_agcount (%d)", | |
1204 | agno, mp->m_sb.sb_agcount); | |
1205 | } | |
1206 | if (agbno >= mp->m_sb.sb_agblocks) { | |
1207 | xfs_fs_cmn_err(CE_ALERT, mp, | |
1208 | "xfs_dilocate: agbno (0x%llx) >= " | |
1209 | "mp->m_sb.sb_agblocks (0x%lx)", | |
1210 | (unsigned long long) agbno, | |
1211 | (unsigned long) mp->m_sb.sb_agblocks); | |
1212 | } | |
1213 | if (ino != XFS_AGINO_TO_INO(mp, agno, agino)) { | |
1214 | xfs_fs_cmn_err(CE_ALERT, mp, | |
1215 | "xfs_dilocate: ino (0x%llx) != " | |
1216 | "XFS_AGINO_TO_INO(mp, agno, agino) " | |
1217 | "(0x%llx)", | |
1218 | ino, XFS_AGINO_TO_INO(mp, agno, agino)); | |
1219 | } | |
745b1f47 | 1220 | xfs_stack_trace(); |
1da177e4 LT |
1221 | #endif /* DEBUG */ |
1222 | return XFS_ERROR(EINVAL); | |
1223 | } | |
1224 | if ((mp->m_sb.sb_blocksize >= XFS_INODE_CLUSTER_SIZE(mp)) || | |
1225 | !(flags & XFS_IMAP_LOOKUP)) { | |
1226 | offset = XFS_INO_TO_OFFSET(mp, ino); | |
1227 | ASSERT(offset < mp->m_sb.sb_inopblock); | |
1228 | *bno = XFS_AGB_TO_FSB(mp, agno, agbno); | |
1229 | *off = offset; | |
1230 | *len = 1; | |
1231 | return 0; | |
1232 | } | |
1233 | blks_per_cluster = XFS_INODE_CLUSTER_SIZE(mp) >> mp->m_sb.sb_blocklog; | |
1234 | if (*bno != NULLFSBLOCK) { | |
1235 | offset = XFS_INO_TO_OFFSET(mp, ino); | |
1236 | ASSERT(offset < mp->m_sb.sb_inopblock); | |
1237 | cluster_agbno = XFS_FSB_TO_AGBNO(mp, *bno); | |
1238 | *off = ((agbno - cluster_agbno) * mp->m_sb.sb_inopblock) + | |
1239 | offset; | |
1240 | *len = blks_per_cluster; | |
1241 | return 0; | |
1242 | } | |
1243 | if (mp->m_inoalign_mask) { | |
1244 | offset_agbno = agbno & mp->m_inoalign_mask; | |
1245 | chunk_agbno = agbno - offset_agbno; | |
1246 | } else { | |
1247 | down_read(&mp->m_peraglock); | |
1248 | error = xfs_ialloc_read_agi(mp, tp, agno, &agbp); | |
1249 | up_read(&mp->m_peraglock); | |
1250 | if (error) { | |
1251 | #ifdef DEBUG | |
1252 | xfs_fs_cmn_err(CE_ALERT, mp, "xfs_dilocate: " | |
1253 | "xfs_ialloc_read_agi() returned " | |
1254 | "error %d, agno %d", | |
1255 | error, agno); | |
1256 | #endif /* DEBUG */ | |
1257 | return error; | |
1258 | } | |
561f7d17 | 1259 | cur = xfs_inobt_init_cursor(mp, tp, agbp, agno); |
1da177e4 LT |
1260 | if ((error = xfs_inobt_lookup_le(cur, agino, 0, 0, &i))) { |
1261 | #ifdef DEBUG | |
1262 | xfs_fs_cmn_err(CE_ALERT, mp, "xfs_dilocate: " | |
1263 | "xfs_inobt_lookup_le() failed"); | |
1264 | #endif /* DEBUG */ | |
1265 | goto error0; | |
1266 | } | |
1267 | if ((error = xfs_inobt_get_rec(cur, &chunk_agino, &chunk_cnt, | |
1268 | &chunk_free, &i))) { | |
1269 | #ifdef DEBUG | |
1270 | xfs_fs_cmn_err(CE_ALERT, mp, "xfs_dilocate: " | |
1271 | "xfs_inobt_get_rec() failed"); | |
1272 | #endif /* DEBUG */ | |
1273 | goto error0; | |
1274 | } | |
1275 | if (i == 0) { | |
1276 | #ifdef DEBUG | |
1277 | xfs_fs_cmn_err(CE_ALERT, mp, "xfs_dilocate: " | |
1278 | "xfs_inobt_get_rec() failed"); | |
1279 | #endif /* DEBUG */ | |
1280 | error = XFS_ERROR(EINVAL); | |
1281 | } | |
1282 | xfs_trans_brelse(tp, agbp); | |
1283 | xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); | |
1284 | if (error) | |
1285 | return error; | |
1286 | chunk_agbno = XFS_AGINO_TO_AGBNO(mp, chunk_agino); | |
1287 | offset_agbno = agbno - chunk_agbno; | |
1288 | } | |
1289 | ASSERT(agbno >= chunk_agbno); | |
1290 | cluster_agbno = chunk_agbno + | |
1291 | ((offset_agbno / blks_per_cluster) * blks_per_cluster); | |
1292 | offset = ((agbno - cluster_agbno) * mp->m_sb.sb_inopblock) + | |
1293 | XFS_INO_TO_OFFSET(mp, ino); | |
1294 | *bno = XFS_AGB_TO_FSB(mp, agno, cluster_agbno); | |
1295 | *off = offset; | |
1296 | *len = blks_per_cluster; | |
1297 | return 0; | |
1298 | error0: | |
1299 | xfs_trans_brelse(tp, agbp); | |
1300 | xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); | |
1301 | return error; | |
1302 | } | |
1303 | ||
1304 | /* | |
1305 | * Compute and fill in value of m_in_maxlevels. | |
1306 | */ | |
1307 | void | |
1308 | xfs_ialloc_compute_maxlevels( | |
1309 | xfs_mount_t *mp) /* file system mount structure */ | |
1310 | { | |
1311 | int level; | |
1312 | uint maxblocks; | |
1313 | uint maxleafents; | |
1314 | int minleafrecs; | |
1315 | int minnoderecs; | |
1316 | ||
1317 | maxleafents = (1LL << XFS_INO_AGINO_BITS(mp)) >> | |
1318 | XFS_INODES_PER_CHUNK_LOG; | |
1319 | minleafrecs = mp->m_alloc_mnr[0]; | |
1320 | minnoderecs = mp->m_alloc_mnr[1]; | |
1321 | maxblocks = (maxleafents + minleafrecs - 1) / minleafrecs; | |
1322 | for (level = 1; maxblocks > 1; level++) | |
1323 | maxblocks = (maxblocks + minnoderecs - 1) / minnoderecs; | |
1324 | mp->m_in_maxlevels = level; | |
1325 | } | |
1326 | ||
1327 | /* | |
1328 | * Log specified fields for the ag hdr (inode section) | |
1329 | */ | |
1330 | void | |
1331 | xfs_ialloc_log_agi( | |
1332 | xfs_trans_t *tp, /* transaction pointer */ | |
1333 | xfs_buf_t *bp, /* allocation group header buffer */ | |
1334 | int fields) /* bitmask of fields to log */ | |
1335 | { | |
1336 | int first; /* first byte number */ | |
1337 | int last; /* last byte number */ | |
1338 | static const short offsets[] = { /* field starting offsets */ | |
1339 | /* keep in sync with bit definitions */ | |
1340 | offsetof(xfs_agi_t, agi_magicnum), | |
1341 | offsetof(xfs_agi_t, agi_versionnum), | |
1342 | offsetof(xfs_agi_t, agi_seqno), | |
1343 | offsetof(xfs_agi_t, agi_length), | |
1344 | offsetof(xfs_agi_t, agi_count), | |
1345 | offsetof(xfs_agi_t, agi_root), | |
1346 | offsetof(xfs_agi_t, agi_level), | |
1347 | offsetof(xfs_agi_t, agi_freecount), | |
1348 | offsetof(xfs_agi_t, agi_newino), | |
1349 | offsetof(xfs_agi_t, agi_dirino), | |
1350 | offsetof(xfs_agi_t, agi_unlinked), | |
1351 | sizeof(xfs_agi_t) | |
1352 | }; | |
1353 | #ifdef DEBUG | |
1354 | xfs_agi_t *agi; /* allocation group header */ | |
1355 | ||
1356 | agi = XFS_BUF_TO_AGI(bp); | |
16259e7d | 1357 | ASSERT(be32_to_cpu(agi->agi_magicnum) == XFS_AGI_MAGIC); |
1da177e4 LT |
1358 | #endif |
1359 | /* | |
1360 | * Compute byte offsets for the first and last fields. | |
1361 | */ | |
1362 | xfs_btree_offsets(fields, offsets, XFS_AGI_NUM_BITS, &first, &last); | |
1363 | /* | |
1364 | * Log the allocation group inode header buffer. | |
1365 | */ | |
1366 | xfs_trans_log_buf(tp, bp, first, last); | |
1367 | } | |
1368 | ||
1369 | /* | |
1370 | * Read in the allocation group header (inode allocation section) | |
1371 | */ | |
1372 | int | |
1373 | xfs_ialloc_read_agi( | |
1374 | xfs_mount_t *mp, /* file system mount structure */ | |
1375 | xfs_trans_t *tp, /* transaction pointer */ | |
1376 | xfs_agnumber_t agno, /* allocation group number */ | |
1377 | xfs_buf_t **bpp) /* allocation group hdr buf */ | |
1378 | { | |
1379 | xfs_agi_t *agi; /* allocation group header */ | |
1380 | int agi_ok; /* agi is consistent */ | |
1381 | xfs_buf_t *bp; /* allocation group hdr buf */ | |
1382 | xfs_perag_t *pag; /* per allocation group data */ | |
1383 | int error; | |
1384 | ||
1385 | ASSERT(agno != NULLAGNUMBER); | |
1386 | error = xfs_trans_read_buf( | |
1387 | mp, tp, mp->m_ddev_targp, | |
1388 | XFS_AG_DADDR(mp, agno, XFS_AGI_DADDR(mp)), | |
1389 | XFS_FSS_TO_BB(mp, 1), 0, &bp); | |
1390 | if (error) | |
1391 | return error; | |
1392 | ASSERT(bp && !XFS_BUF_GETERROR(bp)); | |
1393 | ||
1394 | /* | |
1395 | * Validate the magic number of the agi block. | |
1396 | */ | |
1397 | agi = XFS_BUF_TO_AGI(bp); | |
1398 | agi_ok = | |
16259e7d CH |
1399 | be32_to_cpu(agi->agi_magicnum) == XFS_AGI_MAGIC && |
1400 | XFS_AGI_GOOD_VERSION(be32_to_cpu(agi->agi_versionnum)); | |
1da177e4 LT |
1401 | if (unlikely(XFS_TEST_ERROR(!agi_ok, mp, XFS_ERRTAG_IALLOC_READ_AGI, |
1402 | XFS_RANDOM_IALLOC_READ_AGI))) { | |
1403 | XFS_CORRUPTION_ERROR("xfs_ialloc_read_agi", XFS_ERRLEVEL_LOW, | |
1404 | mp, agi); | |
1405 | xfs_trans_brelse(tp, bp); | |
1406 | return XFS_ERROR(EFSCORRUPTED); | |
1407 | } | |
1408 | pag = &mp->m_perag[agno]; | |
1409 | if (!pag->pagi_init) { | |
16259e7d | 1410 | pag->pagi_freecount = be32_to_cpu(agi->agi_freecount); |
92821e2b | 1411 | pag->pagi_count = be32_to_cpu(agi->agi_count); |
1da177e4 LT |
1412 | pag->pagi_init = 1; |
1413 | } else { | |
1414 | /* | |
1415 | * It's possible for these to be out of sync if | |
1416 | * we are in the middle of a forced shutdown. | |
1417 | */ | |
16259e7d CH |
1418 | ASSERT(pag->pagi_freecount == be32_to_cpu(agi->agi_freecount) || |
1419 | XFS_FORCED_SHUTDOWN(mp)); | |
1da177e4 LT |
1420 | } |
1421 | ||
1422 | #ifdef DEBUG | |
1423 | { | |
1424 | int i; | |
1425 | ||
1426 | for (i = 0; i < XFS_AGI_UNLINKED_BUCKETS; i++) | |
1427 | ASSERT(agi->agi_unlinked[i]); | |
1428 | } | |
1429 | #endif | |
1430 | ||
1431 | XFS_BUF_SET_VTYPE_REF(bp, B_FS_AGI, XFS_AGI_REF); | |
1432 | *bpp = bp; | |
1433 | return 0; | |
1434 | } | |
92821e2b DC |
1435 | |
1436 | /* | |
1437 | * Read in the agi to initialise the per-ag data in the mount structure | |
1438 | */ | |
1439 | int | |
1440 | xfs_ialloc_pagi_init( | |
1441 | xfs_mount_t *mp, /* file system mount structure */ | |
1442 | xfs_trans_t *tp, /* transaction pointer */ | |
1443 | xfs_agnumber_t agno) /* allocation group number */ | |
1444 | { | |
1445 | xfs_buf_t *bp = NULL; | |
1446 | int error; | |
1447 | ||
1448 | error = xfs_ialloc_read_agi(mp, tp, agno, &bp); | |
1449 | if (error) | |
1450 | return error; | |
1451 | if (bp) | |
1452 | xfs_trans_brelse(tp, bp); | |
1453 | return 0; | |
1454 | } |