2 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
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
7 * published by the Free Software Foundation.
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.
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
20 #include "xfs_types.h"
24 #include "xfs_trans.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_mount.h"
30 #include "xfs_bmap_btree.h"
31 #include "xfs_alloc_btree.h"
32 #include "xfs_ialloc_btree.h"
33 #include "xfs_dir2_sf.h"
34 #include "xfs_attr_sf.h"
35 #include "xfs_dinode.h"
36 #include "xfs_inode.h"
37 #include "xfs_btree.h"
38 #include "xfs_ialloc.h"
39 #include "xfs_alloc.h"
40 #include "xfs_rtalloc.h"
41 #include "xfs_error.h"
45 * Log specified fields for the inode given by bp and off.
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 */
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),
91 ASSERT(offsetof(xfs_dinode_t, di_core) == 0);
92 ASSERT((fields & (XFS_DI_U|XFS_DI_A)) == 0);
95 * Get the inode-relative first and last bytes for these fields
97 xfs_btree_offsets(fields, offsets, XFS_DI_NUM_BITS, &first, &last);
99 * Convert to buffer offsets and log it.
101 ioffset = off << mp->m_sb.sb_inodelog;
104 xfs_trans_log_buf(tp, bp, first, last);
108 * Allocation group level functions.
111 xfs_ialloc_cluster_alignment(
112 xfs_alloc_arg_t *args)
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;
122 * Lookup the record equal to ino in the btree given by cur.
124 STATIC int /* error */
126 struct xfs_btree_cur *cur, /* btree cursor */
127 xfs_agino_t ino, /* starting inode of chunk */
128 __int32_t fcnt, /* free inode count */
129 xfs_inofree_t free, /* free inode mask */
130 int *stat) /* success/failure */
132 cur->bc_rec.i.ir_startino = ino;
133 cur->bc_rec.i.ir_freecount = fcnt;
134 cur->bc_rec.i.ir_free = free;
135 return xfs_btree_lookup(cur, XFS_LOOKUP_EQ, stat);
139 * Lookup the first record greater than or equal to ino
140 * in the btree given by cur.
144 struct xfs_btree_cur *cur, /* btree cursor */
145 xfs_agino_t ino, /* starting inode of chunk */
146 __int32_t fcnt, /* free inode count */
147 xfs_inofree_t free, /* free inode mask */
148 int *stat) /* success/failure */
150 cur->bc_rec.i.ir_startino = ino;
151 cur->bc_rec.i.ir_freecount = fcnt;
152 cur->bc_rec.i.ir_free = free;
153 return xfs_btree_lookup(cur, XFS_LOOKUP_GE, stat);
157 * Lookup the first record less than or equal to ino
158 * in the btree given by cur.
162 struct xfs_btree_cur *cur, /* btree cursor */
163 xfs_agino_t ino, /* starting inode of chunk */
164 __int32_t fcnt, /* free inode count */
165 xfs_inofree_t free, /* free inode mask */
166 int *stat) /* success/failure */
168 cur->bc_rec.i.ir_startino = ino;
169 cur->bc_rec.i.ir_freecount = fcnt;
170 cur->bc_rec.i.ir_free = free;
171 return xfs_btree_lookup(cur, XFS_LOOKUP_LE, stat);
175 * Allocate new inodes in the allocation group specified by agbp.
176 * Return 0 for success, else error code.
178 STATIC int /* error code or 0 */
180 xfs_trans_t *tp, /* transaction pointer */
181 xfs_buf_t *agbp, /* alloc group buffer */
184 xfs_agi_t *agi; /* allocation group header */
185 xfs_alloc_arg_t args; /* allocation argument structure */
186 int blks_per_cluster; /* fs blocks per inode cluster */
187 xfs_btree_cur_t *cur; /* inode btree cursor */
188 xfs_daddr_t d; /* disk addr of buffer */
191 xfs_buf_t *fbuf; /* new free inodes' buffer */
192 xfs_dinode_t *free; /* new free inode structure */
193 int i; /* inode counter */
194 int j; /* block counter */
195 int nbufs; /* num bufs of new inodes */
196 xfs_agino_t newino; /* new first inode's number */
197 xfs_agino_t newlen; /* new number of inodes */
198 int ninodes; /* num inodes per buf */
199 xfs_agino_t thisino; /* current inode number, for loop */
200 int version; /* inode version number to use */
201 int isaligned = 0; /* inode allocation at stripe unit */
206 args.mp = tp->t_mountp;
209 * Locking will ensure that we don't have two callers in here
212 newlen = XFS_IALLOC_INODES(args.mp);
213 if (args.mp->m_maxicount &&
214 args.mp->m_sb.sb_icount + newlen > args.mp->m_maxicount)
215 return XFS_ERROR(ENOSPC);
216 args.minlen = args.maxlen = XFS_IALLOC_BLOCKS(args.mp);
218 * First try to allocate inodes contiguous with the last-allocated
219 * chunk of inodes. If the filesystem is striped, this will fill
220 * an entire stripe unit with inodes.
222 agi = XFS_BUF_TO_AGI(agbp);
223 newino = be32_to_cpu(agi->agi_newino);
224 args.agbno = XFS_AGINO_TO_AGBNO(args.mp, newino) +
225 XFS_IALLOC_BLOCKS(args.mp);
226 if (likely(newino != NULLAGINO &&
227 (args.agbno < be32_to_cpu(agi->agi_length)))) {
228 args.fsbno = XFS_AGB_TO_FSB(args.mp,
229 be32_to_cpu(agi->agi_seqno), args.agbno);
230 args.type = XFS_ALLOCTYPE_THIS_BNO;
231 args.mod = args.total = args.wasdel = args.isfl =
232 args.userdata = args.minalignslop = 0;
236 * We need to take into account alignment here to ensure that
237 * we don't modify the free list if we fail to have an exact
238 * block. If we don't have an exact match, and every oher
239 * attempt allocation attempt fails, we'll end up cancelling
240 * a dirty transaction and shutting down.
242 * For an exact allocation, alignment must be 1,
243 * however we need to take cluster alignment into account when
244 * fixing up the freelist. Use the minalignslop field to
245 * indicate that extra blocks might be required for alignment,
246 * but not to use them in the actual exact allocation.
249 args.minalignslop = xfs_ialloc_cluster_alignment(&args) - 1;
251 /* Allow space for the inode btree to split. */
252 args.minleft = XFS_IN_MAXLEVELS(args.mp) - 1;
253 if ((error = xfs_alloc_vextent(&args)))
256 args.fsbno = NULLFSBLOCK;
258 if (unlikely(args.fsbno == NULLFSBLOCK)) {
260 * Set the alignment for the allocation.
261 * If stripe alignment is turned on then align at stripe unit
263 * If the cluster size is smaller than a filesystem block
264 * then we're doing I/O for inodes in filesystem block size
265 * pieces, so don't need alignment anyway.
268 if (args.mp->m_sinoalign) {
269 ASSERT(!(args.mp->m_flags & XFS_MOUNT_NOALIGN));
270 args.alignment = args.mp->m_dalign;
273 args.alignment = xfs_ialloc_cluster_alignment(&args);
275 * Need to figure out where to allocate the inode blocks.
276 * Ideally they should be spaced out through the a.g.
277 * For now, just allocate blocks up front.
279 args.agbno = be32_to_cpu(agi->agi_root);
280 args.fsbno = XFS_AGB_TO_FSB(args.mp,
281 be32_to_cpu(agi->agi_seqno), args.agbno);
283 * Allocate a fixed-size extent of inodes.
285 args.type = XFS_ALLOCTYPE_NEAR_BNO;
286 args.mod = args.total = args.wasdel = args.isfl =
287 args.userdata = args.minalignslop = 0;
290 * Allow space for the inode btree to split.
292 args.minleft = XFS_IN_MAXLEVELS(args.mp) - 1;
293 if ((error = xfs_alloc_vextent(&args)))
298 * If stripe alignment is turned on, then try again with cluster
301 if (isaligned && args.fsbno == NULLFSBLOCK) {
302 args.type = XFS_ALLOCTYPE_NEAR_BNO;
303 args.agbno = be32_to_cpu(agi->agi_root);
304 args.fsbno = XFS_AGB_TO_FSB(args.mp,
305 be32_to_cpu(agi->agi_seqno), args.agbno);
306 args.alignment = xfs_ialloc_cluster_alignment(&args);
307 if ((error = xfs_alloc_vextent(&args)))
311 if (args.fsbno == NULLFSBLOCK) {
315 ASSERT(args.len == args.minlen);
317 * Convert the results.
319 newino = XFS_OFFBNO_TO_AGINO(args.mp, args.agbno, 0);
321 * Loop over the new block(s), filling in the inodes.
322 * For small block sizes, manipulate the inodes in buffers
323 * which are multiples of the blocks size.
325 if (args.mp->m_sb.sb_blocksize >= XFS_INODE_CLUSTER_SIZE(args.mp)) {
326 blks_per_cluster = 1;
327 nbufs = (int)args.len;
328 ninodes = args.mp->m_sb.sb_inopblock;
330 blks_per_cluster = XFS_INODE_CLUSTER_SIZE(args.mp) /
331 args.mp->m_sb.sb_blocksize;
332 nbufs = (int)args.len / blks_per_cluster;
333 ninodes = blks_per_cluster * args.mp->m_sb.sb_inopblock;
336 * Figure out what version number to use in the inodes we create.
337 * If the superblock version has caught up to the one that supports
338 * the new inode format, then use the new inode version. Otherwise
339 * use the old version so that old kernels will continue to be
340 * able to use the file system.
342 if (xfs_sb_version_hasnlink(&args.mp->m_sb))
343 version = XFS_DINODE_VERSION_2;
345 version = XFS_DINODE_VERSION_1;
348 * Seed the new inode cluster with a random generation number. This
349 * prevents short-term reuse of generation numbers if a chunk is
350 * freed and then immediately reallocated. We use random numbers
351 * rather than a linear progression to prevent the next generation
352 * number from being easily guessable.
355 for (j = 0; j < nbufs; j++) {
359 d = XFS_AGB_TO_DADDR(args.mp, be32_to_cpu(agi->agi_seqno),
360 args.agbno + (j * blks_per_cluster));
361 fbuf = xfs_trans_get_buf(tp, args.mp->m_ddev_targp, d,
362 args.mp->m_bsize * blks_per_cluster,
365 ASSERT(!XFS_BUF_GETERROR(fbuf));
367 * Set initial values for the inodes in this buffer.
369 xfs_biozero(fbuf, 0, ninodes << args.mp->m_sb.sb_inodelog);
370 for (i = 0; i < ninodes; i++) {
371 free = XFS_MAKE_IPTR(args.mp, fbuf, i);
372 free->di_core.di_magic = cpu_to_be16(XFS_DINODE_MAGIC);
373 free->di_core.di_version = version;
374 free->di_core.di_gen = cpu_to_be32(gen);
375 free->di_next_unlinked = cpu_to_be32(NULLAGINO);
376 xfs_ialloc_log_di(tp, fbuf, i,
377 XFS_DI_CORE_BITS | XFS_DI_NEXT_UNLINKED);
379 xfs_trans_inode_alloc_buf(tp, fbuf);
381 be32_add_cpu(&agi->agi_count, newlen);
382 be32_add_cpu(&agi->agi_freecount, newlen);
383 agno = be32_to_cpu(agi->agi_seqno);
384 down_read(&args.mp->m_peraglock);
385 args.mp->m_perag[agno].pagi_freecount += newlen;
386 up_read(&args.mp->m_peraglock);
387 agi->agi_newino = cpu_to_be32(newino);
389 * Insert records describing the new inode chunk into the btree.
391 cur = xfs_inobt_init_cursor(args.mp, tp, agbp, agno);
392 for (thisino = newino;
393 thisino < newino + newlen;
394 thisino += XFS_INODES_PER_CHUNK) {
395 if ((error = xfs_inobt_lookup_eq(cur, thisino,
396 XFS_INODES_PER_CHUNK, XFS_INOBT_ALL_FREE, &i))) {
397 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
401 if ((error = xfs_inobt_insert(cur, &i))) {
402 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
407 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
409 * Log allocation group header fields
411 xfs_ialloc_log_agi(tp, agbp,
412 XFS_AGI_COUNT | XFS_AGI_FREECOUNT | XFS_AGI_NEWINO);
414 * Modify/log superblock values for inode count and inode free count.
416 xfs_trans_mod_sb(tp, XFS_TRANS_SB_ICOUNT, (long)newlen);
417 xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, (long)newlen);
422 STATIC_INLINE xfs_agnumber_t
428 spin_lock(&mp->m_agirotor_lock);
429 agno = mp->m_agirotor;
430 if (++mp->m_agirotor == mp->m_maxagi)
432 spin_unlock(&mp->m_agirotor_lock);
438 * Select an allocation group to look for a free inode in, based on the parent
439 * inode and then mode. Return the allocation group buffer.
441 STATIC xfs_buf_t * /* allocation group buffer */
442 xfs_ialloc_ag_select(
443 xfs_trans_t *tp, /* transaction pointer */
444 xfs_ino_t parent, /* parent directory inode number */
445 mode_t mode, /* bits set to indicate file type */
446 int okalloc) /* ok to allocate more space */
448 xfs_buf_t *agbp; /* allocation group header buffer */
449 xfs_agnumber_t agcount; /* number of ag's in the filesystem */
450 xfs_agnumber_t agno; /* current ag number */
451 int flags; /* alloc buffer locking flags */
452 xfs_extlen_t ineed; /* blocks needed for inode allocation */
453 xfs_extlen_t longest = 0; /* longest extent available */
454 xfs_mount_t *mp; /* mount point structure */
455 int needspace; /* file mode implies space allocated */
456 xfs_perag_t *pag; /* per allocation group data */
457 xfs_agnumber_t pagno; /* parent (starting) ag number */
460 * Files of these types need at least one block if length > 0
461 * (and they won't fit in the inode, but that's hard to figure out).
463 needspace = S_ISDIR(mode) || S_ISREG(mode) || S_ISLNK(mode);
465 agcount = mp->m_maxagi;
467 pagno = xfs_ialloc_next_ag(mp);
469 pagno = XFS_INO_TO_AGNO(mp, parent);
470 if (pagno >= agcount)
473 ASSERT(pagno < agcount);
475 * Loop through allocation groups, looking for one with a little
476 * free space in it. Note we don't look for free inodes, exactly.
477 * Instead, we include whether there is a need to allocate inodes
478 * to mean that blocks must be allocated for them,
479 * if none are currently free.
482 flags = XFS_ALLOC_FLAG_TRYLOCK;
483 down_read(&mp->m_peraglock);
485 pag = &mp->m_perag[agno];
486 if (!pag->pagi_init) {
487 if (xfs_ialloc_read_agi(mp, tp, agno, &agbp)) {
494 if (!pag->pagi_inodeok) {
495 xfs_ialloc_next_ag(mp);
500 * Is there enough free space for the file plus a block
501 * of inodes (if we need to allocate some)?
503 ineed = pag->pagi_freecount ? 0 : XFS_IALLOC_BLOCKS(mp);
504 if (ineed && !pag->pagf_init) {
506 xfs_ialloc_read_agi(mp, tp, agno, &agbp)) {
510 (void)xfs_alloc_pagf_init(mp, tp, agno, flags);
512 if (!ineed || pag->pagf_init) {
513 if (ineed && !(longest = pag->pagf_longest))
514 longest = pag->pagf_flcount > 0;
516 (pag->pagf_freeblks >= needspace + ineed &&
520 xfs_ialloc_read_agi(mp, tp, agno, &agbp)) {
524 up_read(&mp->m_peraglock);
530 xfs_trans_brelse(tp, agbp);
533 * No point in iterating over the rest, if we're shutting
536 if (XFS_FORCED_SHUTDOWN(mp)) {
537 up_read(&mp->m_peraglock);
545 up_read(&mp->m_peraglock);
554 * Visible inode allocation functions.
558 * Allocate an inode on disk.
559 * Mode is used to tell whether the new inode will need space, and whether
562 * The arguments IO_agbp and alloc_done are defined to work within
563 * the constraint of one allocation per transaction.
564 * xfs_dialloc() is designed to be called twice if it has to do an
565 * allocation to make more free inodes. On the first call,
566 * IO_agbp should be set to NULL. If an inode is available,
567 * i.e., xfs_dialloc() did not need to do an allocation, an inode
568 * number is returned. In this case, IO_agbp would be set to the
569 * current ag_buf and alloc_done set to false.
570 * If an allocation needed to be done, xfs_dialloc would return
571 * the current ag_buf in IO_agbp and set alloc_done to true.
572 * The caller should then commit the current transaction, allocate a new
573 * transaction, and call xfs_dialloc() again, passing in the previous
574 * value of IO_agbp. IO_agbp should be held across the transactions.
575 * Since the agbp is locked across the two calls, the second call is
576 * guaranteed to have a free inode available.
578 * Once we successfully pick an inode its number is returned and the
579 * on-disk data structures are updated. The inode itself is not read
580 * in, since doing so would break ordering constraints with xfs_reclaim.
584 xfs_trans_t *tp, /* transaction pointer */
585 xfs_ino_t parent, /* parent inode (directory) */
586 mode_t mode, /* mode bits for new inode */
587 int okalloc, /* ok to allocate more space */
588 xfs_buf_t **IO_agbp, /* in/out ag header's buffer */
589 boolean_t *alloc_done, /* true if we needed to replenish
591 xfs_ino_t *inop) /* inode number allocated */
593 xfs_agnumber_t agcount; /* number of allocation groups */
594 xfs_buf_t *agbp; /* allocation group header's buffer */
595 xfs_agnumber_t agno; /* allocation group number */
596 xfs_agi_t *agi; /* allocation group header structure */
597 xfs_btree_cur_t *cur; /* inode allocation btree cursor */
598 int error; /* error return value */
599 int i; /* result code */
600 int ialloced; /* inode allocation status */
601 int noroom = 0; /* no space for inode blk allocation */
602 xfs_ino_t ino; /* fs-relative inode to be returned */
604 int j; /* result code */
605 xfs_mount_t *mp; /* file system mount structure */
606 int offset; /* index of inode in chunk */
607 xfs_agino_t pagino; /* parent's a.g. relative inode # */
608 xfs_agnumber_t pagno; /* parent's allocation group number */
609 xfs_inobt_rec_incore_t rec; /* inode allocation record */
610 xfs_agnumber_t tagno; /* testing allocation group number */
611 xfs_btree_cur_t *tcur; /* temp cursor */
612 xfs_inobt_rec_incore_t trec; /* temp inode allocation record */
615 if (*IO_agbp == NULL) {
617 * We do not have an agbp, so select an initial allocation
618 * group for inode allocation.
620 agbp = xfs_ialloc_ag_select(tp, parent, mode, okalloc);
622 * Couldn't find an allocation group satisfying the
629 agi = XFS_BUF_TO_AGI(agbp);
630 ASSERT(be32_to_cpu(agi->agi_magicnum) == XFS_AGI_MAGIC);
633 * Continue where we left off before. In this case, we
634 * know that the allocation group has free inodes.
637 agi = XFS_BUF_TO_AGI(agbp);
638 ASSERT(be32_to_cpu(agi->agi_magicnum) == XFS_AGI_MAGIC);
639 ASSERT(be32_to_cpu(agi->agi_freecount) > 0);
642 agcount = mp->m_sb.sb_agcount;
643 agno = be32_to_cpu(agi->agi_seqno);
645 pagno = XFS_INO_TO_AGNO(mp, parent);
646 pagino = XFS_INO_TO_AGINO(mp, parent);
649 * If we have already hit the ceiling of inode blocks then clear
650 * okalloc so we scan all available agi structures for a free
654 if (mp->m_maxicount &&
655 mp->m_sb.sb_icount + XFS_IALLOC_INODES(mp) > mp->m_maxicount) {
661 * Loop until we find an allocation group that either has free inodes
662 * or in which we can allocate some inodes. Iterate through the
663 * allocation groups upward, wrapping at the end.
665 *alloc_done = B_FALSE;
666 while (!agi->agi_freecount) {
668 * Don't do anything if we're not supposed to allocate
669 * any blocks, just go on to the next ag.
673 * Try to allocate some new inodes in the allocation
676 if ((error = xfs_ialloc_ag_alloc(tp, agbp, &ialloced))) {
677 xfs_trans_brelse(tp, agbp);
678 if (error == ENOSPC) {
686 * We successfully allocated some inodes, return
687 * the current context to the caller so that it
688 * can commit the current transaction and call
689 * us again where we left off.
691 ASSERT(be32_to_cpu(agi->agi_freecount) > 0);
692 *alloc_done = B_TRUE;
699 * If it failed, give up on this ag.
701 xfs_trans_brelse(tp, agbp);
703 * Go on to the next ag: get its ag header.
706 if (++tagno == agcount)
710 return noroom ? ENOSPC : 0;
712 down_read(&mp->m_peraglock);
713 if (mp->m_perag[tagno].pagi_inodeok == 0) {
714 up_read(&mp->m_peraglock);
717 error = xfs_ialloc_read_agi(mp, tp, tagno, &agbp);
718 up_read(&mp->m_peraglock);
721 agi = XFS_BUF_TO_AGI(agbp);
722 ASSERT(be32_to_cpu(agi->agi_magicnum) == XFS_AGI_MAGIC);
725 * Here with an allocation group that has a free inode.
726 * Reset agno since we may have chosen a new ag in the
731 cur = xfs_inobt_init_cursor(mp, tp, agbp, be32_to_cpu(agi->agi_seqno));
733 * If pagino is 0 (this is the root inode allocation) use newino.
734 * This must work because we've just allocated some.
737 pagino = be32_to_cpu(agi->agi_newino);
739 if (cur->bc_nlevels == 1) {
742 if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i)))
744 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
746 if ((error = xfs_inobt_get_rec(cur, &rec.ir_startino,
747 &rec.ir_freecount, &rec.ir_free, &i)))
749 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
750 freecount += rec.ir_freecount;
751 if ((error = xfs_btree_increment(cur, 0, &i)))
755 ASSERT(freecount == be32_to_cpu(agi->agi_freecount) ||
756 XFS_FORCED_SHUTDOWN(mp));
760 * If in the same a.g. as the parent, try to get near the parent.
763 if ((error = xfs_inobt_lookup_le(cur, pagino, 0, 0, &i)))
766 (error = xfs_inobt_get_rec(cur, &rec.ir_startino,
767 &rec.ir_freecount, &rec.ir_free, &j)) == 0 &&
769 rec.ir_freecount > 0) {
771 * Found a free inode in the same chunk
776 * In the same a.g. as parent, but parent's chunk is full.
779 int doneleft; /* done, to the left */
780 int doneright; /* done, to the right */
787 * Duplicate the cursor, search left & right
790 if ((error = xfs_btree_dup_cursor(cur, &tcur)))
793 * Search left with tcur, back up 1 record.
795 if ((error = xfs_btree_decrement(tcur, 0, &i)))
799 if ((error = xfs_inobt_get_rec(tcur,
804 XFS_WANT_CORRUPTED_GOTO(i == 1, error1);
807 * Search right with cur, go forward 1 record.
809 if ((error = xfs_btree_increment(cur, 0, &i)))
813 if ((error = xfs_inobt_get_rec(cur,
818 XFS_WANT_CORRUPTED_GOTO(i == 1, error1);
821 * Loop until we find the closest inode chunk
824 while (!doneleft || !doneright) {
825 int useleft; /* using left inode
829 * Figure out which block is closer,
832 if (!doneleft && !doneright)
836 XFS_INODES_PER_CHUNK - 1) <
837 rec.ir_startino - pagino;
841 * If checking the left, does it have
844 if (useleft && trec.ir_freecount) {
846 * Yes, set it up as the chunk to use.
849 xfs_btree_del_cursor(cur,
855 * If checking the right, does it have
858 if (!useleft && rec.ir_freecount) {
860 * Yes, it's already set up.
862 xfs_btree_del_cursor(tcur,
867 * If used the left, get another one
871 if ((error = xfs_btree_decrement(tcur, 0,
876 if ((error = xfs_inobt_get_rec(
882 XFS_WANT_CORRUPTED_GOTO(i == 1,
887 * If used the right, get another one
891 if ((error = xfs_btree_increment(cur, 0,
896 if ((error = xfs_inobt_get_rec(
902 XFS_WANT_CORRUPTED_GOTO(i == 1,
907 ASSERT(!doneleft || !doneright);
911 * In a different a.g. from the parent.
912 * See if the most recently allocated block has any free.
914 else if (be32_to_cpu(agi->agi_newino) != NULLAGINO) {
915 if ((error = xfs_inobt_lookup_eq(cur,
916 be32_to_cpu(agi->agi_newino), 0, 0, &i)))
919 (error = xfs_inobt_get_rec(cur, &rec.ir_startino,
920 &rec.ir_freecount, &rec.ir_free, &j)) == 0 &&
922 rec.ir_freecount > 0) {
924 * The last chunk allocated in the group still has
929 * None left in the last group, search the whole a.g.
934 if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i)))
938 if ((error = xfs_inobt_get_rec(cur,
940 &rec.ir_freecount, &rec.ir_free,
943 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
944 if (rec.ir_freecount > 0)
946 if ((error = xfs_btree_increment(cur, 0, &i)))
948 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
952 offset = XFS_IALLOC_FIND_FREE(&rec.ir_free);
954 ASSERT(offset < XFS_INODES_PER_CHUNK);
955 ASSERT((XFS_AGINO_TO_OFFSET(mp, rec.ir_startino) %
956 XFS_INODES_PER_CHUNK) == 0);
957 ino = XFS_AGINO_TO_INO(mp, agno, rec.ir_startino + offset);
958 XFS_INOBT_CLR_FREE(&rec, offset);
960 if ((error = xfs_inobt_update(cur, rec.ir_startino, rec.ir_freecount,
963 be32_add_cpu(&agi->agi_freecount, -1);
964 xfs_ialloc_log_agi(tp, agbp, XFS_AGI_FREECOUNT);
965 down_read(&mp->m_peraglock);
966 mp->m_perag[tagno].pagi_freecount--;
967 up_read(&mp->m_peraglock);
969 if (cur->bc_nlevels == 1) {
972 if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i)))
975 if ((error = xfs_inobt_get_rec(cur, &rec.ir_startino,
976 &rec.ir_freecount, &rec.ir_free, &i)))
978 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
979 freecount += rec.ir_freecount;
980 if ((error = xfs_btree_increment(cur, 0, &i)))
983 ASSERT(freecount == be32_to_cpu(agi->agi_freecount) ||
984 XFS_FORCED_SHUTDOWN(mp));
987 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
988 xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, -1);
992 xfs_btree_del_cursor(tcur, XFS_BTREE_ERROR);
994 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
999 * Free disk inode. Carefully avoids touching the incore inode, all
1000 * manipulations incore are the caller's responsibility.
1001 * The on-disk inode is not changed by this operation, only the
1002 * btree (free inode mask) is changed.
1006 xfs_trans_t *tp, /* transaction pointer */
1007 xfs_ino_t inode, /* inode to be freed */
1008 xfs_bmap_free_t *flist, /* extents to free */
1009 int *delete, /* set if inode cluster was deleted */
1010 xfs_ino_t *first_ino) /* first inode in deleted cluster */
1013 xfs_agblock_t agbno; /* block number containing inode */
1014 xfs_buf_t *agbp; /* buffer containing allocation group header */
1015 xfs_agino_t agino; /* inode number relative to allocation group */
1016 xfs_agnumber_t agno; /* allocation group number */
1017 xfs_agi_t *agi; /* allocation group header */
1018 xfs_btree_cur_t *cur; /* inode btree cursor */
1019 int error; /* error return value */
1020 int i; /* result code */
1021 int ilen; /* inodes in an inode cluster */
1022 xfs_mount_t *mp; /* mount structure for filesystem */
1023 int off; /* offset of inode in inode chunk */
1024 xfs_inobt_rec_incore_t rec; /* btree record */
1029 * Break up inode number into its components.
1031 agno = XFS_INO_TO_AGNO(mp, inode);
1032 if (agno >= mp->m_sb.sb_agcount) {
1034 "xfs_difree: agno >= mp->m_sb.sb_agcount (%d >= %d) on %s. Returning EINVAL.",
1035 agno, mp->m_sb.sb_agcount, mp->m_fsname);
1037 return XFS_ERROR(EINVAL);
1039 agino = XFS_INO_TO_AGINO(mp, inode);
1040 if (inode != XFS_AGINO_TO_INO(mp, agno, agino)) {
1042 "xfs_difree: inode != XFS_AGINO_TO_INO() "
1043 "(%llu != %llu) on %s. Returning EINVAL.",
1044 (unsigned long long)inode,
1045 (unsigned long long)XFS_AGINO_TO_INO(mp, agno, agino),
1048 return XFS_ERROR(EINVAL);
1050 agbno = XFS_AGINO_TO_AGBNO(mp, agino);
1051 if (agbno >= mp->m_sb.sb_agblocks) {
1053 "xfs_difree: agbno >= mp->m_sb.sb_agblocks (%d >= %d) on %s. Returning EINVAL.",
1054 agbno, mp->m_sb.sb_agblocks, mp->m_fsname);
1056 return XFS_ERROR(EINVAL);
1059 * Get the allocation group header.
1061 down_read(&mp->m_peraglock);
1062 error = xfs_ialloc_read_agi(mp, tp, agno, &agbp);
1063 up_read(&mp->m_peraglock);
1066 "xfs_difree: xfs_ialloc_read_agi() returned an error %d on %s. Returning error.",
1067 error, mp->m_fsname);
1070 agi = XFS_BUF_TO_AGI(agbp);
1071 ASSERT(be32_to_cpu(agi->agi_magicnum) == XFS_AGI_MAGIC);
1072 ASSERT(agbno < be32_to_cpu(agi->agi_length));
1074 * Initialize the cursor.
1076 cur = xfs_inobt_init_cursor(mp, tp, agbp, agno);
1078 if (cur->bc_nlevels == 1) {
1081 if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i)))
1084 if ((error = xfs_inobt_get_rec(cur, &rec.ir_startino,
1085 &rec.ir_freecount, &rec.ir_free, &i)))
1088 freecount += rec.ir_freecount;
1089 if ((error = xfs_btree_increment(cur, 0, &i)))
1093 ASSERT(freecount == be32_to_cpu(agi->agi_freecount) ||
1094 XFS_FORCED_SHUTDOWN(mp));
1098 * Look for the entry describing this inode.
1100 if ((error = xfs_inobt_lookup_le(cur, agino, 0, 0, &i))) {
1102 "xfs_difree: xfs_inobt_lookup_le returned() an error %d on %s. Returning error.",
1103 error, mp->m_fsname);
1106 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
1107 if ((error = xfs_inobt_get_rec(cur, &rec.ir_startino, &rec.ir_freecount,
1108 &rec.ir_free, &i))) {
1110 "xfs_difree: xfs_inobt_get_rec() returned an error %d on %s. Returning error.",
1111 error, mp->m_fsname);
1114 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
1116 * Get the offset in the inode chunk.
1118 off = agino - rec.ir_startino;
1119 ASSERT(off >= 0 && off < XFS_INODES_PER_CHUNK);
1120 ASSERT(!XFS_INOBT_IS_FREE(&rec, off));
1122 * Mark the inode free & increment the count.
1124 XFS_INOBT_SET_FREE(&rec, off);
1128 * When an inode cluster is free, it becomes eligible for removal
1130 if (!(mp->m_flags & XFS_MOUNT_IKEEP) &&
1131 (rec.ir_freecount == XFS_IALLOC_INODES(mp))) {
1134 *first_ino = XFS_AGINO_TO_INO(mp, agno, rec.ir_startino);
1137 * Remove the inode cluster from the AGI B+Tree, adjust the
1138 * AGI and Superblock inode counts, and mark the disk space
1139 * to be freed when the transaction is committed.
1141 ilen = XFS_IALLOC_INODES(mp);
1142 be32_add_cpu(&agi->agi_count, -ilen);
1143 be32_add_cpu(&agi->agi_freecount, -(ilen - 1));
1144 xfs_ialloc_log_agi(tp, agbp, XFS_AGI_COUNT | XFS_AGI_FREECOUNT);
1145 down_read(&mp->m_peraglock);
1146 mp->m_perag[agno].pagi_freecount -= ilen - 1;
1147 up_read(&mp->m_peraglock);
1148 xfs_trans_mod_sb(tp, XFS_TRANS_SB_ICOUNT, -ilen);
1149 xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, -(ilen - 1));
1151 if ((error = xfs_inobt_delete(cur, &i))) {
1152 cmn_err(CE_WARN, "xfs_difree: xfs_inobt_delete returned an error %d on %s.\n",
1153 error, mp->m_fsname);
1157 xfs_bmap_add_free(XFS_AGB_TO_FSB(mp,
1158 agno, XFS_INO_TO_AGBNO(mp,rec.ir_startino)),
1159 XFS_IALLOC_BLOCKS(mp), flist, mp);
1163 if ((error = xfs_inobt_update(cur, rec.ir_startino, rec.ir_freecount, rec.ir_free))) {
1165 "xfs_difree: xfs_inobt_update() returned an error %d on %s. Returning error.",
1166 error, mp->m_fsname);
1170 * Change the inode free counts and log the ag/sb changes.
1172 be32_add_cpu(&agi->agi_freecount, 1);
1173 xfs_ialloc_log_agi(tp, agbp, XFS_AGI_FREECOUNT);
1174 down_read(&mp->m_peraglock);
1175 mp->m_perag[agno].pagi_freecount++;
1176 up_read(&mp->m_peraglock);
1177 xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, 1);
1181 if (cur->bc_nlevels == 1) {
1184 if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i)))
1187 if ((error = xfs_inobt_get_rec(cur,
1193 freecount += rec.ir_freecount;
1194 if ((error = xfs_btree_increment(cur, 0, &i)))
1198 ASSERT(freecount == be32_to_cpu(agi->agi_freecount) ||
1199 XFS_FORCED_SHUTDOWN(mp));
1202 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
1206 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
1211 * Return the location of the inode in bno/off, for mapping it into a buffer.
1216 xfs_mount_t *mp, /* file system mount structure */
1217 xfs_trans_t *tp, /* transaction pointer */
1218 xfs_ino_t ino, /* inode to locate */
1219 xfs_fsblock_t *bno, /* output: block containing inode */
1220 int *len, /* output: num blocks in inode cluster */
1221 int *off, /* output: index in block of inode */
1222 uint flags) /* flags concerning inode lookup */
1224 xfs_agblock_t agbno; /* block number of inode in the alloc group */
1225 xfs_buf_t *agbp; /* agi buffer */
1226 xfs_agino_t agino; /* inode number within alloc group */
1227 xfs_agnumber_t agno; /* allocation group number */
1228 int blks_per_cluster; /* num blocks per inode cluster */
1229 xfs_agblock_t chunk_agbno; /* first block in inode chunk */
1230 xfs_agino_t chunk_agino; /* first agino in inode chunk */
1231 __int32_t chunk_cnt; /* count of free inodes in chunk */
1232 xfs_inofree_t chunk_free; /* mask of free inodes in chunk */
1233 xfs_agblock_t cluster_agbno; /* first block in inode cluster */
1234 xfs_btree_cur_t *cur; /* inode btree cursor */
1235 int error; /* error code */
1236 int i; /* temp state */
1237 int offset; /* index of inode in its buffer */
1238 int offset_agbno; /* blks from chunk start to inode */
1240 ASSERT(ino != NULLFSINO);
1242 * Split up the inode number into its parts.
1244 agno = XFS_INO_TO_AGNO(mp, ino);
1245 agino = XFS_INO_TO_AGINO(mp, ino);
1246 agbno = XFS_AGINO_TO_AGBNO(mp, agino);
1247 if (agno >= mp->m_sb.sb_agcount || agbno >= mp->m_sb.sb_agblocks ||
1248 ino != XFS_AGINO_TO_INO(mp, agno, agino)) {
1250 /* no diagnostics for bulkstat, ino comes from userspace */
1251 if (flags & XFS_IMAP_BULKSTAT)
1252 return XFS_ERROR(EINVAL);
1253 if (agno >= mp->m_sb.sb_agcount) {
1254 xfs_fs_cmn_err(CE_ALERT, mp,
1255 "xfs_dilocate: agno (%d) >= "
1256 "mp->m_sb.sb_agcount (%d)",
1257 agno, mp->m_sb.sb_agcount);
1259 if (agbno >= mp->m_sb.sb_agblocks) {
1260 xfs_fs_cmn_err(CE_ALERT, mp,
1261 "xfs_dilocate: agbno (0x%llx) >= "
1262 "mp->m_sb.sb_agblocks (0x%lx)",
1263 (unsigned long long) agbno,
1264 (unsigned long) mp->m_sb.sb_agblocks);
1266 if (ino != XFS_AGINO_TO_INO(mp, agno, agino)) {
1267 xfs_fs_cmn_err(CE_ALERT, mp,
1268 "xfs_dilocate: ino (0x%llx) != "
1269 "XFS_AGINO_TO_INO(mp, agno, agino) "
1271 ino, XFS_AGINO_TO_INO(mp, agno, agino));
1275 return XFS_ERROR(EINVAL);
1277 if ((mp->m_sb.sb_blocksize >= XFS_INODE_CLUSTER_SIZE(mp)) ||
1278 !(flags & XFS_IMAP_LOOKUP)) {
1279 offset = XFS_INO_TO_OFFSET(mp, ino);
1280 ASSERT(offset < mp->m_sb.sb_inopblock);
1281 *bno = XFS_AGB_TO_FSB(mp, agno, agbno);
1286 blks_per_cluster = XFS_INODE_CLUSTER_SIZE(mp) >> mp->m_sb.sb_blocklog;
1287 if (*bno != NULLFSBLOCK) {
1288 offset = XFS_INO_TO_OFFSET(mp, ino);
1289 ASSERT(offset < mp->m_sb.sb_inopblock);
1290 cluster_agbno = XFS_FSB_TO_AGBNO(mp, *bno);
1291 *off = ((agbno - cluster_agbno) * mp->m_sb.sb_inopblock) +
1293 *len = blks_per_cluster;
1296 if (mp->m_inoalign_mask) {
1297 offset_agbno = agbno & mp->m_inoalign_mask;
1298 chunk_agbno = agbno - offset_agbno;
1300 down_read(&mp->m_peraglock);
1301 error = xfs_ialloc_read_agi(mp, tp, agno, &agbp);
1302 up_read(&mp->m_peraglock);
1305 xfs_fs_cmn_err(CE_ALERT, mp, "xfs_dilocate: "
1306 "xfs_ialloc_read_agi() returned "
1307 "error %d, agno %d",
1312 cur = xfs_inobt_init_cursor(mp, tp, agbp, agno);
1313 if ((error = xfs_inobt_lookup_le(cur, agino, 0, 0, &i))) {
1315 xfs_fs_cmn_err(CE_ALERT, mp, "xfs_dilocate: "
1316 "xfs_inobt_lookup_le() failed");
1320 if ((error = xfs_inobt_get_rec(cur, &chunk_agino, &chunk_cnt,
1321 &chunk_free, &i))) {
1323 xfs_fs_cmn_err(CE_ALERT, mp, "xfs_dilocate: "
1324 "xfs_inobt_get_rec() failed");
1330 xfs_fs_cmn_err(CE_ALERT, mp, "xfs_dilocate: "
1331 "xfs_inobt_get_rec() failed");
1333 error = XFS_ERROR(EINVAL);
1335 xfs_trans_brelse(tp, agbp);
1336 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
1339 chunk_agbno = XFS_AGINO_TO_AGBNO(mp, chunk_agino);
1340 offset_agbno = agbno - chunk_agbno;
1342 ASSERT(agbno >= chunk_agbno);
1343 cluster_agbno = chunk_agbno +
1344 ((offset_agbno / blks_per_cluster) * blks_per_cluster);
1345 offset = ((agbno - cluster_agbno) * mp->m_sb.sb_inopblock) +
1346 XFS_INO_TO_OFFSET(mp, ino);
1347 *bno = XFS_AGB_TO_FSB(mp, agno, cluster_agbno);
1349 *len = blks_per_cluster;
1352 xfs_trans_brelse(tp, agbp);
1353 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
1358 * Compute and fill in value of m_in_maxlevels.
1361 xfs_ialloc_compute_maxlevels(
1362 xfs_mount_t *mp) /* file system mount structure */
1370 maxleafents = (1LL << XFS_INO_AGINO_BITS(mp)) >>
1371 XFS_INODES_PER_CHUNK_LOG;
1372 minleafrecs = mp->m_alloc_mnr[0];
1373 minnoderecs = mp->m_alloc_mnr[1];
1374 maxblocks = (maxleafents + minleafrecs - 1) / minleafrecs;
1375 for (level = 1; maxblocks > 1; level++)
1376 maxblocks = (maxblocks + minnoderecs - 1) / minnoderecs;
1377 mp->m_in_maxlevels = level;
1381 * Log specified fields for the ag hdr (inode section)
1385 xfs_trans_t *tp, /* transaction pointer */
1386 xfs_buf_t *bp, /* allocation group header buffer */
1387 int fields) /* bitmask of fields to log */
1389 int first; /* first byte number */
1390 int last; /* last byte number */
1391 static const short offsets[] = { /* field starting offsets */
1392 /* keep in sync with bit definitions */
1393 offsetof(xfs_agi_t, agi_magicnum),
1394 offsetof(xfs_agi_t, agi_versionnum),
1395 offsetof(xfs_agi_t, agi_seqno),
1396 offsetof(xfs_agi_t, agi_length),
1397 offsetof(xfs_agi_t, agi_count),
1398 offsetof(xfs_agi_t, agi_root),
1399 offsetof(xfs_agi_t, agi_level),
1400 offsetof(xfs_agi_t, agi_freecount),
1401 offsetof(xfs_agi_t, agi_newino),
1402 offsetof(xfs_agi_t, agi_dirino),
1403 offsetof(xfs_agi_t, agi_unlinked),
1407 xfs_agi_t *agi; /* allocation group header */
1409 agi = XFS_BUF_TO_AGI(bp);
1410 ASSERT(be32_to_cpu(agi->agi_magicnum) == XFS_AGI_MAGIC);
1413 * Compute byte offsets for the first and last fields.
1415 xfs_btree_offsets(fields, offsets, XFS_AGI_NUM_BITS, &first, &last);
1417 * Log the allocation group inode header buffer.
1419 xfs_trans_log_buf(tp, bp, first, last);
1423 * Read in the allocation group header (inode allocation section)
1426 xfs_ialloc_read_agi(
1427 xfs_mount_t *mp, /* file system mount structure */
1428 xfs_trans_t *tp, /* transaction pointer */
1429 xfs_agnumber_t agno, /* allocation group number */
1430 xfs_buf_t **bpp) /* allocation group hdr buf */
1432 xfs_agi_t *agi; /* allocation group header */
1433 int agi_ok; /* agi is consistent */
1434 xfs_buf_t *bp; /* allocation group hdr buf */
1435 xfs_perag_t *pag; /* per allocation group data */
1438 ASSERT(agno != NULLAGNUMBER);
1439 error = xfs_trans_read_buf(
1440 mp, tp, mp->m_ddev_targp,
1441 XFS_AG_DADDR(mp, agno, XFS_AGI_DADDR(mp)),
1442 XFS_FSS_TO_BB(mp, 1), 0, &bp);
1445 ASSERT(bp && !XFS_BUF_GETERROR(bp));
1448 * Validate the magic number of the agi block.
1450 agi = XFS_BUF_TO_AGI(bp);
1452 be32_to_cpu(agi->agi_magicnum) == XFS_AGI_MAGIC &&
1453 XFS_AGI_GOOD_VERSION(be32_to_cpu(agi->agi_versionnum));
1454 if (unlikely(XFS_TEST_ERROR(!agi_ok, mp, XFS_ERRTAG_IALLOC_READ_AGI,
1455 XFS_RANDOM_IALLOC_READ_AGI))) {
1456 XFS_CORRUPTION_ERROR("xfs_ialloc_read_agi", XFS_ERRLEVEL_LOW,
1458 xfs_trans_brelse(tp, bp);
1459 return XFS_ERROR(EFSCORRUPTED);
1461 pag = &mp->m_perag[agno];
1462 if (!pag->pagi_init) {
1463 pag->pagi_freecount = be32_to_cpu(agi->agi_freecount);
1464 pag->pagi_count = be32_to_cpu(agi->agi_count);
1468 * It's possible for these to be out of sync if
1469 * we are in the middle of a forced shutdown.
1471 ASSERT(pag->pagi_freecount == be32_to_cpu(agi->agi_freecount) ||
1472 XFS_FORCED_SHUTDOWN(mp));
1479 for (i = 0; i < XFS_AGI_UNLINKED_BUCKETS; i++)
1480 ASSERT(agi->agi_unlinked[i]);
1484 XFS_BUF_SET_VTYPE_REF(bp, B_FS_AGI, XFS_AGI_REF);
1490 * Read in the agi to initialise the per-ag data in the mount structure
1493 xfs_ialloc_pagi_init(
1494 xfs_mount_t *mp, /* file system mount structure */
1495 xfs_trans_t *tp, /* transaction pointer */
1496 xfs_agnumber_t agno) /* allocation group number */
1498 xfs_buf_t *bp = NULL;
1501 error = xfs_ialloc_read_agi(mp, tp, agno, &bp);
1505 xfs_trans_brelse(tp, bp);