hc
2024-05-11 297b60346df8beafee954a0fd7c2d64f33f3b9bc
kernel/fs/xfs/scrub/agheader_repair.c
....@@ -9,22 +9,17 @@
99 #include "xfs_format.h"
1010 #include "xfs_trans_resv.h"
1111 #include "xfs_mount.h"
12
-#include "xfs_defer.h"
1312 #include "xfs_btree.h"
14
-#include "xfs_bit.h"
1513 #include "xfs_log_format.h"
1614 #include "xfs_trans.h"
1715 #include "xfs_sb.h"
18
-#include "xfs_inode.h"
1916 #include "xfs_alloc.h"
2017 #include "xfs_alloc_btree.h"
2118 #include "xfs_ialloc.h"
2219 #include "xfs_ialloc_btree.h"
2320 #include "xfs_rmap.h"
2421 #include "xfs_rmap_btree.h"
25
-#include "xfs_refcount.h"
2622 #include "xfs_refcount_btree.h"
27
-#include "scrub/xfs_scrub.h"
2823 #include "scrub/scrub.h"
2924 #include "scrub/common.h"
3025 #include "scrub/trace.h"
....@@ -54,7 +49,7 @@
5449
5550 /* Copy AG 0's superblock to this one. */
5651 xfs_buf_zero(bp, 0, BBTOB(bp->b_length));
57
- xfs_sb_to_disk(XFS_BUF_TO_SBP(bp), &mp->m_sb);
52
+ xfs_sb_to_disk(bp->b_addr, &mp->m_sb);
5853
5954 /* Write this to disk. */
6055 xfs_trans_buf_set_type(sc->tp, bp, XFS_BLFT_SB_BUF);
....@@ -145,7 +140,7 @@
145140 struct xrep_find_ag_btree *fab,
146141 struct xfs_buf *agfl_bp)
147142 {
148
- struct xfs_agf *old_agf = XFS_BUF_TO_AGF(agf_bp);
143
+ struct xfs_agf *old_agf = agf_bp->b_addr;
149144 int error;
150145
151146 /* Go find the root data. */
....@@ -186,7 +181,7 @@
186181 struct xfs_agf *old_agf)
187182 {
188183 struct xfs_mount *mp = sc->mp;
189
- struct xfs_agf *agf = XFS_BUF_TO_AGF(agf_bp);
184
+ struct xfs_agf *agf = agf_bp->b_addr;
190185
191186 memcpy(old_agf, agf, sizeof(*old_agf));
192187 memset(agf, 0, BBTOB(agf_bp->b_length));
....@@ -243,7 +238,7 @@
243238 {
244239 struct xrep_agf_allocbt raa = { .sc = sc };
245240 struct xfs_btree_cur *cur = NULL;
246
- struct xfs_agf *agf = XFS_BUF_TO_AGF(agf_bp);
241
+ struct xfs_agf *agf = agf_bp->b_addr;
247242 struct xfs_mount *mp = sc->mp;
248243 xfs_agblock_t btreeblks;
249244 xfs_agblock_t blocks;
....@@ -307,7 +302,7 @@
307302 struct xfs_buf *agf_bp)
308303 {
309304 struct xfs_perag *pag;
310
- struct xfs_agf *agf = XFS_BUF_TO_AGF(agf_bp);
305
+ struct xfs_agf *agf = agf_bp->b_addr;
311306
312307 /* Trigger fdblocks recalculation */
313308 xfs_force_summary_recalc(sc->mp);
....@@ -341,23 +336,19 @@
341336 struct xrep_find_ag_btree fab[XREP_AGF_MAX] = {
342337 [XREP_AGF_BNOBT] = {
343338 .rmap_owner = XFS_RMAP_OWN_AG,
344
- .buf_ops = &xfs_allocbt_buf_ops,
345
- .magic = XFS_ABTB_CRC_MAGIC,
339
+ .buf_ops = &xfs_bnobt_buf_ops,
346340 },
347341 [XREP_AGF_CNTBT] = {
348342 .rmap_owner = XFS_RMAP_OWN_AG,
349
- .buf_ops = &xfs_allocbt_buf_ops,
350
- .magic = XFS_ABTC_CRC_MAGIC,
343
+ .buf_ops = &xfs_cntbt_buf_ops,
351344 },
352345 [XREP_AGF_RMAPBT] = {
353346 .rmap_owner = XFS_RMAP_OWN_AG,
354347 .buf_ops = &xfs_rmapbt_buf_ops,
355
- .magic = XFS_RMAP_CRC_MAGIC,
356348 },
357349 [XREP_AGF_REFCOUNTBT] = {
358350 .rmap_owner = XFS_RMAP_OWN_REFC,
359351 .buf_ops = &xfs_refcountbt_buf_ops,
360
- .magic = XFS_REFC_CRC_MAGIC,
361352 },
362353 [XREP_AGF_END] = {
363354 .buf_ops = NULL,
....@@ -385,7 +376,7 @@
385376 if (error)
386377 return error;
387378 agf_bp->b_ops = &xfs_agf_buf_ops;
388
- agf = XFS_BUF_TO_AGF(agf_bp);
379
+ agf = agf_bp->b_addr;
389380
390381 /*
391382 * Load the AGFL so that we can screen out OWN_AG blocks that are on
....@@ -404,7 +395,7 @@
404395 * Spot-check the AGFL blocks; if they're obviously corrupt then
405396 * there's nothing we can do but bail out.
406397 */
407
- error = xfs_agfl_walk(sc->mp, XFS_BUF_TO_AGF(agf_bp), agfl_bp,
398
+ error = xfs_agfl_walk(sc->mp, agf_bp->b_addr, agfl_bp,
408399 xrep_agf_check_agfl_block, sc);
409400 if (error)
410401 return error;
....@@ -438,10 +429,10 @@
438429
439430 struct xrep_agfl {
440431 /* Bitmap of other OWN_AG metadata blocks. */
441
- struct xfs_bitmap agmetablocks;
432
+ struct xbitmap agmetablocks;
442433
443434 /* Bitmap of free space. */
444
- struct xfs_bitmap *freesp;
435
+ struct xbitmap *freesp;
445436
446437 struct xfs_scrub *sc;
447438 };
....@@ -462,14 +453,14 @@
462453
463454 /* Record all the OWN_AG blocks. */
464455 if (rec->rm_owner == XFS_RMAP_OWN_AG) {
465
- fsb = XFS_AGB_TO_FSB(cur->bc_mp, cur->bc_private.a.agno,
456
+ fsb = XFS_AGB_TO_FSB(cur->bc_mp, cur->bc_ag.agno,
466457 rec->rm_startblock);
467
- error = xfs_bitmap_set(ra->freesp, fsb, rec->rm_blockcount);
458
+ error = xbitmap_set(ra->freesp, fsb, rec->rm_blockcount);
468459 if (error)
469460 return error;
470461 }
471462
472
- return xfs_bitmap_set_btcur_path(&ra->agmetablocks, cur);
463
+ return xbitmap_set_btcur_path(&ra->agmetablocks, cur);
473464 }
474465
475466 /*
....@@ -485,19 +476,17 @@
485476 xrep_agfl_collect_blocks(
486477 struct xfs_scrub *sc,
487478 struct xfs_buf *agf_bp,
488
- struct xfs_bitmap *agfl_extents,
479
+ struct xbitmap *agfl_extents,
489480 xfs_agblock_t *flcount)
490481 {
491482 struct xrep_agfl ra;
492483 struct xfs_mount *mp = sc->mp;
493484 struct xfs_btree_cur *cur;
494
- struct xfs_bitmap_range *br;
495
- struct xfs_bitmap_range *n;
496485 int error;
497486
498487 ra.sc = sc;
499488 ra.freesp = agfl_extents;
500
- xfs_bitmap_init(&ra.agmetablocks);
489
+ xbitmap_init(&ra.agmetablocks);
501490
502491 /* Find all space used by the free space btrees & rmapbt. */
503492 cur = xfs_rmapbt_init_cursor(mp, sc->tp, agf_bp, sc->sa.agno);
....@@ -509,7 +498,7 @@
509498 /* Find all blocks currently being used by the bnobt. */
510499 cur = xfs_allocbt_init_cursor(mp, sc->tp, agf_bp, sc->sa.agno,
511500 XFS_BTNUM_BNO);
512
- error = xfs_bitmap_set_btblocks(&ra.agmetablocks, cur);
501
+ error = xbitmap_set_btblocks(&ra.agmetablocks, cur);
513502 if (error)
514503 goto err;
515504 xfs_btree_del_cursor(cur, error);
....@@ -517,7 +506,7 @@
517506 /* Find all blocks currently being used by the cntbt. */
518507 cur = xfs_allocbt_init_cursor(mp, sc->tp, agf_bp, sc->sa.agno,
519508 XFS_BTNUM_CNT);
520
- error = xfs_bitmap_set_btblocks(&ra.agmetablocks, cur);
509
+ error = xbitmap_set_btblocks(&ra.agmetablocks, cur);
521510 if (error)
522511 goto err;
523512
....@@ -527,8 +516,8 @@
527516 * Drop the freesp meta blocks that are in use by btrees.
528517 * The remaining blocks /should/ be AGFL blocks.
529518 */
530
- error = xfs_bitmap_disunion(agfl_extents, &ra.agmetablocks);
531
- xfs_bitmap_destroy(&ra.agmetablocks);
519
+ error = xbitmap_disunion(agfl_extents, &ra.agmetablocks);
520
+ xbitmap_destroy(&ra.agmetablocks);
532521 if (error)
533522 return error;
534523
....@@ -536,18 +525,12 @@
536525 * Calculate the new AGFL size. If we found more blocks than fit in
537526 * the AGFL we'll free them later.
538527 */
539
- *flcount = 0;
540
- for_each_xfs_bitmap_extent(br, n, agfl_extents) {
541
- *flcount += br->len;
542
- if (*flcount > xfs_agfl_size(mp))
543
- break;
544
- }
545
- if (*flcount > xfs_agfl_size(mp))
546
- *flcount = xfs_agfl_size(mp);
528
+ *flcount = min_t(uint64_t, xbitmap_hweight(agfl_extents),
529
+ xfs_agfl_size(mp));
547530 return 0;
548531
549532 err:
550
- xfs_bitmap_destroy(&ra.agmetablocks);
533
+ xbitmap_destroy(&ra.agmetablocks);
551534 xfs_btree_del_cursor(cur, error);
552535 return error;
553536 }
....@@ -559,7 +542,7 @@
559542 struct xfs_buf *agf_bp,
560543 xfs_agblock_t flcount)
561544 {
562
- struct xfs_agf *agf = XFS_BUF_TO_AGF(agf_bp);
545
+ struct xfs_agf *agf = agf_bp->b_addr;
563546
564547 ASSERT(flcount <= xfs_agfl_size(sc->mp));
565548
....@@ -582,13 +565,13 @@
582565 xrep_agfl_init_header(
583566 struct xfs_scrub *sc,
584567 struct xfs_buf *agfl_bp,
585
- struct xfs_bitmap *agfl_extents,
568
+ struct xbitmap *agfl_extents,
586569 xfs_agblock_t flcount)
587570 {
588571 struct xfs_mount *mp = sc->mp;
589572 __be32 *agfl_bno;
590
- struct xfs_bitmap_range *br;
591
- struct xfs_bitmap_range *n;
573
+ struct xbitmap_range *br;
574
+ struct xbitmap_range *n;
592575 struct xfs_agfl *agfl;
593576 xfs_agblock_t agbno;
594577 unsigned int fl_off;
....@@ -611,8 +594,8 @@
611594 * step.
612595 */
613596 fl_off = 0;
614
- agfl_bno = XFS_BUF_TO_AGFL_BNO(mp, agfl_bp);
615
- for_each_xfs_bitmap_extent(br, n, agfl_extents) {
597
+ agfl_bno = xfs_buf_to_agfl_bno(agfl_bp);
598
+ for_each_xbitmap_extent(br, n, agfl_extents) {
616599 agbno = XFS_FSB_TO_AGBNO(mp, br->start);
617600
618601 trace_xrep_agfl_insert(mp, sc->sa.agno, agbno, br->len);
....@@ -646,8 +629,7 @@
646629 xrep_agfl(
647630 struct xfs_scrub *sc)
648631 {
649
- struct xfs_owner_info oinfo;
650
- struct xfs_bitmap agfl_extents;
632
+ struct xbitmap agfl_extents;
651633 struct xfs_mount *mp = sc->mp;
652634 struct xfs_buf *agf_bp;
653635 struct xfs_buf *agfl_bp;
....@@ -659,7 +641,7 @@
659641 return -EOPNOTSUPP;
660642
661643 xchk_perag_get(sc->mp, &sc->sa);
662
- xfs_bitmap_init(&agfl_extents);
644
+ xbitmap_init(&agfl_extents);
663645
664646 /*
665647 * Read the AGF so that we can query the rmapbt. We hope that there's
....@@ -669,8 +651,6 @@
669651 error = xfs_alloc_read_agf(mp, sc->tp, sc->sa.agno, 0, &agf_bp);
670652 if (error)
671653 return error;
672
- if (!agf_bp)
673
- return -ENOMEM;
674654
675655 /*
676656 * Make sure we have the AGFL buffer, as scrub might have decided it
....@@ -708,10 +688,10 @@
708688 goto err;
709689
710690 /* Dump any AGFL overflow. */
711
- xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_AG);
712
- return xrep_reap_extents(sc, &agfl_extents, &oinfo, XFS_AG_RESV_AGFL);
691
+ error = xrep_reap_extents(sc, &agfl_extents, &XFS_RMAP_OINFO_AG,
692
+ XFS_AG_RESV_AGFL);
713693 err:
714
- xfs_bitmap_destroy(&agfl_extents);
694
+ xbitmap_destroy(&agfl_extents);
715695 return error;
716696 }
717697
....@@ -745,8 +725,6 @@
745725 error = xfs_alloc_read_agf(mp, sc->tp, sc->sa.agno, 0, &agf_bp);
746726 if (error)
747727 return error;
748
- if (!agf_bp)
749
- return -ENOMEM;
750728
751729 /* Find the btree roots. */
752730 error = xrep_find_ag_btree_roots(sc, agf_bp, fab, NULL);
....@@ -775,7 +753,7 @@
775753 struct xfs_buf *agi_bp,
776754 struct xfs_agi *old_agi)
777755 {
778
- struct xfs_agi *agi = XFS_BUF_TO_AGI(agi_bp);
756
+ struct xfs_agi *agi = agi_bp->b_addr;
779757 struct xfs_mount *mp = sc->mp;
780758
781759 memcpy(old_agi, agi, sizeof(*old_agi));
....@@ -821,7 +799,7 @@
821799 struct xfs_buf *agi_bp)
822800 {
823801 struct xfs_btree_cur *cur;
824
- struct xfs_agi *agi = XFS_BUF_TO_AGI(agi_bp);
802
+ struct xfs_agi *agi = agi_bp->b_addr;
825803 struct xfs_mount *mp = sc->mp;
826804 xfs_agino_t count;
827805 xfs_agino_t freecount;
....@@ -832,10 +810,34 @@
832810 error = xfs_ialloc_count_inodes(cur, &count, &freecount);
833811 if (error)
834812 goto err;
813
+ if (xfs_sb_version_hasinobtcounts(&mp->m_sb)) {
814
+ xfs_agblock_t blocks;
815
+
816
+ error = xfs_btree_count_blocks(cur, &blocks);
817
+ if (error)
818
+ goto err;
819
+ agi->agi_iblocks = cpu_to_be32(blocks);
820
+ }
835821 xfs_btree_del_cursor(cur, error);
836822
837823 agi->agi_count = cpu_to_be32(count);
838824 agi->agi_freecount = cpu_to_be32(freecount);
825
+
826
+ if (xfs_sb_version_hasfinobt(&mp->m_sb) &&
827
+ xfs_sb_version_hasinobtcounts(&mp->m_sb)) {
828
+ xfs_agblock_t blocks;
829
+
830
+ cur = xfs_inobt_init_cursor(mp, sc->tp, agi_bp, sc->sa.agno,
831
+ XFS_BTNUM_FINO);
832
+ if (error)
833
+ goto err;
834
+ error = xfs_btree_count_blocks(cur, &blocks);
835
+ if (error)
836
+ goto err;
837
+ xfs_btree_del_cursor(cur, error);
838
+ agi->agi_fblocks = cpu_to_be32(blocks);
839
+ }
840
+
839841 return 0;
840842 err:
841843 xfs_btree_del_cursor(cur, error);
....@@ -849,7 +851,7 @@
849851 struct xfs_buf *agi_bp)
850852 {
851853 struct xfs_perag *pag;
852
- struct xfs_agi *agi = XFS_BUF_TO_AGI(agi_bp);
854
+ struct xfs_agi *agi = agi_bp->b_addr;
853855
854856 /* Trigger inode count recalculation */
855857 xfs_force_summary_recalc(sc->mp);
....@@ -876,12 +878,10 @@
876878 [XREP_AGI_INOBT] = {
877879 .rmap_owner = XFS_RMAP_OWN_INOBT,
878880 .buf_ops = &xfs_inobt_buf_ops,
879
- .magic = XFS_IBT_CRC_MAGIC,
880881 },
881882 [XREP_AGI_FINOBT] = {
882883 .rmap_owner = XFS_RMAP_OWN_INOBT,
883
- .buf_ops = &xfs_inobt_buf_ops,
884
- .magic = XFS_FIBT_CRC_MAGIC,
884
+ .buf_ops = &xfs_finobt_buf_ops,
885885 },
886886 [XREP_AGI_END] = {
887887 .buf_ops = NULL
....@@ -908,7 +908,7 @@
908908 if (error)
909909 return error;
910910 agi_bp->b_ops = &xfs_agi_buf_ops;
911
- agi = XFS_BUF_TO_AGI(agi_bp);
911
+ agi = agi_bp->b_addr;
912912
913913 /* Find the AGI btree roots. */
914914 error = xrep_agi_find_btrees(sc, fab);