• Darrick J. Wong's avatar
    xfs: estimate post-merge refcounts correctly · b25d1984
    Darrick J. Wong authored
    Upon enabling fsdax + reflink for XFS, xfs/179 began to report refcount
    metadata corruptions after being run.  Specifically, xfs_repair noticed
    single-block refcount records that could be combined but had not been.
    
    The root cause of this is improper MAXREFCOUNT edge case handling in
    xfs_refcount_merge_extents.  When we're trying to find candidates for a
    refcount btree record merge, we compute the refcount attribute of the
    merged record, but we fail to account for the fact that once a record
    hits rc_refcount == MAXREFCOUNT, it is pinned that way forever.  Hence
    the computed refcount is wrong, and we fail to merge the extents.
    
    Fix this by adjusting the merge predicates to compute the adjusted
    refcount correctly.
    
    Fixes: 31727258 ("xfs: adjust refcount of an extent of blocks in refcount btree")
    Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
    Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
    Reviewed-by: default avatarXiao Yang <yangx.jy@fujitsu.com>
    b25d1984
xfs_refcount.c 53.5 KB