hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/fs/xfs/scrub/btree.c
....@@ -9,14 +9,7 @@
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"
15
-#include "xfs_log_format.h"
16
-#include "xfs_trans.h"
17
-#include "xfs_sb.h"
18
-#include "xfs_inode.h"
19
-#include "xfs_alloc.h"
2013 #include "scrub/scrub.h"
2114 #include "scrub/common.h"
2215 #include "scrub/btree.h"
....@@ -415,8 +408,17 @@
415408 struct xfs_btree_cur *cur = bs->cur;
416409 struct check_owner *co;
417410
418
- if ((cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) && bp == NULL)
411
+ /*
412
+ * In theory, xfs_btree_get_block should only give us a null buffer
413
+ * pointer for the root of a root-in-inode btree type, but we need
414
+ * to check defensively here in case the cursor state is also screwed
415
+ * up.
416
+ */
417
+ if (bp == NULL) {
418
+ if (!(cur->bc_flags & XFS_BTREE_ROOT_IN_INODE))
419
+ xchk_btree_set_corrupt(bs->sc, bs->cur, level);
419420 return 0;
421
+ }
420422
421423 /*
422424 * We want to cross-reference each btree block with the bnobt
....@@ -592,31 +594,32 @@
592594 */
593595 int
594596 xchk_btree(
595
- struct xfs_scrub *sc,
596
- struct xfs_btree_cur *cur,
597
- xchk_btree_rec_fn scrub_fn,
598
- struct xfs_owner_info *oinfo,
599
- void *private)
597
+ struct xfs_scrub *sc,
598
+ struct xfs_btree_cur *cur,
599
+ xchk_btree_rec_fn scrub_fn,
600
+ const struct xfs_owner_info *oinfo,
601
+ void *private)
600602 {
601
- struct xchk_btree bs = { NULL };
602
- union xfs_btree_ptr ptr;
603
- union xfs_btree_ptr *pp;
604
- union xfs_btree_rec *recp;
605
- struct xfs_btree_block *block;
606
- int level;
607
- struct xfs_buf *bp;
608
- struct check_owner *co;
609
- struct check_owner *n;
610
- int i;
611
- int error = 0;
603
+ struct xchk_btree bs = {
604
+ .cur = cur,
605
+ .scrub_rec = scrub_fn,
606
+ .oinfo = oinfo,
607
+ .firstrec = true,
608
+ .private = private,
609
+ .sc = sc,
610
+ };
611
+ union xfs_btree_ptr ptr;
612
+ union xfs_btree_ptr *pp;
613
+ union xfs_btree_rec *recp;
614
+ struct xfs_btree_block *block;
615
+ int level;
616
+ struct xfs_buf *bp;
617
+ struct check_owner *co;
618
+ struct check_owner *n;
619
+ int i;
620
+ int error = 0;
612621
613622 /* Initialize scrub state */
614
- bs.cur = cur;
615
- bs.scrub_rec = scrub_fn;
616
- bs.oinfo = oinfo;
617
- bs.firstrec = true;
618
- bs.private = private;
619
- bs.sc = sc;
620623 for (i = 0; i < XFS_BTREE_MAXLEVELS; i++)
621624 bs.firstkey[i] = true;
622625 INIT_LIST_HEAD(&bs.to_check);