cleanup btree record / key / ptr addressing macros
PATCH 4/6 cleanup btree record / key / ptr addressing macros
Replace the generic record / key / ptr addressing macros that use cpp token pasting with simpler macros that do the job for just one given btree type. The new macros lose the cur argument and thus can be used outside the core btree code, but also gain an xfs_mount * argument to allow for checking the CRC flag in the near future. Note that many of these macros aren't actually used in the kernel code, but only in userspace (mostly in xfs_repair).
Signed-off-by Christoph Hellwig <[email protected]>
fs/xfs/xfs_alloc_btree.c +1 -1
@@ -179,7 +179,7 @@ xfs_allocbt_update_lastrec(if (numrecs) {xfs_alloc_rec_t *rrp; - rrp =XFS_ALLOC_REC_ADDR (block, numrecs, cur); + rrp =XFS_ALLOC_REC_ADDR (cur->bc_mp, block, numrecs); len = rrp->ar_blockcount; }else { len =0 ;
fs/xfs/xfs_bmap_btree.c +6 -7
@@ -44,7 +44,6 @@#include "xfs_error.h" #include "xfs_quota.h" -/* * Determine the extent state. */
@@ -85,9 +84,9 @@ xfs_bmdr_to_bmbt( rblock->bb_leftsib =cpu_to_be64 (NULLDFSBNO ); rblock->bb_rightsib =cpu_to_be64 (NULLDFSBNO ); dmxr =xfs_bmdr_maxrecs (mp, dblocklen,0 ); - fkp =XFS_BTREE_KEY_ADDR (xfs_bmdr, dblock,1 ); - tkp =XFS_BMAP_BROOT_KEY_ADDR (rblock,1 , rblocklen); - fpp =XFS_BTREE_PTR_ADDR (xfs_bmdr, dblock,1 , dmxr); + fkp =XFS_BMDR_KEY_ADDR (dblock,1 ); + tkp =XFS_BMBT_KEY_ADDR (mp, rblock,1 ); + fpp =XFS_BMDR_PTR_ADDR (dblock,1 , dmxr); tpp =XFS_BMAP_BROOT_PTR_ADDR (mp, rblock,1 , rblocklen); dmxr =be16_to_cpu (dblock->bb_numrecs);memcpy (tkp, fkp,sizeof (*fkp) * dmxr);
@@ -448,10 +447,10 @@ xfs_bmbt_to_bmdr( dblock->bb_level = rblock->bb_level; dblock->bb_numrecs = rblock->bb_numrecs; dmxr =xfs_bmdr_maxrecs (mp, dblocklen,0 ); - fkp =XFS_BMAP_BROOT_KEY_ADDR (rblock,1 , rblocklen); - tkp =XFS_BTREE_KEY_ADDR (xfs_bmdr, dblock,1 ); + fkp =XFS_BMBT_KEY_ADDR (mp, rblock,1 ); + tkp =XFS_BMDR_KEY_ADDR (dblock,1 ); fpp =XFS_BMAP_BROOT_PTR_ADDR (mp, rblock,1 , rblocklen); - tpp =XFS_BTREE_PTR_ADDR (xfs_bmdr, dblock,1 , dmxr); + tpp =XFS_BMDR_PTR_ADDR (dblock,1 , dmxr); dmxr =be16_to_cpu (dblock->bb_numrecs);memcpy (tkp, fkp,sizeof (*fkp) * dmxr);memcpy (tpp, fpp,sizeof (*fpp) * dmxr);
fs/xfs/xfs_alloc_btree.h +20 -9
@@ -78,16 +78,27 @@ typedef struct xfs_btree_sblock xfs_allo/* * Record, key, and pointer address macros for btree blocks. +* +* (note that some of these may appear unused, but they are used in userspace) */ -#define XFS_ALLOC_REC_ADDR (bb,i,cur) \ - XFS_BTREE_REC_ADDR(xfs_alloc, bb, i) - -#define XFS_ALLOC_KEY_ADDR (bb,i,cur) \ - XFS_BTREE_KEY_ADDR(xfs_alloc, bb, i) - -#define XFS_ALLOC_PTR_ADDR (bb,i,cur) \ - XFS_BTREE_PTR_ADDR(xfs_alloc, bb, i, XFS_ALLOC_BLOCK_MAXRECS(1, cur)) - +#define XFS_ALLOC_REC_ADDR (mp, block, index) \ + ((xfs_alloc_rec_t *) \ + ((char *)(block) + \ + sizeof(struct xfs_btree_sblock) + \ + (((index) - 1) * sizeof(xfs_alloc_rec_t)))) + +#define XFS_ALLOC_KEY_ADDR (mp, block, index) \ + ((xfs_alloc_key_t *) \ + ((char *)(block) + \ + sizeof(struct xfs_btree_sblock) + \ + ((index) - 1) * sizeof(xfs_alloc_key_t))) + +#define XFS_ALLOC_PTR_ADDR (mp, block, index, maxrecs) \ + ((xfs_alloc_ptr_t *) \ + ((char *)(block) + \ + sizeof(struct xfs_btree_sblock) + \ + (maxrecs) * sizeof(xfs_alloc_key_t) + \ + ((index) - 1) * sizeof(xfs_alloc_ptr_t))) extern struct xfs_btree_cur *xfs_allocbt_init_cursor(struct xfs_mount *, struct xfs_trans *, struct xfs_buf *,
fs/xfs/xfs_ialloc_btree.h +18 -7
@@ -97,16 +97,27 @@ typedef struct xfs_btree_sblock xfs_inob/* * Record, key, and pointer address macros for btree blocks. +* +* (note that some of these may appear unused, but they are used in userspace) */ -#define XFS_INOBT_REC_ADDR (bb,i,cur) \ - (XFS_BTREE_REC_ADDR(xfs_inobt, bb, i)) +#define XFS_INOBT_REC_ADDR (mp, block, index) \ + ((xfs_inobt_rec_t *) \ + ((char *)(block) + \ + sizeof(struct xfs_btree_sblock) + \ + (((index) - 1) * sizeof(xfs_inobt_rec_t)))) -#define XFS_INOBT_KEY_ADDR (bb,i,cur) \ - (XFS_BTREE_KEY_ADDR(xfs_inobt, bb, i)) +#define XFS_INOBT_KEY_ADDR (mp, block, index) \ + ((xfs_inobt_key_t *) \ + ((char *)(block) + \ + sizeof(struct xfs_btree_sblock) + \ + ((index) - 1) * sizeof(xfs_inobt_key_t))) -#define XFS_INOBT_PTR_ADDR (bb,i,cur) \ - (XFS_BTREE_PTR_ADDR(xfs_inobt, bb, \ - i, XFS_INOBT_BLOCK_MAXRECS(1, cur))) +#define XFS_INOBT_PTR_ADDR (mp, block, index, maxrecs) \ + ((xfs_inobt_ptr_t *) \ + ((char *)(block) + \ + sizeof(struct xfs_btree_sblock) + \ + (maxrecs) * sizeof(xfs_inobt_key_t) + \ + ((index) - 1) * sizeof(xfs_inobt_ptr_t)))extern struct xfs_btree_cur *xfs_inobt_init_cursor (struct xfs_mount *,struct xfs_trans *,struct xfs_buf *,xfs_agnumber_t );
fs/xfs/xfs_bmap.c +24 -30
143 lines not on this page · raw message
fs/xfs/xfs_bmap_btree.h +40 -22
79 lines not on this page · raw message
fs/xfs/xfs_fsops.c +2 -2
@@ -258,7 +258,7 @@ xfs_growfs_data_private( block->bb_numrecs =cpu_to_be16 (1 ); block->bb_leftsib =cpu_to_be32 (NULLAGBLOCK ); block->bb_rightsib =cpu_to_be32 (NULLAGBLOCK ); - arec =XFS_BTREE_REC_ADDR (xfs_alloc, block,1 ); + arec =XFS_ALLOC_REC_ADDR (mp, block,1 ); arec->ar_startblock =cpu_to_be32 (XFS_PREALLOC_BLOCKS (mp)); arec->ar_blockcount =cpu_to_be32 ( agsize -be32_to_cpu (arec->ar_startblock));
@@ -279,7 +279,7 @@ xfs_growfs_data_private( block->bb_numrecs =cpu_to_be16 (1 ); block->bb_leftsib =cpu_to_be32 (NULLAGBLOCK ); block->bb_rightsib =cpu_to_be32 (NULLAGBLOCK ); - arec =XFS_BTREE_REC_ADDR (xfs_alloc, block,1 ); + arec =XFS_ALLOC_REC_ADDR (mp, block,1 ); arec->ar_startblock =cpu_to_be32 (XFS_PREALLOC_BLOCKS (mp)); arec->ar_blockcount =cpu_to_be32 ( agsize -be32_to_cpu (arec->ar_startblock));
fs/xfs/xfs_inode.c +2 -4
@@ -2435,10 +2435,8 @@ xfs_iroot_realloc(/* * First copy the records. */ - op = (char *)XFS_BMAP_BROOT_REC_ADDR (ifp->if_broot,1 , - ifp->if_broot_bytes); - np = (char *)XFS_BMAP_BROOT_REC_ADDR (new_broot,1 , - (int )new_size); + op = (char *)XFS_BMBT_REC_ADDR (mp, ifp->if_broot,1 ); + np = (char *)XFS_BMBT_REC_ADDR (mp, new_broot,1 );memcpy (np, op, new_max * (uint )sizeof (xfs_bmbt_rec_t));/*
fs/xfs/xfs_btree.h +0 -15
@@ -149,21 +149,6 @@ do { \ } \ } while (0) -/* -* Record, key, and pointer address calculation macros. -* Given block size, type prefix, block pointer, and index of requested entry -* (first entry numbered 1). - */ -#define XFS_BTREE_REC_ADDR (t,bb,i) \ - ((t ## _rec_t *)((char *)(bb) + sizeof(t ## _block_t) + \ - ((i) - 1) * sizeof(t ## _rec_t))) -#define XFS_BTREE_KEY_ADDR (t,bb,i) \ - ((t ## _key_t *)((char *)(bb) + sizeof(t ## _block_t) + \ - ((i) - 1) * sizeof(t ## _key_t))) -#define XFS_BTREE_PTR_ADDR (t,bb,i,mxr) \ - ((t ## _ptr_t *)((char *)(bb) + sizeof(t ## _block_t) + \ - (mxr) * sizeof(t ## _key_t) + ((i) - 1) * sizeof(t ## _ptr_t))) -#define XFS_BTREE_MAXLEVELS 8/* max of all btrees */ struct xfs_btree_ops {