Skip to content

Commit 08daa3c

Browse files
committed
xfs: add repair helpers for the reference count btree
Add a couple of functions to the refcount btree and generic btree code that will be used to repair the refcountbt. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Dave Chinner <[email protected]>
1 parent 4d4f86b commit 08daa3c

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

fs/xfs/libxfs/xfs_btree.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4919,3 +4919,24 @@ xfs_btree_has_record(
49194919
*exists = false;
49204920
return error;
49214921
}
4922+
4923+
/* Are there more records in this btree? */
4924+
bool
4925+
xfs_btree_has_more_records(
4926+
struct xfs_btree_cur *cur)
4927+
{
4928+
struct xfs_btree_block *block;
4929+
struct xfs_buf *bp;
4930+
4931+
block = xfs_btree_get_block(cur, 0, &bp);
4932+
4933+
/* There are still records in this block. */
4934+
if (cur->bc_ptrs[0] < xfs_btree_get_numrecs(block))
4935+
return true;
4936+
4937+
/* There are more record blocks. */
4938+
if (cur->bc_flags & XFS_BTREE_LONG_PTRS)
4939+
return block->bb_u.l.bb_rightsib != cpu_to_be64(NULLFSBLOCK);
4940+
else
4941+
return block->bb_u.s.bb_rightsib != cpu_to_be32(NULLAGBLOCK);
4942+
}

fs/xfs/libxfs/xfs_btree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,5 +528,6 @@ union xfs_btree_key *xfs_btree_high_key_from_key(struct xfs_btree_cur *cur,
528528
union xfs_btree_key *key);
529529
int xfs_btree_has_record(struct xfs_btree_cur *cur, union xfs_btree_irec *low,
530530
union xfs_btree_irec *high, bool *exists);
531+
bool xfs_btree_has_more_records(struct xfs_btree_cur *cur);
531532

532533
#endif /* __XFS_BTREE_H__ */

fs/xfs/libxfs/xfs_refcount.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,23 @@ xfs_refcount_lookup_ge(
8888
return xfs_btree_lookup(cur, XFS_LOOKUP_GE, stat);
8989
}
9090

91+
/*
92+
* Look up the first record equal to [bno, len] in the btree
93+
* given by cur.
94+
*/
95+
int
96+
xfs_refcount_lookup_eq(
97+
struct xfs_btree_cur *cur,
98+
xfs_agblock_t bno,
99+
int *stat)
100+
{
101+
trace_xfs_refcount_lookup(cur->bc_mp, cur->bc_private.a.agno, bno,
102+
XFS_LOOKUP_LE);
103+
cur->bc_rec.rc.rc_startblock = bno;
104+
cur->bc_rec.rc.rc_blockcount = 0;
105+
return xfs_btree_lookup(cur, XFS_LOOKUP_EQ, stat);
106+
}
107+
91108
/* Convert on-disk record to in-core format. */
92109
void
93110
xfs_refcount_btrec_to_irec(

fs/xfs/libxfs/xfs_refcount.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ extern int xfs_refcount_lookup_le(struct xfs_btree_cur *cur,
2424
xfs_agblock_t bno, int *stat);
2525
extern int xfs_refcount_lookup_ge(struct xfs_btree_cur *cur,
2626
xfs_agblock_t bno, int *stat);
27+
extern int xfs_refcount_lookup_eq(struct xfs_btree_cur *cur,
28+
xfs_agblock_t bno, int *stat);
2729
extern int xfs_refcount_get_rec(struct xfs_btree_cur *cur,
2830
struct xfs_refcount_irec *irec, int *stat);
2931

0 commit comments

Comments
 (0)