Skip to content

Commit 2bea8df

Browse files
author
Darrick J. Wong
committed
xfs: always scrub record/key order of interior records
In commit d47fef9, we removed the firstrec and firstkey fields of struct xchk_btree because Christoph thought they were unnecessary because we could use the record index in the btree cursor. This is incorrect because bc_ptrs (now bc_levels[].ptr) tracks the cursor position within a specific btree block, not within the entire level. The end result is that scrub no longer detects situations where the rightmost record of a block is identical to the leftmost record of that block's right sibling. Fix this regression by reintroducing record validity booleans so that order checking skips *only* the leftmost record/key in each level. Fixes: d47fef9 ("xfs: don't track firstrec/firstkey separately in xchk_btree") Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com>
1 parent c99f99f commit 2bea8df

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

fs/xfs/scrub/btree.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,12 @@ xchk_btree_rec(
151151

152152
trace_xchk_btree_rec(bs->sc, cur, 0);
153153

154-
/* If this isn't the first record, are they in order? */
155-
if (cur->bc_levels[0].ptr > 1 &&
154+
/* Are all records across all record blocks in order? */
155+
if (bs->lastrec_valid &&
156156
!cur->bc_ops->recs_inorder(cur, &bs->lastrec, rec))
157157
xchk_btree_set_corrupt(bs->sc, cur, 0);
158158
memcpy(&bs->lastrec, rec, cur->bc_ops->rec_len);
159+
bs->lastrec_valid = true;
159160

160161
if (cur->bc_nlevels == 1)
161162
return;
@@ -198,11 +199,12 @@ xchk_btree_key(
198199

199200
trace_xchk_btree_key(bs->sc, cur, level);
200201

201-
/* If this isn't the first key, are they in order? */
202-
if (cur->bc_levels[level].ptr > 1 &&
203-
!cur->bc_ops->keys_inorder(cur, &bs->lastkey[level - 1], key))
202+
/* Are all low keys across all node blocks in order? */
203+
if (bs->lastkey[level - 1].valid &&
204+
!cur->bc_ops->keys_inorder(cur, &bs->lastkey[level - 1].key, key))
204205
xchk_btree_set_corrupt(bs->sc, cur, level);
205-
memcpy(&bs->lastkey[level - 1], key, cur->bc_ops->key_len);
206+
memcpy(&bs->lastkey[level - 1].key, key, cur->bc_ops->key_len);
207+
bs->lastkey[level - 1].valid = true;
206208

207209
if (level + 1 >= cur->bc_nlevels)
208210
return;

fs/xfs/scrub/btree.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ typedef int (*xchk_btree_rec_fn)(
3131
struct xchk_btree *bs,
3232
const union xfs_btree_rec *rec);
3333

34+
struct xchk_btree_key {
35+
union xfs_btree_key key;
36+
bool valid;
37+
};
38+
3439
struct xchk_btree {
3540
/* caller-provided scrub state */
3641
struct xfs_scrub *sc;
@@ -40,11 +45,12 @@ struct xchk_btree {
4045
void *private;
4146

4247
/* internal scrub state */
48+
bool lastrec_valid;
4349
union xfs_btree_rec lastrec;
4450
struct list_head to_check;
4551

4652
/* this element must come last! */
47-
union xfs_btree_key lastkey[];
53+
struct xchk_btree_key lastkey[];
4854
};
4955

5056
/*

0 commit comments

Comments
 (0)