提交 b25d1984 编写于 作者: D Darrick J. Wong

xfs: estimate post-merge refcounts correctly

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: NDarrick J. Wong <djwong@kernel.org>
Reviewed-by: NDave Chinner <dchinner@redhat.com>
Reviewed-by: NXiao Yang <yangx.jy@fujitsu.com>
上级 9d720a5a
...@@ -820,6 +820,17 @@ xfs_refc_valid( ...@@ -820,6 +820,17 @@ xfs_refc_valid(
return rc->rc_startblock != NULLAGBLOCK; return rc->rc_startblock != NULLAGBLOCK;
} }
static inline xfs_nlink_t
xfs_refc_merge_refcount(
const struct xfs_refcount_irec *irec,
enum xfs_refc_adjust_op adjust)
{
/* Once a record hits MAXREFCOUNT, it is pinned there forever */
if (irec->rc_refcount == MAXREFCOUNT)
return MAXREFCOUNT;
return irec->rc_refcount + adjust;
}
static inline bool static inline bool
xfs_refc_want_merge_center( xfs_refc_want_merge_center(
const struct xfs_refcount_irec *left, const struct xfs_refcount_irec *left,
...@@ -831,6 +842,7 @@ xfs_refc_want_merge_center( ...@@ -831,6 +842,7 @@ xfs_refc_want_merge_center(
unsigned long long *ulenp) unsigned long long *ulenp)
{ {
unsigned long long ulen = left->rc_blockcount; unsigned long long ulen = left->rc_blockcount;
xfs_nlink_t new_refcount;
/* /*
* To merge with a center record, both shoulder records must be * To merge with a center record, both shoulder records must be
...@@ -846,9 +858,10 @@ xfs_refc_want_merge_center( ...@@ -846,9 +858,10 @@ xfs_refc_want_merge_center(
return false; return false;
/* The shoulder record refcounts must match the new refcount. */ /* The shoulder record refcounts must match the new refcount. */
if (left->rc_refcount != cleft->rc_refcount + adjust) new_refcount = xfs_refc_merge_refcount(cleft, adjust);
if (left->rc_refcount != new_refcount)
return false; return false;
if (right->rc_refcount != cleft->rc_refcount + adjust) if (right->rc_refcount != new_refcount)
return false; return false;
/* /*
...@@ -871,6 +884,7 @@ xfs_refc_want_merge_left( ...@@ -871,6 +884,7 @@ xfs_refc_want_merge_left(
enum xfs_refc_adjust_op adjust) enum xfs_refc_adjust_op adjust)
{ {
unsigned long long ulen = left->rc_blockcount; unsigned long long ulen = left->rc_blockcount;
xfs_nlink_t new_refcount;
/* /*
* For a left merge, the left shoulder record must be adjacent to the * For a left merge, the left shoulder record must be adjacent to the
...@@ -881,7 +895,8 @@ xfs_refc_want_merge_left( ...@@ -881,7 +895,8 @@ xfs_refc_want_merge_left(
return false; return false;
/* Left shoulder record refcount must match the new refcount. */ /* Left shoulder record refcount must match the new refcount. */
if (left->rc_refcount != cleft->rc_refcount + adjust) new_refcount = xfs_refc_merge_refcount(cleft, adjust);
if (left->rc_refcount != new_refcount)
return false; return false;
/* /*
...@@ -903,6 +918,7 @@ xfs_refc_want_merge_right( ...@@ -903,6 +918,7 @@ xfs_refc_want_merge_right(
enum xfs_refc_adjust_op adjust) enum xfs_refc_adjust_op adjust)
{ {
unsigned long long ulen = right->rc_blockcount; unsigned long long ulen = right->rc_blockcount;
xfs_nlink_t new_refcount;
/* /*
* For a right merge, the right shoulder record must be adjacent to the * For a right merge, the right shoulder record must be adjacent to the
...@@ -913,7 +929,8 @@ xfs_refc_want_merge_right( ...@@ -913,7 +929,8 @@ xfs_refc_want_merge_right(
return false; return false;
/* Right shoulder record refcount must match the new refcount. */ /* Right shoulder record refcount must match the new refcount. */
if (right->rc_refcount != cright->rc_refcount + adjust) new_refcount = xfs_refc_merge_refcount(cright, adjust);
if (right->rc_refcount != new_refcount)
return false; return false;
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册