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"
46 * Allocation group level functions.
49 xfs_ialloc_cluster_alignment(
50 xfs_alloc_arg_t *args)
52 if (xfs_sb_version_hasalign(&args->mp->m_sb) &&
53 args->mp->m_sb.sb_inoalignmt >=
54 XFS_B_TO_FSBT(args->mp, XFS_INODE_CLUSTER_SIZE(args->mp)))
55 return args->mp->m_sb.sb_inoalignmt;
60 * Lookup the record equal to ino in the btree given by cur.
62 STATIC int /* error */
64 struct xfs_btree_cur *cur, /* btree cursor */
65 xfs_agino_t ino, /* starting inode of chunk */
66 __int32_t fcnt, /* free inode count */
67 xfs_inofree_t free, /* free inode mask */
68 int *stat) /* success/failure */
70 cur->bc_rec.i.ir_startino = ino;
71 cur->bc_rec.i.ir_freecount = fcnt;
72 cur->bc_rec.i.ir_free = free;
73 return xfs_btree_lookup(cur, XFS_LOOKUP_EQ, stat);
77 * Lookup the first record greater than or equal to ino
78 * in the btree given by cur.
82 struct xfs_btree_cur *cur, /* btree cursor */
83 xfs_agino_t ino, /* starting inode of chunk */
84 __int32_t fcnt, /* free inode count */
85 xfs_inofree_t free, /* free inode mask */
86 int *stat) /* success/failure */
88 cur->bc_rec.i.ir_startino = ino;
89 cur->bc_rec.i.ir_freecount = fcnt;
90 cur->bc_rec.i.ir_free = free;
91 return xfs_btree_lookup(cur, XFS_LOOKUP_GE, stat);
95 * Lookup the first record less than or equal to ino
96 * in the btree given by cur.
100 struct xfs_btree_cur *cur, /* btree cursor */
101 xfs_agino_t ino, /* starting inode of chunk */
102 __int32_t fcnt, /* free inode count */
103 xfs_inofree_t free, /* free inode mask */
104 int *stat) /* success/failure */
106 cur->bc_rec.i.ir_startino = ino;
107 cur->bc_rec.i.ir_freecount = fcnt;
108 cur->bc_rec.i.ir_free = free;
109 return xfs_btree_lookup(cur, XFS_LOOKUP_LE, stat);
113 * Update the record referred to by cur to the value given
114 * by [ino, fcnt, free].
115 * This either works (return 0) or gets an EFSCORRUPTED error.
117 STATIC int /* error */
119 struct xfs_btree_cur *cur, /* btree cursor */
120 xfs_agino_t ino, /* starting inode of chunk */
121 __int32_t fcnt, /* free inode count */
122 xfs_inofree_t free) /* free inode mask */
124 union xfs_btree_rec rec;
126 rec.inobt.ir_startino = cpu_to_be32(ino);
127 rec.inobt.ir_freecount = cpu_to_be32(fcnt);
128 rec.inobt.ir_free = cpu_to_be64(free);
129 return xfs_btree_update(cur, &rec);
133 * Get the data from the pointed-to record.
137 struct xfs_btree_cur *cur, /* btree cursor */
138 xfs_inobt_rec_incore_t *irec, /* btree record */
139 int *stat) /* output: success/failure */
141 union xfs_btree_rec *rec;
144 error = xfs_btree_get_rec(cur, &rec, stat);
145 if (!error && *stat == 1) {
146 irec->ir_startino = be32_to_cpu(rec->inobt.ir_startino);
147 irec->ir_freecount = be32_to_cpu(rec->inobt.ir_freecount);
148 irec->ir_free = be64_to_cpu(rec->inobt.ir_free);
154 * Initialise a new set of inodes.
157 xfs_ialloc_inode_init(
158 struct xfs_mount *mp,
159 struct xfs_trans *tp,
162 xfs_agblock_t length,
165 struct xfs_buf *fbuf;
166 struct xfs_dinode *free;
167 int blks_per_cluster, nbufs, ninodes;
173 * Loop over the new block(s), filling in the inodes.
174 * For small block sizes, manipulate the inodes in buffers
175 * which are multiples of the blocks size.
177 if (mp->m_sb.sb_blocksize >= XFS_INODE_CLUSTER_SIZE(mp)) {
178 blks_per_cluster = 1;
180 ninodes = mp->m_sb.sb_inopblock;
182 blks_per_cluster = XFS_INODE_CLUSTER_SIZE(mp) /
183 mp->m_sb.sb_blocksize;
184 nbufs = length / blks_per_cluster;
185 ninodes = blks_per_cluster * mp->m_sb.sb_inopblock;
189 * Figure out what version number to use in the inodes we create.
190 * If the superblock version has caught up to the one that supports
191 * the new inode format, then use the new inode version. Otherwise
192 * use the old version so that old kernels will continue to be
193 * able to use the file system.
195 if (xfs_sb_version_hasnlink(&mp->m_sb))
200 for (j = 0; j < nbufs; j++) {
204 d = XFS_AGB_TO_DADDR(mp, agno, agbno + (j * blks_per_cluster));
205 fbuf = xfs_trans_get_buf(tp, mp->m_ddev_targp, d,
206 mp->m_bsize * blks_per_cluster,
209 ASSERT(!XFS_BUF_GETERROR(fbuf));
212 * Initialize all inodes in this buffer and then log them.
214 * XXX: It would be much better if we had just one transaction
215 * to log a whole cluster of inodes instead of all the
216 * individual transactions causing a lot of log traffic.
218 xfs_biozero(fbuf, 0, ninodes << mp->m_sb.sb_inodelog);
219 for (i = 0; i < ninodes; i++) {
220 int ioffset = i << mp->m_sb.sb_inodelog;
221 uint isize = sizeof(struct xfs_dinode);
223 free = xfs_make_iptr(mp, fbuf, i);
224 free->di_magic = cpu_to_be16(XFS_DINODE_MAGIC);
225 free->di_version = version;
226 free->di_gen = cpu_to_be32(gen);
227 free->di_next_unlinked = cpu_to_be32(NULLAGINO);
228 xfs_trans_log_buf(tp, fbuf, ioffset, ioffset + isize - 1);
230 xfs_trans_inode_alloc_buf(tp, fbuf);
235 * Allocate new inodes in the allocation group specified by agbp.
236 * Return 0 for success, else error code.
238 STATIC int /* error code or 0 */
240 xfs_trans_t *tp, /* transaction pointer */
241 xfs_buf_t *agbp, /* alloc group buffer */
244 xfs_agi_t *agi; /* allocation group header */
245 xfs_alloc_arg_t args; /* allocation argument structure */
246 xfs_btree_cur_t *cur; /* inode btree cursor */
250 xfs_agino_t newino; /* new first inode's number */
251 xfs_agino_t newlen; /* new number of inodes */
252 xfs_agino_t thisino; /* current inode number, for loop */
253 int isaligned = 0; /* inode allocation at stripe unit */
257 args.mp = tp->t_mountp;
260 * Locking will ensure that we don't have two callers in here
263 newlen = XFS_IALLOC_INODES(args.mp);
264 if (args.mp->m_maxicount &&
265 args.mp->m_sb.sb_icount + newlen > args.mp->m_maxicount)
266 return XFS_ERROR(ENOSPC);
267 args.minlen = args.maxlen = XFS_IALLOC_BLOCKS(args.mp);
269 * First try to allocate inodes contiguous with the last-allocated
270 * chunk of inodes. If the filesystem is striped, this will fill
271 * an entire stripe unit with inodes.
273 agi = XFS_BUF_TO_AGI(agbp);
274 newino = be32_to_cpu(agi->agi_newino);
275 agno = be32_to_cpu(agi->agi_seqno);
276 args.agbno = XFS_AGINO_TO_AGBNO(args.mp, newino) +
277 XFS_IALLOC_BLOCKS(args.mp);
278 if (likely(newino != NULLAGINO &&
279 (args.agbno < be32_to_cpu(agi->agi_length)))) {
280 args.fsbno = XFS_AGB_TO_FSB(args.mp, agno, args.agbno);
281 args.type = XFS_ALLOCTYPE_THIS_BNO;
282 args.mod = args.total = args.wasdel = args.isfl =
283 args.userdata = args.minalignslop = 0;
287 * We need to take into account alignment here to ensure that
288 * we don't modify the free list if we fail to have an exact
289 * block. If we don't have an exact match, and every oher
290 * attempt allocation attempt fails, we'll end up cancelling
291 * a dirty transaction and shutting down.
293 * For an exact allocation, alignment must be 1,
294 * however we need to take cluster alignment into account when
295 * fixing up the freelist. Use the minalignslop field to
296 * indicate that extra blocks might be required for alignment,
297 * but not to use them in the actual exact allocation.
300 args.minalignslop = xfs_ialloc_cluster_alignment(&args) - 1;
302 /* Allow space for the inode btree to split. */
303 args.minleft = args.mp->m_in_maxlevels - 1;
304 if ((error = xfs_alloc_vextent(&args)))
307 args.fsbno = NULLFSBLOCK;
309 if (unlikely(args.fsbno == NULLFSBLOCK)) {
311 * Set the alignment for the allocation.
312 * If stripe alignment is turned on then align at stripe unit
314 * If the cluster size is smaller than a filesystem block
315 * then we're doing I/O for inodes in filesystem block size
316 * pieces, so don't need alignment anyway.
319 if (args.mp->m_sinoalign) {
320 ASSERT(!(args.mp->m_flags & XFS_MOUNT_NOALIGN));
321 args.alignment = args.mp->m_dalign;
324 args.alignment = xfs_ialloc_cluster_alignment(&args);
326 * Need to figure out where to allocate the inode blocks.
327 * Ideally they should be spaced out through the a.g.
328 * For now, just allocate blocks up front.
330 args.agbno = be32_to_cpu(agi->agi_root);
331 args.fsbno = XFS_AGB_TO_FSB(args.mp, agno, args.agbno);
333 * Allocate a fixed-size extent of inodes.
335 args.type = XFS_ALLOCTYPE_NEAR_BNO;
336 args.mod = args.total = args.wasdel = args.isfl =
337 args.userdata = args.minalignslop = 0;
340 * Allow space for the inode btree to split.
342 args.minleft = args.mp->m_in_maxlevels - 1;
343 if ((error = xfs_alloc_vextent(&args)))
348 * If stripe alignment is turned on, then try again with cluster
351 if (isaligned && args.fsbno == NULLFSBLOCK) {
352 args.type = XFS_ALLOCTYPE_NEAR_BNO;
353 args.agbno = be32_to_cpu(agi->agi_root);
354 args.fsbno = XFS_AGB_TO_FSB(args.mp, agno, args.agbno);
355 args.alignment = xfs_ialloc_cluster_alignment(&args);
356 if ((error = xfs_alloc_vextent(&args)))
360 if (args.fsbno == NULLFSBLOCK) {
364 ASSERT(args.len == args.minlen);
367 * Stamp and write the inode buffers.
369 * Seed the new inode cluster with a random generation number. This
370 * prevents short-term reuse of generation numbers if a chunk is
371 * freed and then immediately reallocated. We use random numbers
372 * rather than a linear progression to prevent the next generation
373 * number from being easily guessable.
375 xfs_ialloc_inode_init(args.mp, tp, agno, args.agbno, args.len,
379 * Convert the results.
381 newino = XFS_OFFBNO_TO_AGINO(args.mp, args.agbno, 0);
382 be32_add_cpu(&agi->agi_count, newlen);
383 be32_add_cpu(&agi->agi_freecount, newlen);
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);
390 * Insert records describing the new inode chunk into the btree.
392 cur = xfs_inobt_init_cursor(args.mp, tp, agbp, agno);
393 for (thisino = newino;
394 thisino < newino + newlen;
395 thisino += XFS_INODES_PER_CHUNK) {
396 if ((error = xfs_inobt_lookup_eq(cur, thisino,
397 XFS_INODES_PER_CHUNK, XFS_INOBT_ALL_FREE, &i))) {
398 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
402 if ((error = xfs_btree_insert(cur, &i))) {
403 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
408 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
410 * Log allocation group header fields
412 xfs_ialloc_log_agi(tp, agbp,
413 XFS_AGI_COUNT | XFS_AGI_FREECOUNT | XFS_AGI_NEWINO);
415 * Modify/log superblock values for inode count and inode free count.
417 xfs_trans_mod_sb(tp, XFS_TRANS_SB_ICOUNT, (long)newlen);
418 xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, (long)newlen);
423 STATIC_INLINE xfs_agnumber_t
429 spin_lock(&mp->m_agirotor_lock);
430 agno = mp->m_agirotor;
431 if (++mp->m_agirotor == mp->m_maxagi)
433 spin_unlock(&mp->m_agirotor_lock);
439 * Select an allocation group to look for a free inode in, based on the parent
440 * inode and then mode. Return the allocation group buffer.
442 STATIC xfs_buf_t * /* allocation group buffer */
443 xfs_ialloc_ag_select(
444 xfs_trans_t *tp, /* transaction pointer */
445 xfs_ino_t parent, /* parent directory inode number */
446 mode_t mode, /* bits set to indicate file type */
447 int okalloc) /* ok to allocate more space */
449 xfs_buf_t *agbp; /* allocation group header buffer */
450 xfs_agnumber_t agcount; /* number of ag's in the filesystem */
451 xfs_agnumber_t agno; /* current ag number */
452 int flags; /* alloc buffer locking flags */
453 xfs_extlen_t ineed; /* blocks needed for inode allocation */
454 xfs_extlen_t longest = 0; /* longest extent available */
455 xfs_mount_t *mp; /* mount point structure */
456 int needspace; /* file mode implies space allocated */
457 xfs_perag_t *pag; /* per allocation group data */
458 xfs_agnumber_t pagno; /* parent (starting) ag number */
461 * Files of these types need at least one block if length > 0
462 * (and they won't fit in the inode, but that's hard to figure out).
464 needspace = S_ISDIR(mode) || S_ISREG(mode) || S_ISLNK(mode);
466 agcount = mp->m_maxagi;
468 pagno = xfs_ialloc_next_ag(mp);
470 pagno = XFS_INO_TO_AGNO(mp, parent);
471 if (pagno >= agcount)
474 ASSERT(pagno < agcount);
476 * Loop through allocation groups, looking for one with a little
477 * free space in it. Note we don't look for free inodes, exactly.
478 * Instead, we include whether there is a need to allocate inodes
479 * to mean that blocks must be allocated for them,
480 * if none are currently free.
483 flags = XFS_ALLOC_FLAG_TRYLOCK;
484 down_read(&mp->m_peraglock);
486 pag = &mp->m_perag[agno];
487 if (!pag->pagi_init) {
488 if (xfs_ialloc_read_agi(mp, tp, agno, &agbp)) {
495 if (!pag->pagi_inodeok) {
496 xfs_ialloc_next_ag(mp);
501 * Is there enough free space for the file plus a block
502 * of inodes (if we need to allocate some)?
504 ineed = pag->pagi_freecount ? 0 : XFS_IALLOC_BLOCKS(mp);
505 if (ineed && !pag->pagf_init) {
507 xfs_ialloc_read_agi(mp, tp, agno, &agbp)) {
511 (void)xfs_alloc_pagf_init(mp, tp, agno, flags);
513 if (!ineed || pag->pagf_init) {
514 if (ineed && !(longest = pag->pagf_longest))
515 longest = pag->pagf_flcount > 0;
517 (pag->pagf_freeblks >= needspace + ineed &&
521 xfs_ialloc_read_agi(mp, tp, agno, &agbp)) {
525 up_read(&mp->m_peraglock);
531 xfs_trans_brelse(tp, agbp);
534 * No point in iterating over the rest, if we're shutting
537 if (XFS_FORCED_SHUTDOWN(mp)) {
538 up_read(&mp->m_peraglock);
546 up_read(&mp->m_peraglock);
555 * Visible inode allocation functions.
559 * Allocate an inode on disk.
560 * Mode is used to tell whether the new inode will need space, and whether
563 * The arguments IO_agbp and alloc_done are defined to work within
564 * the constraint of one allocation per transaction.
565 * xfs_dialloc() is designed to be called twice if it has to do an
566 * allocation to make more free inodes. On the first call,
567 * IO_agbp should be set to NULL. If an inode is available,
568 * i.e., xfs_dialloc() did not need to do an allocation, an inode
569 * number is returned. In this case, IO_agbp would be set to the
570 * current ag_buf and alloc_done set to false.
571 * If an allocation needed to be done, xfs_dialloc would return
572 * the current ag_buf in IO_agbp and set alloc_done to true.
573 * The caller should then commit the current transaction, allocate a new
574 * transaction, and call xfs_dialloc() again, passing in the previous
575 * value of IO_agbp. IO_agbp should be held across the transactions.
576 * Since the agbp is locked across the two calls, the second call is
577 * guaranteed to have a free inode available.
579 * Once we successfully pick an inode its number is returned and the
580 * on-disk data structures are updated. The inode itself is not read
581 * in, since doing so would break ordering constraints with xfs_reclaim.
585 xfs_trans_t *tp, /* transaction pointer */
586 xfs_ino_t parent, /* parent inode (directory) */
587 mode_t mode, /* mode bits for new inode */
588 int okalloc, /* ok to allocate more space */
589 xfs_buf_t **IO_agbp, /* in/out ag header's buffer */
590 boolean_t *alloc_done, /* true if we needed to replenish
592 xfs_ino_t *inop) /* inode number allocated */
594 xfs_agnumber_t agcount; /* number of allocation groups */
595 xfs_buf_t *agbp; /* allocation group header's buffer */
596 xfs_agnumber_t agno; /* allocation group number */
597 xfs_agi_t *agi; /* allocation group header structure */
598 xfs_btree_cur_t *cur; /* inode allocation btree cursor */
599 int error; /* error return value */
600 int i; /* result code */
601 int ialloced; /* inode allocation status */
602 int noroom = 0; /* no space for inode blk allocation */
603 xfs_ino_t ino; /* fs-relative inode to be returned */
605 int j; /* result code */
606 xfs_mount_t *mp; /* file system mount structure */
607 int offset; /* index of inode in chunk */
608 xfs_agino_t pagino; /* parent's a.g. relative inode # */
609 xfs_agnumber_t pagno; /* parent's allocation group number */
610 xfs_inobt_rec_incore_t rec; /* inode allocation record */
611 xfs_agnumber_t tagno; /* testing allocation group number */
612 xfs_btree_cur_t *tcur; /* temp cursor */
613 xfs_inobt_rec_incore_t trec; /* temp inode allocation record */
616 if (*IO_agbp == NULL) {
618 * We do not have an agbp, so select an initial allocation
619 * group for inode allocation.
621 agbp = xfs_ialloc_ag_select(tp, parent, mode, okalloc);
623 * Couldn't find an allocation group satisfying the
630 agi = XFS_BUF_TO_AGI(agbp);
631 ASSERT(be32_to_cpu(agi->agi_magicnum) == XFS_AGI_MAGIC);
634 * Continue where we left off before. In this case, we
635 * know that the allocation group has free inodes.
638 agi = XFS_BUF_TO_AGI(agbp);
639 ASSERT(be32_to_cpu(agi->agi_magicnum) == XFS_AGI_MAGIC);
640 ASSERT(be32_to_cpu(agi->agi_freecount) > 0);
643 agcount = mp->m_sb.sb_agcount;
644 agno = be32_to_cpu(agi->agi_seqno);
646 pagno = XFS_INO_TO_AGNO(mp, parent);
647 pagino = XFS_INO_TO_AGINO(mp, parent);
650 * If we have already hit the ceiling of inode blocks then clear
651 * okalloc so we scan all available agi structures for a free
655 if (mp->m_maxicount &&
656 mp->m_sb.sb_icount + XFS_IALLOC_INODES(mp) > mp->m_maxicount) {
662 * Loop until we find an allocation group that either has free inodes
663 * or in which we can allocate some inodes. Iterate through the
664 * allocation groups upward, wrapping at the end.
666 *alloc_done = B_FALSE;
667 while (!agi->agi_freecount) {
669 * Don't do anything if we're not supposed to allocate
670 * any blocks, just go on to the next ag.
674 * Try to allocate some new inodes in the allocation
677 if ((error = xfs_ialloc_ag_alloc(tp, agbp, &ialloced))) {
678 xfs_trans_brelse(tp, agbp);
679 if (error == ENOSPC) {
687 * We successfully allocated some inodes, return
688 * the current context to the caller so that it
689 * can commit the current transaction and call
690 * us again where we left off.
692 ASSERT(be32_to_cpu(agi->agi_freecount) > 0);
693 *alloc_done = B_TRUE;
700 * If it failed, give up on this ag.
702 xfs_trans_brelse(tp, agbp);
704 * Go on to the next ag: get its ag header.
707 if (++tagno == agcount)
711 return noroom ? ENOSPC : 0;
713 down_read(&mp->m_peraglock);
714 if (mp->m_perag[tagno].pagi_inodeok == 0) {
715 up_read(&mp->m_peraglock);
718 error = xfs_ialloc_read_agi(mp, tp, tagno, &agbp);
719 up_read(&mp->m_peraglock);
722 agi = XFS_BUF_TO_AGI(agbp);
723 ASSERT(be32_to_cpu(agi->agi_magicnum) == XFS_AGI_MAGIC);
726 * Here with an allocation group that has a free inode.
727 * Reset agno since we may have chosen a new ag in the
732 cur = xfs_inobt_init_cursor(mp, tp, agbp, be32_to_cpu(agi->agi_seqno));
734 * If pagino is 0 (this is the root inode allocation) use newino.
735 * This must work because we've just allocated some.
738 pagino = be32_to_cpu(agi->agi_newino);
740 if (cur->bc_nlevels == 1) {
743 if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i)))
745 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
747 error = xfs_inobt_get_rec(cur, &rec, &i);
750 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
751 freecount += rec.ir_freecount;
752 if ((error = xfs_btree_increment(cur, 0, &i)))
756 ASSERT(freecount == be32_to_cpu(agi->agi_freecount) ||
757 XFS_FORCED_SHUTDOWN(mp));
761 * If in the same a.g. as the parent, try to get near the parent.
764 if ((error = xfs_inobt_lookup_le(cur, pagino, 0, 0, &i)))
767 (error = xfs_inobt_get_rec(cur, &rec, &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 error = xfs_inobt_get_rec(tcur, &trec, &i);
802 XFS_WANT_CORRUPTED_GOTO(i == 1, error1);
805 * Search right with cur, go forward 1 record.
807 if ((error = xfs_btree_increment(cur, 0, &i)))
811 error = xfs_inobt_get_rec(cur, &rec, &i);
814 XFS_WANT_CORRUPTED_GOTO(i == 1, error1);
817 * Loop until we find the closest inode chunk
820 while (!doneleft || !doneright) {
821 int useleft; /* using left inode
825 * Figure out which block is closer,
828 if (!doneleft && !doneright)
832 XFS_INODES_PER_CHUNK - 1) <
833 rec.ir_startino - pagino;
837 * If checking the left, does it have
840 if (useleft && trec.ir_freecount) {
842 * Yes, set it up as the chunk to use.
845 xfs_btree_del_cursor(cur,
851 * If checking the right, does it have
854 if (!useleft && rec.ir_freecount) {
856 * Yes, it's already set up.
858 xfs_btree_del_cursor(tcur,
863 * If used the left, get another one
867 if ((error = xfs_btree_decrement(tcur, 0,
872 error = xfs_inobt_get_rec(
876 XFS_WANT_CORRUPTED_GOTO(i == 1,
881 * If used the right, get another one
885 if ((error = xfs_btree_increment(cur, 0,
890 error = xfs_inobt_get_rec(
894 XFS_WANT_CORRUPTED_GOTO(i == 1,
899 ASSERT(!doneleft || !doneright);
903 * In a different a.g. from the parent.
904 * See if the most recently allocated block has any free.
906 else if (be32_to_cpu(agi->agi_newino) != NULLAGINO) {
907 if ((error = xfs_inobt_lookup_eq(cur,
908 be32_to_cpu(agi->agi_newino), 0, 0, &i)))
911 (error = xfs_inobt_get_rec(cur, &rec, &j)) == 0 &&
913 rec.ir_freecount > 0) {
915 * The last chunk allocated in the group still has
920 * None left in the last group, search the whole a.g.
925 if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i)))
929 error = xfs_inobt_get_rec(cur, &rec, &i);
932 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
933 if (rec.ir_freecount > 0)
935 if ((error = xfs_btree_increment(cur, 0, &i)))
937 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
941 offset = xfs_ialloc_find_free(&rec.ir_free);
943 ASSERT(offset < XFS_INODES_PER_CHUNK);
944 ASSERT((XFS_AGINO_TO_OFFSET(mp, rec.ir_startino) %
945 XFS_INODES_PER_CHUNK) == 0);
946 ino = XFS_AGINO_TO_INO(mp, agno, rec.ir_startino + offset);
947 rec.ir_free &= ~XFS_INOBT_MASK(offset);
949 if ((error = xfs_inobt_update(cur, rec.ir_startino, rec.ir_freecount,
952 be32_add_cpu(&agi->agi_freecount, -1);
953 xfs_ialloc_log_agi(tp, agbp, XFS_AGI_FREECOUNT);
954 down_read(&mp->m_peraglock);
955 mp->m_perag[tagno].pagi_freecount--;
956 up_read(&mp->m_peraglock);
958 if (cur->bc_nlevels == 1) {
961 if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i)))
964 error = xfs_inobt_get_rec(cur, &rec, &i);
967 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
968 freecount += rec.ir_freecount;
969 if ((error = xfs_btree_increment(cur, 0, &i)))
972 ASSERT(freecount == be32_to_cpu(agi->agi_freecount) ||
973 XFS_FORCED_SHUTDOWN(mp));
976 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
977 xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, -1);
981 xfs_btree_del_cursor(tcur, XFS_BTREE_ERROR);
983 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
988 * Free disk inode. Carefully avoids touching the incore inode, all
989 * manipulations incore are the caller's responsibility.
990 * The on-disk inode is not changed by this operation, only the
991 * btree (free inode mask) is changed.
995 xfs_trans_t *tp, /* transaction pointer */
996 xfs_ino_t inode, /* inode to be freed */
997 xfs_bmap_free_t *flist, /* extents to free */
998 int *delete, /* set if inode cluster was deleted */
999 xfs_ino_t *first_ino) /* first inode in deleted cluster */
1002 xfs_agblock_t agbno; /* block number containing inode */
1003 xfs_buf_t *agbp; /* buffer containing allocation group header */
1004 xfs_agino_t agino; /* inode number relative to allocation group */
1005 xfs_agnumber_t agno; /* allocation group number */
1006 xfs_agi_t *agi; /* allocation group header */
1007 xfs_btree_cur_t *cur; /* inode btree cursor */
1008 int error; /* error return value */
1009 int i; /* result code */
1010 int ilen; /* inodes in an inode cluster */
1011 xfs_mount_t *mp; /* mount structure for filesystem */
1012 int off; /* offset of inode in inode chunk */
1013 xfs_inobt_rec_incore_t rec; /* btree record */
1018 * Break up inode number into its components.
1020 agno = XFS_INO_TO_AGNO(mp, inode);
1021 if (agno >= mp->m_sb.sb_agcount) {
1023 "xfs_difree: agno >= mp->m_sb.sb_agcount (%d >= %d) on %s. Returning EINVAL.",
1024 agno, mp->m_sb.sb_agcount, mp->m_fsname);
1026 return XFS_ERROR(EINVAL);
1028 agino = XFS_INO_TO_AGINO(mp, inode);
1029 if (inode != XFS_AGINO_TO_INO(mp, agno, agino)) {
1031 "xfs_difree: inode != XFS_AGINO_TO_INO() "
1032 "(%llu != %llu) on %s. Returning EINVAL.",
1033 (unsigned long long)inode,
1034 (unsigned long long)XFS_AGINO_TO_INO(mp, agno, agino),
1037 return XFS_ERROR(EINVAL);
1039 agbno = XFS_AGINO_TO_AGBNO(mp, agino);
1040 if (agbno >= mp->m_sb.sb_agblocks) {
1042 "xfs_difree: agbno >= mp->m_sb.sb_agblocks (%d >= %d) on %s. Returning EINVAL.",
1043 agbno, mp->m_sb.sb_agblocks, mp->m_fsname);
1045 return XFS_ERROR(EINVAL);
1048 * Get the allocation group header.
1050 down_read(&mp->m_peraglock);
1051 error = xfs_ialloc_read_agi(mp, tp, agno, &agbp);
1052 up_read(&mp->m_peraglock);
1055 "xfs_difree: xfs_ialloc_read_agi() returned an error %d on %s. Returning error.",
1056 error, mp->m_fsname);
1059 agi = XFS_BUF_TO_AGI(agbp);
1060 ASSERT(be32_to_cpu(agi->agi_magicnum) == XFS_AGI_MAGIC);
1061 ASSERT(agbno < be32_to_cpu(agi->agi_length));
1063 * Initialize the cursor.
1065 cur = xfs_inobt_init_cursor(mp, tp, agbp, agno);
1067 if (cur->bc_nlevels == 1) {
1070 if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i)))
1073 error = xfs_inobt_get_rec(cur, &rec, &i);
1077 freecount += rec.ir_freecount;
1078 if ((error = xfs_btree_increment(cur, 0, &i)))
1082 ASSERT(freecount == be32_to_cpu(agi->agi_freecount) ||
1083 XFS_FORCED_SHUTDOWN(mp));
1087 * Look for the entry describing this inode.
1089 if ((error = xfs_inobt_lookup_le(cur, agino, 0, 0, &i))) {
1091 "xfs_difree: xfs_inobt_lookup_le returned() an error %d on %s. Returning error.",
1092 error, mp->m_fsname);
1095 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
1096 error = xfs_inobt_get_rec(cur, &rec, &i);
1099 "xfs_difree: xfs_inobt_get_rec() returned an error %d on %s. Returning error.",
1100 error, mp->m_fsname);
1103 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
1105 * Get the offset in the inode chunk.
1107 off = agino - rec.ir_startino;
1108 ASSERT(off >= 0 && off < XFS_INODES_PER_CHUNK);
1109 ASSERT(!(rec.ir_free & XFS_INOBT_MASK(off)));
1111 * Mark the inode free & increment the count.
1113 rec.ir_free |= XFS_INOBT_MASK(off);
1117 * When an inode cluster is free, it becomes eligible for removal
1119 if (!(mp->m_flags & XFS_MOUNT_IKEEP) &&
1120 (rec.ir_freecount == XFS_IALLOC_INODES(mp))) {
1123 *first_ino = XFS_AGINO_TO_INO(mp, agno, rec.ir_startino);
1126 * Remove the inode cluster from the AGI B+Tree, adjust the
1127 * AGI and Superblock inode counts, and mark the disk space
1128 * to be freed when the transaction is committed.
1130 ilen = XFS_IALLOC_INODES(mp);
1131 be32_add_cpu(&agi->agi_count, -ilen);
1132 be32_add_cpu(&agi->agi_freecount, -(ilen - 1));
1133 xfs_ialloc_log_agi(tp, agbp, XFS_AGI_COUNT | XFS_AGI_FREECOUNT);
1134 down_read(&mp->m_peraglock);
1135 mp->m_perag[agno].pagi_freecount -= ilen - 1;
1136 up_read(&mp->m_peraglock);
1137 xfs_trans_mod_sb(tp, XFS_TRANS_SB_ICOUNT, -ilen);
1138 xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, -(ilen - 1));
1140 if ((error = xfs_btree_delete(cur, &i))) {
1141 cmn_err(CE_WARN, "xfs_difree: xfs_btree_delete returned an error %d on %s.\n",
1142 error, mp->m_fsname);
1146 xfs_bmap_add_free(XFS_AGB_TO_FSB(mp,
1147 agno, XFS_INO_TO_AGBNO(mp,rec.ir_startino)),
1148 XFS_IALLOC_BLOCKS(mp), flist, mp);
1152 if ((error = xfs_inobt_update(cur, rec.ir_startino, rec.ir_freecount, rec.ir_free))) {
1154 "xfs_difree: xfs_inobt_update() returned an error %d on %s. Returning error.",
1155 error, mp->m_fsname);
1159 * Change the inode free counts and log the ag/sb changes.
1161 be32_add_cpu(&agi->agi_freecount, 1);
1162 xfs_ialloc_log_agi(tp, agbp, XFS_AGI_FREECOUNT);
1163 down_read(&mp->m_peraglock);
1164 mp->m_perag[agno].pagi_freecount++;
1165 up_read(&mp->m_peraglock);
1166 xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, 1);
1170 if (cur->bc_nlevels == 1) {
1173 if ((error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i)))
1176 error = xfs_inobt_get_rec(cur, &rec, &i);
1180 freecount += rec.ir_freecount;
1181 if ((error = xfs_btree_increment(cur, 0, &i)))
1185 ASSERT(freecount == be32_to_cpu(agi->agi_freecount) ||
1186 XFS_FORCED_SHUTDOWN(mp));
1189 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
1193 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
1198 * Return the location of the inode in imap, for mapping it into a buffer.
1202 xfs_mount_t *mp, /* file system mount structure */
1203 xfs_trans_t *tp, /* transaction pointer */
1204 xfs_ino_t ino, /* inode to locate */
1205 struct xfs_imap *imap, /* location map structure */
1206 uint flags) /* flags for inode btree lookup */
1208 xfs_agblock_t agbno; /* block number of inode in the alloc group */
1209 xfs_agino_t agino; /* inode number within alloc group */
1210 xfs_agnumber_t agno; /* allocation group number */
1211 int blks_per_cluster; /* num blocks per inode cluster */
1212 xfs_agblock_t chunk_agbno; /* first block in inode chunk */
1213 xfs_agblock_t cluster_agbno; /* first block in inode cluster */
1214 int error; /* error code */
1215 int offset; /* index of inode in its buffer */
1216 int offset_agbno; /* blks from chunk start to inode */
1218 ASSERT(ino != NULLFSINO);
1221 * Split up the inode number into its parts.
1223 agno = XFS_INO_TO_AGNO(mp, ino);
1224 agino = XFS_INO_TO_AGINO(mp, ino);
1225 agbno = XFS_AGINO_TO_AGBNO(mp, agino);
1226 if (agno >= mp->m_sb.sb_agcount || agbno >= mp->m_sb.sb_agblocks ||
1227 ino != XFS_AGINO_TO_INO(mp, agno, agino)) {
1229 /* no diagnostics for bulkstat, ino comes from userspace */
1230 if (flags & XFS_IGET_BULKSTAT)
1231 return XFS_ERROR(EINVAL);
1232 if (agno >= mp->m_sb.sb_agcount) {
1233 xfs_fs_cmn_err(CE_ALERT, mp,
1234 "xfs_imap: agno (%d) >= "
1235 "mp->m_sb.sb_agcount (%d)",
1236 agno, mp->m_sb.sb_agcount);
1238 if (agbno >= mp->m_sb.sb_agblocks) {
1239 xfs_fs_cmn_err(CE_ALERT, mp,
1240 "xfs_imap: agbno (0x%llx) >= "
1241 "mp->m_sb.sb_agblocks (0x%lx)",
1242 (unsigned long long) agbno,
1243 (unsigned long) mp->m_sb.sb_agblocks);
1245 if (ino != XFS_AGINO_TO_INO(mp, agno, agino)) {
1246 xfs_fs_cmn_err(CE_ALERT, mp,
1247 "xfs_imap: ino (0x%llx) != "
1248 "XFS_AGINO_TO_INO(mp, agno, agino) "
1250 ino, XFS_AGINO_TO_INO(mp, agno, agino));
1254 return XFS_ERROR(EINVAL);
1258 * If the inode cluster size is the same as the blocksize or
1259 * smaller we get to the buffer by simple arithmetics.
1261 if (XFS_INODE_CLUSTER_SIZE(mp) <= mp->m_sb.sb_blocksize) {
1262 offset = XFS_INO_TO_OFFSET(mp, ino);
1263 ASSERT(offset < mp->m_sb.sb_inopblock);
1265 imap->im_blkno = XFS_AGB_TO_DADDR(mp, agno, agbno);
1266 imap->im_len = XFS_FSB_TO_BB(mp, 1);
1267 imap->im_boffset = (ushort)(offset << mp->m_sb.sb_inodelog);
1271 blks_per_cluster = XFS_INODE_CLUSTER_SIZE(mp) >> mp->m_sb.sb_blocklog;
1274 * If we get a block number passed from bulkstat we can use it to
1275 * find the buffer easily.
1277 if (imap->im_blkno) {
1278 offset = XFS_INO_TO_OFFSET(mp, ino);
1279 ASSERT(offset < mp->m_sb.sb_inopblock);
1281 cluster_agbno = xfs_daddr_to_agbno(mp, imap->im_blkno);
1282 offset += (agbno - cluster_agbno) * mp->m_sb.sb_inopblock;
1284 imap->im_len = XFS_FSB_TO_BB(mp, blks_per_cluster);
1285 imap->im_boffset = (ushort)(offset << mp->m_sb.sb_inodelog);
1290 * If the inode chunks are aligned then use simple maths to
1291 * find the location. Otherwise we have to do a btree
1292 * lookup to find the location.
1294 if (mp->m_inoalign_mask) {
1295 offset_agbno = agbno & mp->m_inoalign_mask;
1296 chunk_agbno = agbno - offset_agbno;
1298 xfs_btree_cur_t *cur; /* inode btree cursor */
1299 xfs_inobt_rec_incore_t chunk_rec;
1300 xfs_buf_t *agbp; /* agi buffer */
1301 int i; /* temp state */
1303 down_read(&mp->m_peraglock);
1304 error = xfs_ialloc_read_agi(mp, tp, agno, &agbp);
1305 up_read(&mp->m_peraglock);
1307 xfs_fs_cmn_err(CE_ALERT, mp, "xfs_imap: "
1308 "xfs_ialloc_read_agi() returned "
1309 "error %d, agno %d",
1314 cur = xfs_inobt_init_cursor(mp, tp, agbp, agno);
1315 error = xfs_inobt_lookup_le(cur, agino, 0, 0, &i);
1317 xfs_fs_cmn_err(CE_ALERT, mp, "xfs_imap: "
1318 "xfs_inobt_lookup_le() failed");
1322 error = xfs_inobt_get_rec(cur, &chunk_rec, &i);
1324 xfs_fs_cmn_err(CE_ALERT, mp, "xfs_imap: "
1325 "xfs_inobt_get_rec() failed");
1330 xfs_fs_cmn_err(CE_ALERT, mp, "xfs_imap: "
1331 "xfs_inobt_get_rec() failed");
1333 error = XFS_ERROR(EINVAL);
1336 xfs_trans_brelse(tp, agbp);
1337 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
1340 chunk_agbno = XFS_AGINO_TO_AGBNO(mp, chunk_rec.ir_startino);
1341 offset_agbno = agbno - chunk_agbno;
1344 ASSERT(agbno >= chunk_agbno);
1345 cluster_agbno = chunk_agbno +
1346 ((offset_agbno / blks_per_cluster) * blks_per_cluster);
1347 offset = ((agbno - cluster_agbno) * mp->m_sb.sb_inopblock) +
1348 XFS_INO_TO_OFFSET(mp, ino);
1350 imap->im_blkno = XFS_AGB_TO_DADDR(mp, agno, cluster_agbno);
1351 imap->im_len = XFS_FSB_TO_BB(mp, blks_per_cluster);
1352 imap->im_boffset = (ushort)(offset << mp->m_sb.sb_inodelog);
1355 * If the inode number maps to a block outside the bounds
1356 * of the file system then return NULL rather than calling
1357 * read_buf and panicing when we get an error from the
1360 if ((imap->im_blkno + imap->im_len) >
1361 XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks)) {
1362 xfs_fs_cmn_err(CE_ALERT, mp, "xfs_imap: "
1363 "(imap->im_blkno (0x%llx) + imap->im_len (0x%llx)) > "
1364 " XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks) (0x%llx)",
1365 (unsigned long long) imap->im_blkno,
1366 (unsigned long long) imap->im_len,
1367 XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks));
1368 return XFS_ERROR(EINVAL);
1375 * Compute and fill in value of m_in_maxlevels.
1378 xfs_ialloc_compute_maxlevels(
1379 xfs_mount_t *mp) /* file system mount structure */
1387 maxleafents = (1LL << XFS_INO_AGINO_BITS(mp)) >>
1388 XFS_INODES_PER_CHUNK_LOG;
1389 minleafrecs = mp->m_alloc_mnr[0];
1390 minnoderecs = mp->m_alloc_mnr[1];
1391 maxblocks = (maxleafents + minleafrecs - 1) / minleafrecs;
1392 for (level = 1; maxblocks > 1; level++)
1393 maxblocks = (maxblocks + minnoderecs - 1) / minnoderecs;
1394 mp->m_in_maxlevels = level;
1398 * Log specified fields for the ag hdr (inode section)
1402 xfs_trans_t *tp, /* transaction pointer */
1403 xfs_buf_t *bp, /* allocation group header buffer */
1404 int fields) /* bitmask of fields to log */
1406 int first; /* first byte number */
1407 int last; /* last byte number */
1408 static const short offsets[] = { /* field starting offsets */
1409 /* keep in sync with bit definitions */
1410 offsetof(xfs_agi_t, agi_magicnum),
1411 offsetof(xfs_agi_t, agi_versionnum),
1412 offsetof(xfs_agi_t, agi_seqno),
1413 offsetof(xfs_agi_t, agi_length),
1414 offsetof(xfs_agi_t, agi_count),
1415 offsetof(xfs_agi_t, agi_root),
1416 offsetof(xfs_agi_t, agi_level),
1417 offsetof(xfs_agi_t, agi_freecount),
1418 offsetof(xfs_agi_t, agi_newino),
1419 offsetof(xfs_agi_t, agi_dirino),
1420 offsetof(xfs_agi_t, agi_unlinked),
1424 xfs_agi_t *agi; /* allocation group header */
1426 agi = XFS_BUF_TO_AGI(bp);
1427 ASSERT(be32_to_cpu(agi->agi_magicnum) == XFS_AGI_MAGIC);
1430 * Compute byte offsets for the first and last fields.
1432 xfs_btree_offsets(fields, offsets, XFS_AGI_NUM_BITS, &first, &last);
1434 * Log the allocation group inode header buffer.
1436 xfs_trans_log_buf(tp, bp, first, last);
1441 xfs_check_agi_unlinked(
1442 struct xfs_agi *agi)
1446 for (i = 0; i < XFS_AGI_UNLINKED_BUCKETS; i++)
1447 ASSERT(agi->agi_unlinked[i]);
1450 #define xfs_check_agi_unlinked(agi)
1454 * Read in the allocation group header (inode allocation section)
1458 struct xfs_mount *mp, /* file system mount structure */
1459 struct xfs_trans *tp, /* transaction pointer */
1460 xfs_agnumber_t agno, /* allocation group number */
1461 struct xfs_buf **bpp) /* allocation group hdr buf */
1463 struct xfs_agi *agi; /* allocation group header */
1464 int agi_ok; /* agi is consistent */
1467 ASSERT(agno != NULLAGNUMBER);
1469 error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp,
1470 XFS_AG_DADDR(mp, agno, XFS_AGI_DADDR(mp)),
1471 XFS_FSS_TO_BB(mp, 1), 0, bpp);
1475 ASSERT(*bpp && !XFS_BUF_GETERROR(*bpp));
1476 agi = XFS_BUF_TO_AGI(*bpp);
1479 * Validate the magic number of the agi block.
1481 agi_ok = be32_to_cpu(agi->agi_magicnum) == XFS_AGI_MAGIC &&
1482 XFS_AGI_GOOD_VERSION(be32_to_cpu(agi->agi_versionnum)) &&
1483 be32_to_cpu(agi->agi_seqno) == agno;
1484 if (unlikely(XFS_TEST_ERROR(!agi_ok, mp, XFS_ERRTAG_IALLOC_READ_AGI,
1485 XFS_RANDOM_IALLOC_READ_AGI))) {
1486 XFS_CORRUPTION_ERROR("xfs_read_agi", XFS_ERRLEVEL_LOW,
1488 xfs_trans_brelse(tp, *bpp);
1489 return XFS_ERROR(EFSCORRUPTED);
1492 XFS_BUF_SET_VTYPE_REF(*bpp, B_FS_AGI, XFS_AGI_REF);
1494 xfs_check_agi_unlinked(agi);
1499 xfs_ialloc_read_agi(
1500 struct xfs_mount *mp, /* file system mount structure */
1501 struct xfs_trans *tp, /* transaction pointer */
1502 xfs_agnumber_t agno, /* allocation group number */
1503 struct xfs_buf **bpp) /* allocation group hdr buf */
1505 struct xfs_agi *agi; /* allocation group header */
1506 struct xfs_perag *pag; /* per allocation group data */
1509 error = xfs_read_agi(mp, tp, agno, bpp);
1513 agi = XFS_BUF_TO_AGI(*bpp);
1514 pag = &mp->m_perag[agno];
1516 if (!pag->pagi_init) {
1517 pag->pagi_freecount = be32_to_cpu(agi->agi_freecount);
1518 pag->pagi_count = be32_to_cpu(agi->agi_count);
1523 * It's possible for these to be out of sync if
1524 * we are in the middle of a forced shutdown.
1526 ASSERT(pag->pagi_freecount == be32_to_cpu(agi->agi_freecount) ||
1527 XFS_FORCED_SHUTDOWN(mp));
1532 * Read in the agi to initialise the per-ag data in the mount structure
1535 xfs_ialloc_pagi_init(
1536 xfs_mount_t *mp, /* file system mount structure */
1537 xfs_trans_t *tp, /* transaction pointer */
1538 xfs_agnumber_t agno) /* allocation group number */
1540 xfs_buf_t *bp = NULL;
1543 error = xfs_ialloc_read_agi(mp, tp, agno, &bp);
1547 xfs_trans_brelse(tp, bp);