Commit 14861c47 authored by Darrick J. Wong's avatar Darrick J. Wong

xfs: add helpers to calculate btree size

Add a bunch of helper functions that calculate the sizes of various
btrees.  These will be used to repair btrees and btree headers.
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
parent 9d9c9028
...@@ -547,3 +547,12 @@ xfs_allocbt_maxrecs( ...@@ -547,3 +547,12 @@ xfs_allocbt_maxrecs(
return blocklen / sizeof(xfs_alloc_rec_t); return blocklen / sizeof(xfs_alloc_rec_t);
return blocklen / (sizeof(xfs_alloc_key_t) + sizeof(xfs_alloc_ptr_t)); return blocklen / (sizeof(xfs_alloc_key_t) + sizeof(xfs_alloc_ptr_t));
} }
/* Calculate the freespace btree size for some records. */
xfs_extlen_t
xfs_allocbt_calc_size(
struct xfs_mount *mp,
unsigned long long len)
{
return xfs_btree_calc_size(mp->m_alloc_mnr, len);
}
...@@ -61,5 +61,7 @@ extern struct xfs_btree_cur *xfs_allocbt_init_cursor(struct xfs_mount *, ...@@ -61,5 +61,7 @@ extern struct xfs_btree_cur *xfs_allocbt_init_cursor(struct xfs_mount *,
struct xfs_trans *, struct xfs_buf *, struct xfs_trans *, struct xfs_buf *,
xfs_agnumber_t, xfs_btnum_t); xfs_agnumber_t, xfs_btnum_t);
extern int xfs_allocbt_maxrecs(struct xfs_mount *, int, int); extern int xfs_allocbt_maxrecs(struct xfs_mount *, int, int);
extern xfs_extlen_t xfs_allocbt_calc_size(struct xfs_mount *mp,
unsigned long long len);
#endif /* __XFS_ALLOC_BTREE_H__ */ #endif /* __XFS_ALLOC_BTREE_H__ */
...@@ -660,3 +660,12 @@ xfs_bmbt_change_owner( ...@@ -660,3 +660,12 @@ xfs_bmbt_change_owner(
xfs_btree_del_cursor(cur, error ? XFS_BTREE_ERROR : XFS_BTREE_NOERROR); xfs_btree_del_cursor(cur, error ? XFS_BTREE_ERROR : XFS_BTREE_NOERROR);
return error; return error;
} }
/* Calculate the bmap btree size for some records. */
unsigned long long
xfs_bmbt_calc_size(
struct xfs_mount *mp,
unsigned long long len)
{
return xfs_btree_calc_size(mp->m_bmap_dmnr, len);
}
...@@ -118,4 +118,7 @@ extern int xfs_bmbt_change_owner(struct xfs_trans *tp, struct xfs_inode *ip, ...@@ -118,4 +118,7 @@ extern int xfs_bmbt_change_owner(struct xfs_trans *tp, struct xfs_inode *ip,
extern struct xfs_btree_cur *xfs_bmbt_init_cursor(struct xfs_mount *, extern struct xfs_btree_cur *xfs_bmbt_init_cursor(struct xfs_mount *,
struct xfs_trans *, struct xfs_inode *, int); struct xfs_trans *, struct xfs_inode *, int);
extern unsigned long long xfs_bmbt_calc_size(struct xfs_mount *mp,
unsigned long long len);
#endif /* __XFS_BMAP_BTREE_H__ */ #endif /* __XFS_BMAP_BTREE_H__ */
...@@ -4836,14 +4836,14 @@ xfs_btree_query_all( ...@@ -4836,14 +4836,14 @@ xfs_btree_query_all(
* Calculate the number of blocks needed to store a given number of records * Calculate the number of blocks needed to store a given number of records
* in a short-format (per-AG metadata) btree. * in a short-format (per-AG metadata) btree.
*/ */
xfs_extlen_t unsigned long long
xfs_btree_calc_size( xfs_btree_calc_size(
uint *limits, uint *limits,
unsigned long long len) unsigned long long len)
{ {
int level; int level;
int maxrecs; int maxrecs;
xfs_extlen_t rval; unsigned long long rval;
maxrecs = limits[0]; maxrecs = limits[0];
for (level = 0, rval = 0; len > 1; level++) { for (level = 0, rval = 0; len > 1; level++) {
......
...@@ -482,7 +482,7 @@ xfs_failaddr_t xfs_btree_lblock_verify(struct xfs_buf *bp, ...@@ -482,7 +482,7 @@ xfs_failaddr_t xfs_btree_lblock_verify(struct xfs_buf *bp,
unsigned int max_recs); unsigned int max_recs);
uint xfs_btree_compute_maxlevels(uint *limits, unsigned long len); uint xfs_btree_compute_maxlevels(uint *limits, unsigned long len);
xfs_extlen_t xfs_btree_calc_size(uint *limits, unsigned long long len); unsigned long long xfs_btree_calc_size(uint *limits, unsigned long long len);
/* return codes */ /* return codes */
#define XFS_BTREE_QUERY_RANGE_CONTINUE 0 /* keep iterating */ #define XFS_BTREE_QUERY_RANGE_CONTINUE 0 /* keep iterating */
......
...@@ -608,3 +608,12 @@ xfs_finobt_calc_reserves( ...@@ -608,3 +608,12 @@ xfs_finobt_calc_reserves(
*used += tree_len; *used += tree_len;
return 0; return 0;
} }
/* Calculate the inobt btree size for some records. */
xfs_extlen_t
xfs_iallocbt_calc_size(
struct xfs_mount *mp,
unsigned long long len)
{
return xfs_btree_calc_size(mp->m_inobt_mnr, len);
}
...@@ -74,5 +74,7 @@ int xfs_inobt_rec_check_count(struct xfs_mount *, ...@@ -74,5 +74,7 @@ int xfs_inobt_rec_check_count(struct xfs_mount *,
int xfs_finobt_calc_reserves(struct xfs_mount *mp, xfs_agnumber_t agno, int xfs_finobt_calc_reserves(struct xfs_mount *mp, xfs_agnumber_t agno,
xfs_extlen_t *ask, xfs_extlen_t *used); xfs_extlen_t *ask, xfs_extlen_t *used);
extern xfs_extlen_t xfs_iallocbt_calc_size(struct xfs_mount *mp,
unsigned long long len);
#endif /* __XFS_IALLOC_BTREE_H__ */ #endif /* __XFS_IALLOC_BTREE_H__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment