hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/xfs/libxfs/xfs_ialloc.c
....@@ -12,17 +12,14 @@
1212 #include "xfs_bit.h"
1313 #include "xfs_sb.h"
1414 #include "xfs_mount.h"
15
-#include "xfs_defer.h"
1615 #include "xfs_inode.h"
1716 #include "xfs_btree.h"
1817 #include "xfs_ialloc.h"
1918 #include "xfs_ialloc_btree.h"
2019 #include "xfs_alloc.h"
21
-#include "xfs_rtalloc.h"
2220 #include "xfs_errortag.h"
2321 #include "xfs_error.h"
2422 #include "xfs_bmap.h"
25
-#include "xfs_cksum.h"
2623 #include "xfs_trans.h"
2724 #include "xfs_buf_item.h"
2825 #include "xfs_icreate_item.h"
....@@ -30,20 +27,6 @@
3027 #include "xfs_trace.h"
3128 #include "xfs_log.h"
3229 #include "xfs_rmap.h"
33
-
34
-
35
-/*
36
- * Allocation group level functions.
37
- */
38
-int
39
-xfs_ialloc_cluster_alignment(
40
- struct xfs_mount *mp)
41
-{
42
- if (xfs_sb_version_hasalign(&mp->m_sb) &&
43
- mp->m_sb.sb_inoalignmt >= xfs_icluster_size_fsb(mp))
44
- return mp->m_sb.sb_inoalignmt;
45
- return 1;
46
-}
4730
4831 /*
4932 * Lookup a record by ino in the btree given by cur.
....@@ -122,7 +105,7 @@
122105 int *stat)
123106 {
124107 struct xfs_mount *mp = cur->bc_mp;
125
- xfs_agnumber_t agno = cur->bc_private.a.agno;
108
+ xfs_agnumber_t agno = cur->bc_ag.agno;
126109 union xfs_btree_rec *rec;
127110 int error;
128111 uint64_t realfree;
....@@ -194,7 +177,7 @@
194177 xfs_btnum_t btnum)
195178 {
196179 struct xfs_btree_cur *cur;
197
- struct xfs_agi *agi = XFS_BUF_TO_AGI(agbp);
180
+ struct xfs_agi *agi = agbp->b_addr;
198181 xfs_agnumber_t agno = be32_to_cpu(agi->agi_seqno);
199182 xfs_agino_t thisino;
200183 int i;
....@@ -288,20 +271,19 @@
288271 {
289272 struct xfs_buf *fbuf;
290273 struct xfs_dinode *free;
291
- int nbufs, blks_per_cluster, inodes_per_cluster;
274
+ int nbufs;
292275 int version;
293276 int i, j;
294277 xfs_daddr_t d;
295278 xfs_ino_t ino = 0;
279
+ int error;
296280
297281 /*
298282 * Loop over the new block(s), filling in the inodes. For small block
299283 * sizes, manipulate the inodes in buffers which are multiples of the
300284 * blocks size.
301285 */
302
- blks_per_cluster = xfs_icluster_size_fsb(mp);
303
- inodes_per_cluster = blks_per_cluster << mp->m_sb.sb_inopblog;
304
- nbufs = length / blks_per_cluster;
286
+ nbufs = length / M_IGEO(mp)->blocks_per_cluster;
305287
306288 /*
307289 * Figure out what version number to use in the inodes we create. If
....@@ -312,7 +294,7 @@
312294 *
313295 * For v3 inodes, we also need to write the inode number into the inode,
314296 * so calculate the first inode number of the chunk here as
315
- * XFS_OFFBNO_TO_AGINO() only works within a filesystem block, not
297
+ * XFS_AGB_TO_AGINO() only works within a filesystem block, not
316298 * across multiple filesystem blocks (such as a cluster) and so cannot
317299 * be used in the cluster buffer loop below.
318300 *
....@@ -322,10 +304,9 @@
322304 * That means for v3 inode we log the entire buffer rather than just the
323305 * inode cores.
324306 */
325
- if (xfs_sb_version_hascrc(&mp->m_sb)) {
307
+ if (xfs_sb_version_has_v3inode(&mp->m_sb)) {
326308 version = 3;
327
- ino = XFS_AGINO_TO_INO(mp, agno,
328
- XFS_OFFBNO_TO_AGINO(mp, agbno, 0));
309
+ ino = XFS_AGINO_TO_INO(mp, agno, XFS_AGB_TO_AGINO(mp, agbno));
329310
330311 /*
331312 * log the initialisation that is about to take place as an
....@@ -345,19 +326,20 @@
345326 /*
346327 * Get the block.
347328 */
348
- d = XFS_AGB_TO_DADDR(mp, agno, agbno + (j * blks_per_cluster));
349
- fbuf = xfs_trans_get_buf(tp, mp->m_ddev_targp, d,
350
- mp->m_bsize * blks_per_cluster,
351
- XBF_UNMAPPED);
352
- if (!fbuf)
353
- return -ENOMEM;
329
+ d = XFS_AGB_TO_DADDR(mp, agno, agbno +
330
+ (j * M_IGEO(mp)->blocks_per_cluster));
331
+ error = xfs_trans_get_buf(tp, mp->m_ddev_targp, d,
332
+ mp->m_bsize * M_IGEO(mp)->blocks_per_cluster,
333
+ XBF_UNMAPPED, &fbuf);
334
+ if (error)
335
+ return error;
354336
355337 /* Initialize the inode buffers and log them appropriately. */
356338 fbuf->b_ops = &xfs_inode_buf_ops;
357339 xfs_buf_zero(fbuf, 0, BBTOB(fbuf->b_length));
358
- for (i = 0; i < inodes_per_cluster; i++) {
340
+ for (i = 0; i < M_IGEO(mp)->inodes_per_cluster; i++) {
359341 int ioffset = i << mp->m_sb.sb_inodelog;
360
- uint isize = xfs_dinode_size(version);
342
+ uint isize = XFS_DINODE_SIZE(&mp->m_sb);
361343
362344 free = xfs_make_iptr(mp, fbuf, i);
363345 free->di_magic = cpu_to_be16(XFS_DINODE_MAGIC);
....@@ -445,7 +427,7 @@
445427 return;
446428
447429 /* calculate the inode offset and align startino */
448
- offset = mod << mp->m_sb.sb_inopblog;
430
+ offset = XFS_AGB_TO_AGINO(mp, mod);
449431 *startino -= offset;
450432
451433 /*
....@@ -543,7 +525,7 @@
543525 bool merge) /* merge or replace */
544526 {
545527 struct xfs_btree_cur *cur;
546
- struct xfs_agi *agi = XFS_BUF_TO_AGI(agbp);
528
+ struct xfs_agi *agi = agbp->b_addr;
547529 xfs_agnumber_t agno = be32_to_cpu(agi->agi_seqno);
548530 int error;
549531 int i;
....@@ -562,7 +544,10 @@
562544 nrec->ir_free, &i);
563545 if (error)
564546 goto error;
565
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error);
547
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
548
+ error = -EFSCORRUPTED;
549
+ goto error;
550
+ }
566551
567552 goto out;
568553 }
....@@ -575,17 +560,23 @@
575560 error = xfs_inobt_get_rec(cur, &rec, &i);
576561 if (error)
577562 goto error;
578
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error);
579
- XFS_WANT_CORRUPTED_GOTO(mp,
580
- rec.ir_startino == nrec->ir_startino,
581
- error);
563
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
564
+ error = -EFSCORRUPTED;
565
+ goto error;
566
+ }
567
+ if (XFS_IS_CORRUPT(mp, rec.ir_startino != nrec->ir_startino)) {
568
+ error = -EFSCORRUPTED;
569
+ goto error;
570
+ }
582571
583572 /*
584573 * This should never fail. If we have coexisting records that
585574 * cannot merge, something is seriously wrong.
586575 */
587
- XFS_WANT_CORRUPTED_GOTO(mp, __xfs_inobt_can_merge(nrec, &rec),
588
- error);
576
+ if (XFS_IS_CORRUPT(mp, !__xfs_inobt_can_merge(nrec, &rec))) {
577
+ error = -EFSCORRUPTED;
578
+ goto error;
579
+ }
589580
590581 trace_xfs_irec_merge_pre(mp, agno, rec.ir_startino,
591582 rec.ir_holemask, nrec->ir_startino,
....@@ -618,35 +609,37 @@
618609 * Allocate new inodes in the allocation group specified by agbp.
619610 * Return 0 for success, else error code.
620611 */
621
-STATIC int /* error code or 0 */
612
+STATIC int
622613 xfs_ialloc_ag_alloc(
623
- xfs_trans_t *tp, /* transaction pointer */
624
- xfs_buf_t *agbp, /* alloc group buffer */
625
- int *alloc)
614
+ struct xfs_trans *tp,
615
+ struct xfs_buf *agbp,
616
+ int *alloc)
626617 {
627
- xfs_agi_t *agi; /* allocation group header */
628
- xfs_alloc_arg_t args; /* allocation argument structure */
629
- xfs_agnumber_t agno;
630
- int error;
631
- xfs_agino_t newino; /* new first inode's number */
632
- xfs_agino_t newlen; /* new number of inodes */
633
- int isaligned = 0; /* inode allocation at stripe unit */
634
- /* boundary */
635
- uint16_t allocmask = (uint16_t) -1; /* init. to full chunk */
618
+ struct xfs_agi *agi;
619
+ struct xfs_alloc_arg args;
620
+ xfs_agnumber_t agno;
621
+ int error;
622
+ xfs_agino_t newino; /* new first inode's number */
623
+ xfs_agino_t newlen; /* new number of inodes */
624
+ int isaligned = 0; /* inode allocation at stripe */
625
+ /* unit boundary */
626
+ /* init. to full chunk */
627
+ uint16_t allocmask = (uint16_t) -1;
636628 struct xfs_inobt_rec_incore rec;
637
- struct xfs_perag *pag;
638
- int do_sparse = 0;
629
+ struct xfs_perag *pag;
630
+ struct xfs_ino_geometry *igeo = M_IGEO(tp->t_mountp);
631
+ int do_sparse = 0;
639632
640633 memset(&args, 0, sizeof(args));
641634 args.tp = tp;
642635 args.mp = tp->t_mountp;
643636 args.fsbno = NULLFSBLOCK;
644
- xfs_rmap_ag_owner(&args.oinfo, XFS_RMAP_OWN_INODES);
637
+ args.oinfo = XFS_RMAP_OINFO_INODES;
645638
646639 #ifdef DEBUG
647640 /* randomly do sparse inode allocations */
648641 if (xfs_sb_version_hassparseinodes(&tp->t_mountp->m_sb) &&
649
- args.mp->m_ialloc_min_blks < args.mp->m_ialloc_blks)
642
+ igeo->ialloc_min_blks < igeo->ialloc_blks)
650643 do_sparse = prandom_u32() & 1;
651644 #endif
652645
....@@ -654,22 +647,22 @@
654647 * Locking will ensure that we don't have two callers in here
655648 * at one time.
656649 */
657
- newlen = args.mp->m_ialloc_inos;
658
- if (args.mp->m_maxicount &&
650
+ newlen = igeo->ialloc_inos;
651
+ if (igeo->maxicount &&
659652 percpu_counter_read_positive(&args.mp->m_icount) + newlen >
660
- args.mp->m_maxicount)
653
+ igeo->maxicount)
661654 return -ENOSPC;
662
- args.minlen = args.maxlen = args.mp->m_ialloc_blks;
655
+ args.minlen = args.maxlen = igeo->ialloc_blks;
663656 /*
664657 * First try to allocate inodes contiguous with the last-allocated
665658 * chunk of inodes. If the filesystem is striped, this will fill
666659 * an entire stripe unit with inodes.
667660 */
668
- agi = XFS_BUF_TO_AGI(agbp);
661
+ agi = agbp->b_addr;
669662 newino = be32_to_cpu(agi->agi_newino);
670663 agno = be32_to_cpu(agi->agi_seqno);
671664 args.agbno = XFS_AGINO_TO_AGBNO(args.mp, newino) +
672
- args.mp->m_ialloc_blks;
665
+ igeo->ialloc_blks;
673666 if (do_sparse)
674667 goto sparse_alloc;
675668 if (likely(newino != NULLAGINO &&
....@@ -692,10 +685,10 @@
692685 * but not to use them in the actual exact allocation.
693686 */
694687 args.alignment = 1;
695
- args.minalignslop = xfs_ialloc_cluster_alignment(args.mp) - 1;
688
+ args.minalignslop = igeo->cluster_align - 1;
696689
697690 /* Allow space for the inode btree to split. */
698
- args.minleft = args.mp->m_in_maxlevels - 1;
691
+ args.minleft = igeo->inobt_maxlevels;
699692 if ((error = xfs_alloc_vextent(&args)))
700693 return error;
701694
....@@ -722,12 +715,12 @@
722715 * pieces, so don't need alignment anyway.
723716 */
724717 isaligned = 0;
725
- if (args.mp->m_sinoalign) {
718
+ if (igeo->ialloc_align) {
726719 ASSERT(!(args.mp->m_flags & XFS_MOUNT_NOALIGN));
727720 args.alignment = args.mp->m_dalign;
728721 isaligned = 1;
729722 } else
730
- args.alignment = xfs_ialloc_cluster_alignment(args.mp);
723
+ args.alignment = igeo->cluster_align;
731724 /*
732725 * Need to figure out where to allocate the inode blocks.
733726 * Ideally they should be spaced out through the a.g.
....@@ -743,7 +736,7 @@
743736 /*
744737 * Allow space for the inode btree to split.
745738 */
746
- args.minleft = args.mp->m_in_maxlevels - 1;
739
+ args.minleft = igeo->inobt_maxlevels;
747740 if ((error = xfs_alloc_vextent(&args)))
748741 return error;
749742 }
....@@ -756,7 +749,7 @@
756749 args.type = XFS_ALLOCTYPE_NEAR_BNO;
757750 args.agbno = be32_to_cpu(agi->agi_root);
758751 args.fsbno = XFS_AGB_TO_FSB(args.mp, agno, args.agbno);
759
- args.alignment = xfs_ialloc_cluster_alignment(args.mp);
752
+ args.alignment = igeo->cluster_align;
760753 if ((error = xfs_alloc_vextent(&args)))
761754 return error;
762755 }
....@@ -766,7 +759,7 @@
766759 * the sparse allocation length is smaller than a full chunk.
767760 */
768761 if (xfs_sb_version_hassparseinodes(&args.mp->m_sb) &&
769
- args.mp->m_ialloc_min_blks < args.mp->m_ialloc_blks &&
762
+ igeo->ialloc_min_blks < igeo->ialloc_blks &&
770763 args.fsbno == NULLFSBLOCK) {
771764 sparse_alloc:
772765 args.type = XFS_ALLOCTYPE_NEAR_BNO;
....@@ -775,7 +768,7 @@
775768 args.alignment = args.mp->m_sb.sb_spino_align;
776769 args.prod = 1;
777770
778
- args.minlen = args.mp->m_ialloc_min_blks;
771
+ args.minlen = igeo->ialloc_min_blks;
779772 args.maxlen = args.minlen;
780773
781774 /*
....@@ -791,13 +784,13 @@
791784 args.min_agbno = args.mp->m_sb.sb_inoalignmt;
792785 args.max_agbno = round_down(args.mp->m_sb.sb_agblocks,
793786 args.mp->m_sb.sb_inoalignmt) -
794
- args.mp->m_ialloc_blks;
787
+ igeo->ialloc_blks;
795788
796789 error = xfs_alloc_vextent(&args);
797790 if (error)
798791 return error;
799792
800
- newlen = args.len << args.mp->m_sb.sb_inopblog;
793
+ newlen = XFS_AGB_TO_AGINO(args.mp, args.len);
801794 ASSERT(newlen <= XFS_INODES_PER_CHUNK);
802795 allocmask = (1 << (newlen / XFS_INODES_PER_HOLEMASK_BIT)) - 1;
803796 }
....@@ -825,7 +818,7 @@
825818 /*
826819 * Convert the results.
827820 */
828
- newino = XFS_OFFBNO_TO_AGINO(args.mp, args.agbno, 0);
821
+ newino = XFS_AGB_TO_AGINO(args.mp, args.agbno);
829822
830823 if (xfs_inobt_issparse(~allocmask)) {
831824 /*
....@@ -895,10 +888,9 @@
895888 */
896889 be32_add_cpu(&agi->agi_count, newlen);
897890 be32_add_cpu(&agi->agi_freecount, newlen);
898
- pag = xfs_perag_get(args.mp, agno);
891
+ pag = agbp->b_pag;
899892 pag->pagi_freecount += newlen;
900893 pag->pagi_count += newlen;
901
- xfs_perag_put(pag);
902894 agi->agi_newino = cpu_to_be32(newino);
903895
904896 /*
....@@ -1008,7 +1000,7 @@
10081000 * space needed for alignment of inode chunks when checking the
10091001 * longest contiguous free space in the AG - this prevents us
10101002 * from getting ENOSPC because we have free space larger than
1011
- * m_ialloc_blks but alignment constraints prevent us from using
1003
+ * ialloc_blks but alignment constraints prevent us from using
10121004 * it.
10131005 *
10141006 * If we can't find an AG with space for full alignment slack to
....@@ -1017,9 +1009,9 @@
10171009 * if we fail allocation due to alignment issues then it is most
10181010 * likely a real ENOSPC condition.
10191011 */
1020
- ineed = mp->m_ialloc_min_blks;
1012
+ ineed = M_IGEO(mp)->ialloc_min_blks;
10211013 if (flags && ineed > 1)
1022
- ineed += xfs_ialloc_cluster_alignment(mp);
1014
+ ineed += M_IGEO(mp)->cluster_align;
10231015 longest = pag->pagf_longest;
10241016 if (!longest)
10251017 longest = pag->pagf_flcount > 0;
....@@ -1073,7 +1065,8 @@
10731065 error = xfs_inobt_get_rec(cur, rec, &i);
10741066 if (error)
10751067 return error;
1076
- XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1);
1068
+ if (XFS_IS_CORRUPT(cur->bc_mp, i != 1))
1069
+ return -EFSCORRUPTED;
10771070 }
10781071
10791072 return 0;
....@@ -1097,7 +1090,8 @@
10971090 error = xfs_inobt_get_rec(cur, rec, &i);
10981091 if (error)
10991092 return error;
1100
- XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1);
1093
+ if (XFS_IS_CORRUPT(cur->bc_mp, i != 1))
1094
+ return -EFSCORRUPTED;
11011095 }
11021096
11031097 return 0;
....@@ -1135,11 +1129,11 @@
11351129 xfs_ino_t *inop)
11361130 {
11371131 struct xfs_mount *mp = tp->t_mountp;
1138
- struct xfs_agi *agi = XFS_BUF_TO_AGI(agbp);
1132
+ struct xfs_agi *agi = agbp->b_addr;
11391133 xfs_agnumber_t agno = be32_to_cpu(agi->agi_seqno);
11401134 xfs_agnumber_t pagno = XFS_INO_TO_AGNO(mp, parent);
11411135 xfs_agino_t pagino = XFS_INO_TO_AGINO(mp, parent);
1142
- struct xfs_perag *pag;
1136
+ struct xfs_perag *pag = agbp->b_pag;
11431137 struct xfs_btree_cur *cur, *tcur;
11441138 struct xfs_inobt_rec_incore rec, trec;
11451139 xfs_ino_t ino;
....@@ -1147,8 +1141,6 @@
11471141 int offset;
11481142 int i, j;
11491143 int searchdistance = 10;
1150
-
1151
- pag = xfs_perag_get(mp, agno);
11521144
11531145 ASSERT(pag->pagi_init);
11541146 ASSERT(pag->pagi_inodeok);
....@@ -1177,12 +1169,18 @@
11771169 error = xfs_inobt_lookup(cur, pagino, XFS_LOOKUP_LE, &i);
11781170 if (error)
11791171 goto error0;
1180
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1172
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1173
+ error = -EFSCORRUPTED;
1174
+ goto error0;
1175
+ }
11811176
11821177 error = xfs_inobt_get_rec(cur, &rec, &j);
11831178 if (error)
11841179 goto error0;
1185
- XFS_WANT_CORRUPTED_GOTO(mp, j == 1, error0);
1180
+ if (XFS_IS_CORRUPT(mp, j != 1)) {
1181
+ error = -EFSCORRUPTED;
1182
+ goto error0;
1183
+ }
11861184
11871185 if (rec.ir_freecount > 0) {
11881186 /*
....@@ -1337,19 +1335,28 @@
13371335 error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &i);
13381336 if (error)
13391337 goto error0;
1340
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1338
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1339
+ error = -EFSCORRUPTED;
1340
+ goto error0;
1341
+ }
13411342
13421343 for (;;) {
13431344 error = xfs_inobt_get_rec(cur, &rec, &i);
13441345 if (error)
13451346 goto error0;
1346
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1347
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1348
+ error = -EFSCORRUPTED;
1349
+ goto error0;
1350
+ }
13471351 if (rec.ir_freecount > 0)
13481352 break;
13491353 error = xfs_btree_increment(cur, 0, &i);
13501354 if (error)
13511355 goto error0;
1352
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1356
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1357
+ error = -EFSCORRUPTED;
1358
+ goto error0;
1359
+ }
13531360 }
13541361
13551362 alloc_inode:
....@@ -1374,14 +1381,12 @@
13741381
13751382 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
13761383 xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, -1);
1377
- xfs_perag_put(pag);
13781384 *inop = ino;
13791385 return 0;
13801386 error1:
13811387 xfs_btree_del_cursor(tcur, XFS_BTREE_ERROR);
13821388 error0:
13831389 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
1384
- xfs_perag_put(pag);
13851390 return error;
13861391 }
13871392
....@@ -1409,7 +1414,8 @@
14091414 error = xfs_inobt_get_rec(lcur, rec, &i);
14101415 if (error)
14111416 return error;
1412
- XFS_WANT_CORRUPTED_RETURN(lcur->bc_mp, i == 1);
1417
+ if (XFS_IS_CORRUPT(lcur->bc_mp, i != 1))
1418
+ return -EFSCORRUPTED;
14131419
14141420 /*
14151421 * See if we've landed in the parent inode record. The finobt
....@@ -1432,10 +1438,16 @@
14321438 error = xfs_inobt_get_rec(rcur, &rrec, &j);
14331439 if (error)
14341440 goto error_rcur;
1435
- XFS_WANT_CORRUPTED_GOTO(lcur->bc_mp, j == 1, error_rcur);
1441
+ if (XFS_IS_CORRUPT(lcur->bc_mp, j != 1)) {
1442
+ error = -EFSCORRUPTED;
1443
+ goto error_rcur;
1444
+ }
14361445 }
14371446
1438
- XFS_WANT_CORRUPTED_GOTO(lcur->bc_mp, i == 1 || j == 1, error_rcur);
1447
+ if (XFS_IS_CORRUPT(lcur->bc_mp, i != 1 && j != 1)) {
1448
+ error = -EFSCORRUPTED;
1449
+ goto error_rcur;
1450
+ }
14391451 if (i == 1 && j == 1) {
14401452 /*
14411453 * Both the left and right records are valid. Choose the closer
....@@ -1488,7 +1500,8 @@
14881500 error = xfs_inobt_get_rec(cur, rec, &i);
14891501 if (error)
14901502 return error;
1491
- XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1);
1503
+ if (XFS_IS_CORRUPT(cur->bc_mp, i != 1))
1504
+ return -EFSCORRUPTED;
14921505 return 0;
14931506 }
14941507 }
....@@ -1499,12 +1512,14 @@
14991512 error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &i);
15001513 if (error)
15011514 return error;
1502
- XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1);
1515
+ if (XFS_IS_CORRUPT(cur->bc_mp, i != 1))
1516
+ return -EFSCORRUPTED;
15031517
15041518 error = xfs_inobt_get_rec(cur, rec, &i);
15051519 if (error)
15061520 return error;
1507
- XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1);
1521
+ if (XFS_IS_CORRUPT(cur->bc_mp, i != 1))
1522
+ return -EFSCORRUPTED;
15081523
15091524 return 0;
15101525 }
....@@ -1526,20 +1541,24 @@
15261541 error = xfs_inobt_lookup(cur, frec->ir_startino, XFS_LOOKUP_EQ, &i);
15271542 if (error)
15281543 return error;
1529
- XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1);
1544
+ if (XFS_IS_CORRUPT(cur->bc_mp, i != 1))
1545
+ return -EFSCORRUPTED;
15301546
15311547 error = xfs_inobt_get_rec(cur, &rec, &i);
15321548 if (error)
15331549 return error;
1534
- XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1);
1550
+ if (XFS_IS_CORRUPT(cur->bc_mp, i != 1))
1551
+ return -EFSCORRUPTED;
15351552 ASSERT((XFS_AGINO_TO_OFFSET(cur->bc_mp, rec.ir_startino) %
15361553 XFS_INODES_PER_CHUNK) == 0);
15371554
15381555 rec.ir_free &= ~XFS_INOBT_MASK(offset);
15391556 rec.ir_freecount--;
15401557
1541
- XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, (rec.ir_free == frec->ir_free) &&
1542
- (rec.ir_freecount == frec->ir_freecount));
1558
+ if (XFS_IS_CORRUPT(cur->bc_mp,
1559
+ rec.ir_free != frec->ir_free ||
1560
+ rec.ir_freecount != frec->ir_freecount))
1561
+ return -EFSCORRUPTED;
15431562
15441563 return xfs_inobt_update(cur, &rec);
15451564 }
....@@ -1559,11 +1578,10 @@
15591578 xfs_ino_t *inop)
15601579 {
15611580 struct xfs_mount *mp = tp->t_mountp;
1562
- struct xfs_agi *agi = XFS_BUF_TO_AGI(agbp);
1581
+ struct xfs_agi *agi = agbp->b_addr;
15631582 xfs_agnumber_t agno = be32_to_cpu(agi->agi_seqno);
15641583 xfs_agnumber_t pagno = XFS_INO_TO_AGNO(mp, parent);
15651584 xfs_agino_t pagino = XFS_INO_TO_AGINO(mp, parent);
1566
- struct xfs_perag *pag;
15671585 struct xfs_btree_cur *cur; /* finobt cursor */
15681586 struct xfs_btree_cur *icur; /* inobt cursor */
15691587 struct xfs_inobt_rec_incore rec;
....@@ -1574,8 +1592,6 @@
15741592
15751593 if (!xfs_sb_version_hasfinobt(&mp->m_sb))
15761594 return xfs_dialloc_ag_inobt(tp, agbp, parent, inop);
1577
-
1578
- pag = xfs_perag_get(mp, agno);
15791595
15801596 /*
15811597 * If pagino is 0 (this is the root inode allocation) use newino.
....@@ -1643,7 +1659,7 @@
16431659 */
16441660 be32_add_cpu(&agi->agi_freecount, -1);
16451661 xfs_ialloc_log_agi(tp, agbp, XFS_AGI_FREECOUNT);
1646
- pag->pagi_freecount--;
1662
+ agbp->b_pag->pagi_freecount--;
16471663
16481664 xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, -1);
16491665
....@@ -1656,7 +1672,6 @@
16561672
16571673 xfs_btree_del_cursor(icur, XFS_BTREE_NOERROR);
16581674 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
1659
- xfs_perag_put(pag);
16601675 *inop = ino;
16611676 return 0;
16621677
....@@ -1664,7 +1679,6 @@
16641679 xfs_btree_del_cursor(icur, XFS_BTREE_ERROR);
16651680 error_cur:
16661681 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
1667
- xfs_perag_put(pag);
16681682 return error;
16691683 }
16701684
....@@ -1705,6 +1719,7 @@
17051719 int noroom = 0;
17061720 xfs_agnumber_t start_agno;
17071721 struct xfs_perag *pag;
1722
+ struct xfs_ino_geometry *igeo = M_IGEO(mp);
17081723 int okalloc = 1;
17091724
17101725 if (*IO_agbp) {
....@@ -1735,9 +1750,9 @@
17351750 * Read rough value of mp->m_icount by percpu_counter_read_positive,
17361751 * which will sacrifice the preciseness but improve the performance.
17371752 */
1738
- if (mp->m_maxicount &&
1739
- percpu_counter_read_positive(&mp->m_icount) + mp->m_ialloc_inos
1740
- > mp->m_maxicount) {
1753
+ if (igeo->maxicount &&
1754
+ percpu_counter_read_positive(&mp->m_icount) + igeo->ialloc_inos
1755
+ > igeo->maxicount) {
17411756 noroom = 1;
17421757 okalloc = 0;
17431758 }
....@@ -1849,14 +1864,13 @@
18491864 int nextbit;
18501865 xfs_agblock_t agbno;
18511866 int contigblk;
1852
- struct xfs_owner_info oinfo;
18531867 DECLARE_BITMAP(holemask, XFS_INOBT_HOLEMASK_BITS);
1854
- xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_INODES);
18551868
18561869 if (!xfs_inobt_issparse(rec->ir_holemask)) {
18571870 /* not sparse, calculate extent info directly */
18581871 xfs_bmap_add_free(tp, XFS_AGB_TO_FSB(mp, agno, sagbno),
1859
- mp->m_ialloc_blks, &oinfo);
1872
+ M_IGEO(mp)->ialloc_blks,
1873
+ &XFS_RMAP_OINFO_INODES);
18601874 return;
18611875 }
18621876
....@@ -1900,7 +1914,7 @@
19001914 ASSERT(agbno % mp->m_sb.sb_spino_align == 0);
19011915 ASSERT(contigblk % mp->m_sb.sb_spino_align == 0);
19021916 xfs_bmap_add_free(tp, XFS_AGB_TO_FSB(mp, agno, agbno),
1903
- contigblk, &oinfo);
1917
+ contigblk, &XFS_RMAP_OINFO_INODES);
19041918
19051919 /* reset range to current bit and carry on... */
19061920 startidx = endidx = nextbit;
....@@ -1919,9 +1933,8 @@
19191933 struct xfs_icluster *xic,
19201934 struct xfs_inobt_rec_incore *orec)
19211935 {
1922
- struct xfs_agi *agi = XFS_BUF_TO_AGI(agbp);
1936
+ struct xfs_agi *agi = agbp->b_addr;
19231937 xfs_agnumber_t agno = be32_to_cpu(agi->agi_seqno);
1924
- struct xfs_perag *pag;
19251938 struct xfs_btree_cur *cur;
19261939 struct xfs_inobt_rec_incore rec;
19271940 int ilen;
....@@ -1949,14 +1962,20 @@
19491962 __func__, error);
19501963 goto error0;
19511964 }
1952
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1965
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1966
+ error = -EFSCORRUPTED;
1967
+ goto error0;
1968
+ }
19531969 error = xfs_inobt_get_rec(cur, &rec, &i);
19541970 if (error) {
19551971 xfs_warn(mp, "%s: xfs_inobt_get_rec() returned error %d.",
19561972 __func__, error);
19571973 goto error0;
19581974 }
1959
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1975
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1976
+ error = -EFSCORRUPTED;
1977
+ goto error0;
1978
+ }
19601979 /*
19611980 * Get the offset in the inode chunk.
19621981 */
....@@ -1977,6 +1996,8 @@
19771996 if (!(mp->m_flags & XFS_MOUNT_IKEEP) &&
19781997 rec.ir_free == XFS_INOBT_ALL_FREE &&
19791998 mp->m_sb.sb_inopblock <= XFS_INODES_PER_CHUNK) {
1999
+ struct xfs_perag *pag = agbp->b_pag;
2000
+
19802001 xic->deleted = true;
19812002 xic->first_ino = XFS_AGINO_TO_INO(mp, agno, rec.ir_startino);
19822003 xic->alloc = xfs_inobt_irec_to_allocmask(&rec);
....@@ -1990,10 +2011,8 @@
19902011 be32_add_cpu(&agi->agi_count, -ilen);
19912012 be32_add_cpu(&agi->agi_freecount, -(ilen - 1));
19922013 xfs_ialloc_log_agi(tp, agbp, XFS_AGI_COUNT | XFS_AGI_FREECOUNT);
1993
- pag = xfs_perag_get(mp, agno);
19942014 pag->pagi_freecount -= ilen - 1;
19952015 pag->pagi_count -= ilen;
1996
- xfs_perag_put(pag);
19972016 xfs_trans_mod_sb(tp, XFS_TRANS_SB_ICOUNT, -ilen);
19982017 xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, -(ilen - 1));
19992018
....@@ -2019,9 +2038,7 @@
20192038 */
20202039 be32_add_cpu(&agi->agi_freecount, 1);
20212040 xfs_ialloc_log_agi(tp, agbp, XFS_AGI_FREECOUNT);
2022
- pag = xfs_perag_get(mp, agno);
2023
- pag->pagi_freecount++;
2024
- xfs_perag_put(pag);
2041
+ agbp->b_pag->pagi_freecount++;
20252042 xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, 1);
20262043 }
20272044
....@@ -2049,7 +2066,7 @@
20492066 xfs_agino_t agino,
20502067 struct xfs_inobt_rec_incore *ibtrec) /* inobt record */
20512068 {
2052
- struct xfs_agi *agi = XFS_BUF_TO_AGI(agbp);
2069
+ struct xfs_agi *agi = agbp->b_addr;
20532070 xfs_agnumber_t agno = be32_to_cpu(agi->agi_seqno);
20542071 struct xfs_btree_cur *cur;
20552072 struct xfs_inobt_rec_incore rec;
....@@ -2068,7 +2085,10 @@
20682085 * freed an inode in a previously fully allocated chunk. If not,
20692086 * something is out of sync.
20702087 */
2071
- XFS_WANT_CORRUPTED_GOTO(mp, ibtrec->ir_freecount == 1, error);
2088
+ if (XFS_IS_CORRUPT(mp, ibtrec->ir_freecount != 1)) {
2089
+ error = -EFSCORRUPTED;
2090
+ goto error;
2091
+ }
20722092
20732093 error = xfs_inobt_insert_rec(cur, ibtrec->ir_holemask,
20742094 ibtrec->ir_count,
....@@ -2091,14 +2111,20 @@
20912111 error = xfs_inobt_get_rec(cur, &rec, &i);
20922112 if (error)
20932113 goto error;
2094
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error);
2114
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
2115
+ error = -EFSCORRUPTED;
2116
+ goto error;
2117
+ }
20952118
20962119 rec.ir_free |= XFS_INOBT_MASK(offset);
20972120 rec.ir_freecount++;
20982121
2099
- XFS_WANT_CORRUPTED_GOTO(mp, (rec.ir_free == ibtrec->ir_free) &&
2100
- (rec.ir_freecount == ibtrec->ir_freecount),
2101
- error);
2122
+ if (XFS_IS_CORRUPT(mp,
2123
+ rec.ir_free != ibtrec->ir_free ||
2124
+ rec.ir_freecount != ibtrec->ir_freecount)) {
2125
+ error = -EFSCORRUPTED;
2126
+ goto error;
2127
+ }
21022128
21032129 /*
21042130 * The content of inobt records should always match between the inobt
....@@ -2265,7 +2291,7 @@
22652291
22662292 /* check that the returned record contains the required inode */
22672293 if (rec.ir_startino > agino ||
2268
- rec.ir_startino + mp->m_ialloc_inos <= agino)
2294
+ rec.ir_startino + M_IGEO(mp)->ialloc_inos <= agino)
22692295 return -EINVAL;
22702296
22712297 /* for untrusted inodes check it is allocated first */
....@@ -2292,7 +2318,6 @@
22922318 xfs_agblock_t agbno; /* block number of inode in the alloc group */
22932319 xfs_agino_t agino; /* inode number within alloc group */
22942320 xfs_agnumber_t agno; /* allocation group number */
2295
- int blks_per_cluster; /* num blocks per inode cluster */
22962321 xfs_agblock_t chunk_agbno; /* first block in inode chunk */
22972322 xfs_agblock_t cluster_agbno; /* first block in inode cluster */
22982323 int error; /* error code */
....@@ -2338,8 +2363,6 @@
23382363 return -EINVAL;
23392364 }
23402365
2341
- blks_per_cluster = xfs_icluster_size_fsb(mp);
2342
-
23432366 /*
23442367 * For bulkstat and handle lookups, we have an untrusted inode number
23452368 * that we have to verify is valid. We cannot do this just by reading
....@@ -2359,7 +2382,7 @@
23592382 * If the inode cluster size is the same as the blocksize or
23602383 * smaller we get to the buffer by simple arithmetics.
23612384 */
2362
- if (blks_per_cluster == 1) {
2385
+ if (M_IGEO(mp)->blocks_per_cluster == 1) {
23632386 offset = XFS_INO_TO_OFFSET(mp, ino);
23642387 ASSERT(offset < mp->m_sb.sb_inopblock);
23652388
....@@ -2375,8 +2398,8 @@
23752398 * find the location. Otherwise we have to do a btree
23762399 * lookup to find the location.
23772400 */
2378
- if (mp->m_inoalign_mask) {
2379
- offset_agbno = agbno & mp->m_inoalign_mask;
2401
+ if (M_IGEO(mp)->inoalign_mask) {
2402
+ offset_agbno = agbno & M_IGEO(mp)->inoalign_mask;
23802403 chunk_agbno = agbno - offset_agbno;
23812404 } else {
23822405 error = xfs_imap_lookup(mp, tp, agno, agino, agbno,
....@@ -2388,12 +2411,13 @@
23882411 out_map:
23892412 ASSERT(agbno >= chunk_agbno);
23902413 cluster_agbno = chunk_agbno +
2391
- ((offset_agbno / blks_per_cluster) * blks_per_cluster);
2414
+ ((offset_agbno / M_IGEO(mp)->blocks_per_cluster) *
2415
+ M_IGEO(mp)->blocks_per_cluster);
23922416 offset = ((agbno - cluster_agbno) * mp->m_sb.sb_inopblock) +
23932417 XFS_INO_TO_OFFSET(mp, ino);
23942418
23952419 imap->im_blkno = XFS_AGB_TO_DADDR(mp, agno, cluster_agbno);
2396
- imap->im_len = XFS_FSB_TO_BB(mp, blks_per_cluster);
2420
+ imap->im_len = XFS_FSB_TO_BB(mp, M_IGEO(mp)->blocks_per_cluster);
23972421 imap->im_boffset = (unsigned short)(offset << mp->m_sb.sb_inodelog);
23982422
23992423 /*
....@@ -2412,20 +2436,6 @@
24122436 return -EINVAL;
24132437 }
24142438 return 0;
2415
-}
2416
-
2417
-/*
2418
- * Compute and fill in value of m_in_maxlevels.
2419
- */
2420
-void
2421
-xfs_ialloc_compute_maxlevels(
2422
- xfs_mount_t *mp) /* file system mount structure */
2423
-{
2424
- uint inodes;
2425
-
2426
- inodes = (1LL << XFS_INO_AGINO_BITS(mp)) >> XFS_INODES_PER_CHUNK_LOG;
2427
- mp->m_in_maxlevels = xfs_btree_compute_maxlevels(mp->m_inobt_mnr,
2428
- inodes);
24292439 }
24302440
24312441 /*
....@@ -2463,12 +2473,12 @@
24632473 offsetof(xfs_agi_t, agi_unlinked),
24642474 offsetof(xfs_agi_t, agi_free_root),
24652475 offsetof(xfs_agi_t, agi_free_level),
2476
+ offsetof(xfs_agi_t, agi_iblocks),
24662477 sizeof(xfs_agi_t)
24672478 };
24682479 #ifdef DEBUG
2469
- xfs_agi_t *agi; /* allocation group header */
2480
+ struct xfs_agi *agi = bp->b_addr;
24702481
2471
- agi = XFS_BUF_TO_AGI(bp);
24722482 ASSERT(agi->agi_magicnum == cpu_to_be32(XFS_AGI_MAGIC));
24732483 #endif
24742484
....@@ -2499,22 +2509,21 @@
24992509 xfs_agi_verify(
25002510 struct xfs_buf *bp)
25012511 {
2502
- struct xfs_mount *mp = bp->b_target->bt_mount;
2503
- struct xfs_agi *agi = XFS_BUF_TO_AGI(bp);
2512
+ struct xfs_mount *mp = bp->b_mount;
2513
+ struct xfs_agi *agi = bp->b_addr;
25042514 int i;
25052515
25062516 if (xfs_sb_version_hascrc(&mp->m_sb)) {
25072517 if (!uuid_equal(&agi->agi_uuid, &mp->m_sb.sb_meta_uuid))
25082518 return __this_address;
2509
- if (!xfs_log_check_lsn(mp,
2510
- be64_to_cpu(XFS_BUF_TO_AGI(bp)->agi_lsn)))
2519
+ if (!xfs_log_check_lsn(mp, be64_to_cpu(agi->agi_lsn)))
25112520 return __this_address;
25122521 }
25132522
25142523 /*
25152524 * Validate the magic number of the agi block.
25162525 */
2517
- if (agi->agi_magicnum != cpu_to_be32(XFS_AGI_MAGIC))
2526
+ if (!xfs_verify_magic(bp, agi->agi_magicnum))
25182527 return __this_address;
25192528 if (!XFS_AGI_GOOD_VERSION(be32_to_cpu(agi->agi_versionnum)))
25202529 return __this_address;
....@@ -2551,7 +2560,7 @@
25512560 xfs_agi_read_verify(
25522561 struct xfs_buf *bp)
25532562 {
2554
- struct xfs_mount *mp = bp->b_target->bt_mount;
2563
+ struct xfs_mount *mp = bp->b_mount;
25552564 xfs_failaddr_t fa;
25562565
25572566 if (xfs_sb_version_hascrc(&mp->m_sb) &&
....@@ -2568,8 +2577,9 @@
25682577 xfs_agi_write_verify(
25692578 struct xfs_buf *bp)
25702579 {
2571
- struct xfs_mount *mp = bp->b_target->bt_mount;
2580
+ struct xfs_mount *mp = bp->b_mount;
25722581 struct xfs_buf_log_item *bip = bp->b_log_item;
2582
+ struct xfs_agi *agi = bp->b_addr;
25732583 xfs_failaddr_t fa;
25742584
25752585 fa = xfs_agi_verify(bp);
....@@ -2582,12 +2592,13 @@
25822592 return;
25832593
25842594 if (bip)
2585
- XFS_BUF_TO_AGI(bp)->agi_lsn = cpu_to_be64(bip->bli_item.li_lsn);
2595
+ agi->agi_lsn = cpu_to_be64(bip->bli_item.li_lsn);
25862596 xfs_buf_update_cksum(bp, XFS_AGI_CRC_OFF);
25872597 }
25882598
25892599 const struct xfs_buf_ops xfs_agi_buf_ops = {
25902600 .name = "xfs_agi",
2601
+ .magic = { cpu_to_be32(XFS_AGI_MAGIC), cpu_to_be32(XFS_AGI_MAGIC) },
25912602 .verify_read = xfs_agi_read_verify,
25922603 .verify_write = xfs_agi_write_verify,
25932604 .verify_struct = xfs_agi_verify,
....@@ -2637,8 +2648,8 @@
26372648 if (error)
26382649 return error;
26392650
2640
- agi = XFS_BUF_TO_AGI(*bpp);
2641
- pag = xfs_perag_get(mp, agno);
2651
+ agi = (*bpp)->b_addr;
2652
+ pag = (*bpp)->b_pag;
26422653 if (!pag->pagi_init) {
26432654 pag->pagi_freecount = be32_to_cpu(agi->agi_freecount);
26442655 pag->pagi_count = be32_to_cpu(agi->agi_count);
....@@ -2651,7 +2662,6 @@
26512662 */
26522663 ASSERT(pag->pagi_freecount == be32_to_cpu(agi->agi_freecount) ||
26532664 XFS_FORCED_SHUTDOWN(mp));
2654
- xfs_perag_put(pag);
26552665 return 0;
26562666 }
26572667
....@@ -2726,8 +2736,8 @@
27262736 xfs_agino_t low;
27272737 xfs_agino_t high;
27282738
2729
- low = XFS_OFFBNO_TO_AGINO(cur->bc_mp, bno, 0);
2730
- high = XFS_OFFBNO_TO_AGINO(cur->bc_mp, bno + len, 0) - 1;
2739
+ low = XFS_AGB_TO_AGINO(cur->bc_mp, bno);
2740
+ high = XFS_AGB_TO_AGINO(cur->bc_mp, bno + len) - 1;
27312741
27322742 return xfs_ialloc_has_inode_record(cur, low, high, exists);
27332743 }
....@@ -2773,3 +2783,183 @@
27732783 *freecount = ci.freecount;
27742784 return 0;
27752785 }
2786
+
2787
+/*
2788
+ * Initialize inode-related geometry information.
2789
+ *
2790
+ * Compute the inode btree min and max levels and set maxicount.
2791
+ *
2792
+ * Set the inode cluster size. This may still be overridden by the file
2793
+ * system block size if it is larger than the chosen cluster size.
2794
+ *
2795
+ * For v5 filesystems, scale the cluster size with the inode size to keep a
2796
+ * constant ratio of inode per cluster buffer, but only if mkfs has set the
2797
+ * inode alignment value appropriately for larger cluster sizes.
2798
+ *
2799
+ * Then compute the inode cluster alignment information.
2800
+ */
2801
+void
2802
+xfs_ialloc_setup_geometry(
2803
+ struct xfs_mount *mp)
2804
+{
2805
+ struct xfs_sb *sbp = &mp->m_sb;
2806
+ struct xfs_ino_geometry *igeo = M_IGEO(mp);
2807
+ uint64_t icount;
2808
+ uint inodes;
2809
+
2810
+ igeo->new_diflags2 = 0;
2811
+ if (xfs_sb_version_hasbigtime(&mp->m_sb))
2812
+ igeo->new_diflags2 |= XFS_DIFLAG2_BIGTIME;
2813
+
2814
+ /* Compute inode btree geometry. */
2815
+ igeo->agino_log = sbp->sb_inopblog + sbp->sb_agblklog;
2816
+ igeo->inobt_mxr[0] = xfs_inobt_maxrecs(mp, sbp->sb_blocksize, 1);
2817
+ igeo->inobt_mxr[1] = xfs_inobt_maxrecs(mp, sbp->sb_blocksize, 0);
2818
+ igeo->inobt_mnr[0] = igeo->inobt_mxr[0] / 2;
2819
+ igeo->inobt_mnr[1] = igeo->inobt_mxr[1] / 2;
2820
+
2821
+ igeo->ialloc_inos = max_t(uint16_t, XFS_INODES_PER_CHUNK,
2822
+ sbp->sb_inopblock);
2823
+ igeo->ialloc_blks = igeo->ialloc_inos >> sbp->sb_inopblog;
2824
+
2825
+ if (sbp->sb_spino_align)
2826
+ igeo->ialloc_min_blks = sbp->sb_spino_align;
2827
+ else
2828
+ igeo->ialloc_min_blks = igeo->ialloc_blks;
2829
+
2830
+ /* Compute and fill in value of m_ino_geo.inobt_maxlevels. */
2831
+ inodes = (1LL << XFS_INO_AGINO_BITS(mp)) >> XFS_INODES_PER_CHUNK_LOG;
2832
+ igeo->inobt_maxlevels = xfs_btree_compute_maxlevels(igeo->inobt_mnr,
2833
+ inodes);
2834
+
2835
+ /*
2836
+ * Set the maximum inode count for this filesystem, being careful not
2837
+ * to use obviously garbage sb_inopblog/sb_inopblock values. Regular
2838
+ * users should never get here due to failing sb verification, but
2839
+ * certain users (xfs_db) need to be usable even with corrupt metadata.
2840
+ */
2841
+ if (sbp->sb_imax_pct && igeo->ialloc_blks) {
2842
+ /*
2843
+ * Make sure the maximum inode count is a multiple
2844
+ * of the units we allocate inodes in.
2845
+ */
2846
+ icount = sbp->sb_dblocks * sbp->sb_imax_pct;
2847
+ do_div(icount, 100);
2848
+ do_div(icount, igeo->ialloc_blks);
2849
+ igeo->maxicount = XFS_FSB_TO_INO(mp,
2850
+ icount * igeo->ialloc_blks);
2851
+ } else {
2852
+ igeo->maxicount = 0;
2853
+ }
2854
+
2855
+ /*
2856
+ * Compute the desired size of an inode cluster buffer size, which
2857
+ * starts at 8K and (on v5 filesystems) scales up with larger inode
2858
+ * sizes.
2859
+ *
2860
+ * Preserve the desired inode cluster size because the sparse inodes
2861
+ * feature uses that desired size (not the actual size) to compute the
2862
+ * sparse inode alignment. The mount code validates this value, so we
2863
+ * cannot change the behavior.
2864
+ */
2865
+ igeo->inode_cluster_size_raw = XFS_INODE_BIG_CLUSTER_SIZE;
2866
+ if (xfs_sb_version_has_v3inode(&mp->m_sb)) {
2867
+ int new_size = igeo->inode_cluster_size_raw;
2868
+
2869
+ new_size *= mp->m_sb.sb_inodesize / XFS_DINODE_MIN_SIZE;
2870
+ if (mp->m_sb.sb_inoalignmt >= XFS_B_TO_FSBT(mp, new_size))
2871
+ igeo->inode_cluster_size_raw = new_size;
2872
+ }
2873
+
2874
+ /* Calculate inode cluster ratios. */
2875
+ if (igeo->inode_cluster_size_raw > mp->m_sb.sb_blocksize)
2876
+ igeo->blocks_per_cluster = XFS_B_TO_FSBT(mp,
2877
+ igeo->inode_cluster_size_raw);
2878
+ else
2879
+ igeo->blocks_per_cluster = 1;
2880
+ igeo->inode_cluster_size = XFS_FSB_TO_B(mp, igeo->blocks_per_cluster);
2881
+ igeo->inodes_per_cluster = XFS_FSB_TO_INO(mp, igeo->blocks_per_cluster);
2882
+
2883
+ /* Calculate inode cluster alignment. */
2884
+ if (xfs_sb_version_hasalign(&mp->m_sb) &&
2885
+ mp->m_sb.sb_inoalignmt >= igeo->blocks_per_cluster)
2886
+ igeo->cluster_align = mp->m_sb.sb_inoalignmt;
2887
+ else
2888
+ igeo->cluster_align = 1;
2889
+ igeo->inoalign_mask = igeo->cluster_align - 1;
2890
+ igeo->cluster_align_inodes = XFS_FSB_TO_INO(mp, igeo->cluster_align);
2891
+
2892
+ /*
2893
+ * If we are using stripe alignment, check whether
2894
+ * the stripe unit is a multiple of the inode alignment
2895
+ */
2896
+ if (mp->m_dalign && igeo->inoalign_mask &&
2897
+ !(mp->m_dalign & igeo->inoalign_mask))
2898
+ igeo->ialloc_align = mp->m_dalign;
2899
+ else
2900
+ igeo->ialloc_align = 0;
2901
+}
2902
+
2903
+/* Compute the location of the root directory inode that is laid out by mkfs. */
2904
+xfs_ino_t
2905
+xfs_ialloc_calc_rootino(
2906
+ struct xfs_mount *mp,
2907
+ int sunit)
2908
+{
2909
+ struct xfs_ino_geometry *igeo = M_IGEO(mp);
2910
+ xfs_agblock_t first_bno;
2911
+
2912
+ /*
2913
+ * Pre-calculate the geometry of AG 0. We know what it looks like
2914
+ * because libxfs knows how to create allocation groups now.
2915
+ *
2916
+ * first_bno is the first block in which mkfs could possibly have
2917
+ * allocated the root directory inode, once we factor in the metadata
2918
+ * that mkfs formats before it. Namely, the four AG headers...
2919
+ */
2920
+ first_bno = howmany(4 * mp->m_sb.sb_sectsize, mp->m_sb.sb_blocksize);
2921
+
2922
+ /* ...the two free space btree roots... */
2923
+ first_bno += 2;
2924
+
2925
+ /* ...the inode btree root... */
2926
+ first_bno += 1;
2927
+
2928
+ /* ...the initial AGFL... */
2929
+ first_bno += xfs_alloc_min_freelist(mp, NULL);
2930
+
2931
+ /* ...the free inode btree root... */
2932
+ if (xfs_sb_version_hasfinobt(&mp->m_sb))
2933
+ first_bno++;
2934
+
2935
+ /* ...the reverse mapping btree root... */
2936
+ if (xfs_sb_version_hasrmapbt(&mp->m_sb))
2937
+ first_bno++;
2938
+
2939
+ /* ...the reference count btree... */
2940
+ if (xfs_sb_version_hasreflink(&mp->m_sb))
2941
+ first_bno++;
2942
+
2943
+ /*
2944
+ * ...and the log, if it is allocated in the first allocation group.
2945
+ *
2946
+ * This can happen with filesystems that only have a single
2947
+ * allocation group, or very odd geometries created by old mkfs
2948
+ * versions on very small filesystems.
2949
+ */
2950
+ if (mp->m_sb.sb_logstart &&
2951
+ XFS_FSB_TO_AGNO(mp, mp->m_sb.sb_logstart) == 0)
2952
+ first_bno += mp->m_sb.sb_logblocks;
2953
+
2954
+ /*
2955
+ * Now round first_bno up to whatever allocation alignment is given
2956
+ * by the filesystem or was passed in.
2957
+ */
2958
+ if (xfs_sb_version_hasdalign(&mp->m_sb) && igeo->ialloc_align > 0)
2959
+ first_bno = roundup(first_bno, sunit);
2960
+ else if (xfs_sb_version_hasalign(&mp->m_sb) &&
2961
+ mp->m_sb.sb_inoalignmt > 1)
2962
+ first_bno = roundup(first_bno, mp->m_sb.sb_inoalignmt);
2963
+
2964
+ return XFS_AGINO_TO_INO(mp, 0, XFS_AGB_TO_AGINO(mp, first_bno));
2965
+}