Skip to content

Commit 8c1771c

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
xfs: add a xfs_btree_ptrs_equal helper
This only has a single caller and thus might be a bit questionable, but I think it really improves the readability of xfs_btree_visit_block. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
1 parent 5076a60 commit 8c1771c

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

fs/xfs/libxfs/xfs_btree.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,17 @@ xfs_btree_set_ptr_null(
10431043
ptr->s = cpu_to_be32(NULLAGBLOCK);
10441044
}
10451045

1046+
static inline bool
1047+
xfs_btree_ptrs_equal(
1048+
struct xfs_btree_cur *cur,
1049+
union xfs_btree_ptr *ptr1,
1050+
union xfs_btree_ptr *ptr2)
1051+
{
1052+
if (cur->bc_ops->ptr_len == XFS_BTREE_LONG_PTR_LEN)
1053+
return ptr1->l == ptr2->l;
1054+
return ptr1->s == ptr2->s;
1055+
}
1056+
10461057
/*
10471058
* Get/set/init sibling pointers
10481059
*/
@@ -4365,7 +4376,7 @@ xfs_btree_visit_block(
43654376
{
43664377
struct xfs_btree_block *block;
43674378
struct xfs_buf *bp;
4368-
union xfs_btree_ptr rptr;
4379+
union xfs_btree_ptr rptr, bufptr;
43694380
int error;
43704381

43714382
/* do right sibling readahead */
@@ -4388,19 +4399,12 @@ xfs_btree_visit_block(
43884399
* return the same block without checking if the right sibling points
43894400
* back to us and creates a cyclic reference in the btree.
43904401
*/
4391-
if (cur->bc_ops->ptr_len == XFS_BTREE_LONG_PTR_LEN) {
4392-
if (be64_to_cpu(rptr.l) == XFS_DADDR_TO_FSB(cur->bc_mp,
4393-
xfs_buf_daddr(bp))) {
4394-
xfs_btree_mark_sick(cur);
4395-
return -EFSCORRUPTED;
4396-
}
4397-
} else {
4398-
if (be32_to_cpu(rptr.s) == xfs_daddr_to_agbno(cur->bc_mp,
4399-
xfs_buf_daddr(bp))) {
4400-
xfs_btree_mark_sick(cur);
4401-
return -EFSCORRUPTED;
4402-
}
4402+
xfs_btree_buf_to_ptr(cur, bp, &bufptr);
4403+
if (xfs_btree_ptrs_equal(cur, &rptr, &bufptr)) {
4404+
xfs_btree_mark_sick(cur);
4405+
return -EFSCORRUPTED;
44034406
}
4407+
44044408
return xfs_btree_lookup_get_block(cur, level, &rptr, &block);
44054409
}
44064410

0 commit comments

Comments
 (0)