Skip to content

Commit add46b3

Browse files
committed
xfs: set buffer ops when repair probes for btree type
In xrep_findroot_block, we work out the btree type and correctness of a given block by calling different btree verifiers on root block candidates. However, we leave the NULL b_ops while ->verify_read validates the block, which means that if the verifier calls xfs_buf_verifier_error it'll crash on the null b_ops. Fix it to set b_ops before calling the verifier and unsetting it if the verifier fails. Furthermore, improve the documentation around xfs_buf_ensure_ops, which is the function that is responsible for cleaning up the b_ops state of buffers that go through xrep_findroot_block but don't match anything. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Brian Foster <bfoster@redhat.com>
1 parent 465fa17 commit add46b3

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

fs/xfs/scrub/repair.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,18 +768,23 @@ xrep_findroot_block(
768768
if (!uuid_equal(&btblock->bb_u.s.bb_uuid,
769769
&mp->m_sb.sb_meta_uuid))
770770
goto out;
771+
/*
772+
* Read verifiers can reference b_ops, so we set the pointer
773+
* here. If the verifier fails we'll reset the buffer state
774+
* to what it was before we touched the buffer.
775+
*/
776+
bp->b_ops = fab->buf_ops;
771777
fab->buf_ops->verify_read(bp);
772778
if (bp->b_error) {
779+
bp->b_ops = NULL;
773780
bp->b_error = 0;
774781
goto out;
775782
}
776783

777784
/*
778785
* Some read verifiers will (re)set b_ops, so we must be
779-
* careful not to blow away any such assignment.
786+
* careful not to change b_ops after running the verifier.
780787
*/
781-
if (!bp->b_ops)
782-
bp->b_ops = fab->buf_ops;
783788
}
784789

785790
/*

fs/xfs/xfs_buf.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,10 +776,26 @@ _xfs_buf_read(
776776
}
777777

778778
/*
779+
* Set buffer ops on an unchecked buffer and validate it, if possible.
780+
*
779781
* If the caller passed in an ops structure and the buffer doesn't have ops
780782
* assigned, set the ops and use them to verify the contents. If the contents
781783
* cannot be verified, we'll clear XBF_DONE. We assume the buffer has no
782784
* recorded errors and is already in XBF_DONE state.
785+
*
786+
* Under normal operations, every in-core buffer must have buffer ops assigned
787+
* to them when the buffer is read in from disk so that we can validate the
788+
* metadata.
789+
*
790+
* However, there are two scenarios where one can encounter in-core buffers
791+
* that don't have buffer ops. The first is during log recovery of buffers on
792+
* a V4 filesystem, though these buffers are purged at the end of recovery.
793+
*
794+
* The other is online repair, which tries to match arbitrary metadata blocks
795+
* with btree types in order to find the root. If online repair doesn't match
796+
* the buffer with /any/ btree type, the buffer remains in memory in DONE state
797+
* with no ops, and a subsequent read_buf call from elsewhere will not set the
798+
* ops. This function helps us fix this situation.
783799
*/
784800
int
785801
xfs_buf_ensure_ops(

0 commit comments

Comments
 (0)