Skip to content

Commit db0502b

Browse files
author
Darrick J. Wong
committed
xfs: flag refcount btree records that could be merged
Complain if we encounter refcount btree records that could be merged. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com>
1 parent d5784ae commit db0502b

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

fs/xfs/scrub/refcount.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ xchk_refcountbt_xref(
333333
}
334334

335335
struct xchk_refcbt_records {
336+
/* Previous refcount record. */
337+
struct xfs_refcount_irec prev_rec;
338+
336339
/* The next AG block where we aren't expecting shared extents. */
337340
xfs_agblock_t next_unshared_agbno;
338341

@@ -390,6 +393,46 @@ xchk_refcountbt_xref_gaps(
390393
xchk_should_check_xref(sc, &error, &sc->sa.rmap_cur);
391394
}
392395

396+
static inline bool
397+
xchk_refcount_mergeable(
398+
struct xchk_refcbt_records *rrc,
399+
const struct xfs_refcount_irec *r2)
400+
{
401+
const struct xfs_refcount_irec *r1 = &rrc->prev_rec;
402+
403+
/* Ignore if prev_rec is not yet initialized. */
404+
if (r1->rc_blockcount > 0)
405+
return false;
406+
407+
if (r1->rc_domain != r2->rc_domain)
408+
return false;
409+
if (r1->rc_startblock + r1->rc_blockcount != r2->rc_startblock)
410+
return false;
411+
if (r1->rc_refcount != r2->rc_refcount)
412+
return false;
413+
if ((unsigned long long)r1->rc_blockcount + r2->rc_blockcount >
414+
MAXREFCEXTLEN)
415+
return false;
416+
417+
return true;
418+
}
419+
420+
/* Flag failures for records that could be merged. */
421+
STATIC void
422+
xchk_refcountbt_check_mergeable(
423+
struct xchk_btree *bs,
424+
struct xchk_refcbt_records *rrc,
425+
const struct xfs_refcount_irec *irec)
426+
{
427+
if (bs->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
428+
return;
429+
430+
if (xchk_refcount_mergeable(rrc, irec))
431+
xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
432+
433+
memcpy(&rrc->prev_rec, irec, sizeof(struct xfs_refcount_irec));
434+
}
435+
393436
/* Scrub a refcountbt record. */
394437
STATIC int
395438
xchk_refcountbt_rec(
@@ -414,6 +457,7 @@ xchk_refcountbt_rec(
414457
xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
415458
rrc->prev_domain = irec.rc_domain;
416459

460+
xchk_refcountbt_check_mergeable(bs, rrc, &irec);
417461
xchk_refcountbt_xref(bs->sc, &irec);
418462

419463
/*

0 commit comments

Comments
 (0)