@@ -31,6 +31,12 @@ xchk_setup_ag_allocbt(
3131}
3232
3333/* Free space btree scrubber. */
34+
35+ struct xchk_alloc {
36+ /* Previous free space extent. */
37+ struct xfs_alloc_rec_incore prev ;
38+ };
39+
3440/*
3541 * Ensure there's a corresponding cntbt/bnobt record matching this
3642 * bnobt/cntbt record, respectively.
@@ -93,20 +99,40 @@ xchk_allocbt_xref(
9399 xchk_xref_is_not_cow_staging (sc , agbno , len );
94100}
95101
102+ /* Flag failures for records that could be merged. */
103+ STATIC void
104+ xchk_allocbt_mergeable (
105+ struct xchk_btree * bs ,
106+ struct xchk_alloc * ca ,
107+ const struct xfs_alloc_rec_incore * irec )
108+ {
109+ if (bs -> sc -> sm -> sm_flags & XFS_SCRUB_OFLAG_CORRUPT )
110+ return ;
111+
112+ if (ca -> prev .ar_blockcount > 0 &&
113+ ca -> prev .ar_startblock + ca -> prev .ar_blockcount == irec -> ar_startblock &&
114+ ca -> prev .ar_blockcount + irec -> ar_blockcount < (uint32_t )~0U )
115+ xchk_btree_set_corrupt (bs -> sc , bs -> cur , 0 );
116+
117+ memcpy (& ca -> prev , irec , sizeof (* irec ));
118+ }
119+
96120/* Scrub a bnobt/cntbt record. */
97121STATIC int
98122xchk_allocbt_rec (
99123 struct xchk_btree * bs ,
100124 const union xfs_btree_rec * rec )
101125{
102126 struct xfs_alloc_rec_incore irec ;
127+ struct xchk_alloc * ca = bs -> private ;
103128
104129 xfs_alloc_btrec_to_irec (rec , & irec );
105130 if (xfs_alloc_check_irec (bs -> cur , & irec ) != NULL ) {
106131 xchk_btree_set_corrupt (bs -> sc , bs -> cur , 0 );
107132 return 0 ;
108133 }
109134
135+ xchk_allocbt_mergeable (bs , ca , & irec );
110136 xchk_allocbt_xref (bs -> sc , & irec );
111137
112138 return 0 ;
@@ -118,10 +144,11 @@ xchk_allocbt(
118144 struct xfs_scrub * sc ,
119145 xfs_btnum_t which )
120146{
147+ struct xchk_alloc ca = { };
121148 struct xfs_btree_cur * cur ;
122149
123150 cur = which == XFS_BTNUM_BNO ? sc -> sa .bno_cur : sc -> sa .cnt_cur ;
124- return xchk_btree (sc , cur , xchk_allocbt_rec , & XFS_RMAP_OINFO_AG , NULL );
151+ return xchk_btree (sc , cur , xchk_allocbt_rec , & XFS_RMAP_OINFO_AG , & ca );
125152}
126153
127154int
0 commit comments