add rec_len and key_len fields to struct xfs_btree_ops
PATCH 26/26 add rec_len and key_len fields to struct xfs_btree_ops
XXX: add detailed patch explanation here
fs/xfs/xfs_alloc_btree.c +3 -193
@@ -261,33 +261,6 @@ xfs_allocbt_init_rec_from_cur( rec->alloc.ar_blockcount =cpu_to_be32 (cur->bc_rec.a.ar_blockcount); } -STATIC union xfs_btree_ptr * -xfs_allocbt_ptr_addr ( -struct xfs_btree_cur *cur, -int index, -struct xfs_btree_block *block) -{ -return (union xfs_btree_ptr *)XFS_ALLOC_PTR_ADDR (block, index, cur); -} - -STATIC union xfs_btree_key * -xfs_allocbt_key_addr ( -struct xfs_btree_cur *cur, -int index, -struct xfs_btree_block *block) -{ -return (union xfs_btree_key *)XFS_ALLOC_KEY_ADDR (block, index, cur); -} - -STATIC union xfs_btree_rec * -xfs_allocbt_rec_addr ( -struct xfs_btree_cur *cur, -int index, -struct xfs_btree_block *block) -{ -return (union xfs_btree_rec *)XFS_ALLOC_REC_ADDR (block, index, cur); -} - STATIC __int64_t xfs_allocbt_key_diff( struct xfs_btree_cur *cur,
@@ -309,161 +282,6 @@ xfs_allocbt_key_diff(return (__int64_t )be32_to_cpu (kp->ar_startblock) - rec->ar_startblock; } -STATIC void -xfs_allocbt_set_key ( -struct xfs_btree_cur *cur, -union xfs_btree_key *key_addr, -int index, -union xfs_btree_key *newkey) -{ -xfs_alloc_key_t *kp = &key_addr->alloc; - - kp[index] = newkey->alloc; -} - -STATIC void -xfs_allocbt_set_rec ( -struct xfs_btree_cur *cur, -union xfs_btree_rec *rec_addr, -int index, -union xfs_btree_rec *newrec) -{ -xfs_alloc_rec_t *rp = &rec_addr->alloc; - - rp[index] = newrec->alloc; -} - -STATIC void -xfs_allocbt_move_keys ( -struct xfs_btree_cur *cur, -union xfs_btree_key *base, -int from, -int to, -int numkeys) -{ -xfs_alloc_key_t *kp = &base->alloc; - -ASSERT (from >=0 ); -ASSERT (to >=0 ); -ASSERT (numkeys >=0 ); - -memmove (&kp[to], &kp[from], numkeys *sizeof (*kp)); -} - -STATIC void -xfs_allocbt_move_recs ( -struct xfs_btree_cur *cur, -union xfs_btree_rec *base, -int from, -int to, -int numrecs) -{ -xfs_alloc_rec_t *rp = &base->alloc; - -ASSERT (from >=0 ); -ASSERT (to >=0 ); -ASSERT (numrecs >=0 ); - -memmove (&rp[to], &rp[from], numrecs *sizeof (*rp)); -} - -STATIC void -xfs_allocbt_copy_keys ( -struct xfs_btree_cur *cur, -union xfs_btree_key *src_key, -union xfs_btree_key *dst_key, -int numkeys) -{ -ASSERT (numkeys >=0 ); -memcpy (dst_key, src_key, numkeys *sizeof (xfs_alloc_key_t)); -} - -STATIC void -xfs_allocbt_copy_recs ( -struct xfs_btree_cur *cur, -union xfs_btree_rec *src_rec, -union xfs_btree_rec *dst_rec, -int numrecs) -{ -ASSERT (numrecs >=0 ); -memcpy (dst_rec, src_rec, numrecs *sizeof (xfs_alloc_rec_t)); -} - -/* -* Log keys from a btree block (nonleaf). -*/ -STATIC void -xfs_allocbt_log_keys ( -struct xfs_btree_cur *cur,/* btree cursor */ -struct xfs_buf *bp,/* buffer containing btree block */ -int first,/* index of first key to log */ -int last)/* index of last key to log */ -{ -struct xfs_btree_block *block =XFS_BUF_TO_BLOCK (bp); -xfs_alloc_key_t *kp =XFS_ALLOC_KEY_ADDR (block,1 , cur); -char *baddr = (char *)block; -int start;/* first byte offset logged */ -int end;/* last byte offset logged */ - -XFS_BTREE_TRACE_CURSOR (cur,XBT_ENTRY ); -XFS_BTREE_TRACE_ARGBII (cur, bp, first, last); - - start = (char *)&kp[first -1 ] - baddr; - end = (char *)&kp[last] -1 - baddr; -xfs_trans_log_buf (cur->bc_tp, bp, start, end); - -XFS_BTREE_TRACE_CURSOR (cur,XBT_EXIT ); -} - -#ifdef DEBUG -STATIC void -xfs_alloc_log_recs_check ( -struct xfs_btree_cur *cur, -xfs_alloc_rec_t *rp, -int first, -int last) -{ -struct xfs_agf *agf =XFS_BUF_TO_AGF (cur->bc_private.a.agbp); -xfs_alloc_rec_t *p; - -for (p = &rp[first -1 ]; p <= &rp[last -1 ]; p++) { -ASSERT (be32_to_cpu (p->ar_startblock) + -be32_to_cpu (p->ar_blockcount) <= -be32_to_cpu (agf->agf_length)); - } -} -#else -#define xfs_alloc_log_recs_check (cur, bp, first, last) -#endif - -/* -* Log records from a btree block (leaf). -*/ -STATIC void -xfs_allocbt_log_recs ( -struct xfs_btree_cur *cur,/* btree cursor */ -struct xfs_buf *bp,/* buffer containing btree block */ -int first,/* index of first record to log */ -int last)/* index of last record to log */ -{ -struct xfs_btree_block *block =XFS_BUF_TO_BLOCK (bp); -xfs_alloc_rec_t *rp =XFS_ALLOC_REC_ADDR (block,1 , cur); -char *baddr = (char *)block; -int start;/* first byte offset logged */ -int end;/* last byte offset logged */ - -XFS_BTREE_TRACE_CURSOR (cur,XBT_ENTRY ); -XFS_BTREE_TRACE_ARGBII (cur, bp, first, last); - -xfs_alloc_log_recs_check (cur, rp, first, last); - - start = (char *)&rp[first -1 ] - baddr; - end = (char *)&rp[last] -1 - baddr; -xfs_trans_log_buf (cur->bc_tp, bp, start, end); - -XFS_BTREE_TRACE_CURSOR (cur,XBT_EXIT ); -} -#ifdef XFS_BTREE_TRACE ktrace_t *xfs_allocbt_trace_buf;
@@ -532,6 +350,9 @@ xfs_allocbt_trace_record(#endif /* XFS_BTREE_TRACE */ static const struct xfs_btree_ops xfs_allocbt_ops = { + .key_len =sizeof (xfs_alloc_key_t), + .rec_len =sizeof (xfs_alloc_rec_t), + .dup_cursor = xfs_allocbt_dup_cursor, .set_root = xfs_allocbt_set_root, .alloc_block = xfs_allocbt_alloc_block,
@@ -543,18 +364,7 @@ static const struct xfs_btree_ops xfs_al .init_ptr_from_cur = xfs_allocbt_init_ptr_from_cur, .init_rec_from_key = xfs_allocbt_init_rec_from_key, .init_rec_from_cur = xfs_allocbt_init_rec_from_cur, - .ptr_addr = xfs_allocbt_ptr_addr, - .key_addr = xfs_allocbt_key_addr, - .rec_addr = xfs_allocbt_rec_addr, .key_diff = xfs_allocbt_key_diff, - .set_key = xfs_allocbt_set_key, - .set_rec = xfs_allocbt_set_rec, - .move_keys = xfs_allocbt_move_keys, - .move_recs = xfs_allocbt_move_recs, - .copy_keys = xfs_allocbt_copy_keys, - .copy_recs = xfs_allocbt_copy_recs, - .log_keys = xfs_allocbt_log_keys, - .log_recs = xfs_allocbt_log_recs, #ifdef XFS_BTREE_TRACE .trace_enter = xfs_allocbt_trace_enter,
fs/xfs/xfs_bmap_btree.c +3 -174
202 lines not on this page · raw message
fs/xfs/xfs_btree.c +320 -129
770 lines not on this page · raw message
fs/xfs/xfs_btree.h +5 -38
67 lines not on this page · raw message
fs/xfs/xfs_ialloc_btree.c +3 -171
199 lines not on this page · raw message
fs/xfs/xfs_bmap.c +1 -1
@@ -3564,7 +3564,7 @@ xfs_bmap_extents_to_btree(* the root is at the right level. */ xfs_btree_log_block (cur, abp,XFS_BB_ALL_BITS ); -xfs_bmbt_log_recs (cur, abp,1 ,be16_to_cpu (ablock->bb_numrecs)); +xfs_btree_log_recs (cur, abp,1 ,be16_to_cpu (ablock->bb_numrecs));ASSERT (*curp ==NULL ); *curp = cur; *logflagsp =XFS_ILOG_CORE |XFS_ILOG_FBROOT (whichfork);
Quoted 1 line · Christoph Hellwig
XXX: add detailed patch explanation here
heh ;)
.....
Quoted 5 lines
Index:
linux-2.6-xfs/fs/xfs/xfs_btree.c
===================================================================
fs/xfs/xfs_btree.c xfs_btree_read_buf_block( · line 1045
Quoted 9 lines
fs/xfs/xfs_btree.c +6
-0@@ -1037,6 +1037,82 @@ xfs_btree_read_buf_block(return error; } +static inline size_t xfs_btree_block_len (struct xfs_btree_cur *cur) +{ +return (cur->bc_flags &XFS_BTREE_LONG_PTRS ) ? +sizeof (struct xfs_btree_lblock ) : +sizeof (struct xfs_btree_sblock ); +}
That's really the block header length, not the block length. Can you change the name to reflect that?
Quoted 7 lines
fs/xfs/xfs_btree.c +7
-0+ +static inline size_t xfs_btree_ptr_len (struct xfs_btree_cur *cur) +{ +return (cur->bc_flags &XFS_BTREE_LONG_PTRS ) ? +sizeof (__be64) :sizeof (__be32); +} +
fs/xfs/xfs_btree.c xfs_btree_read_buf_block( · line 1062
Quoted 10 lines
fs/xfs/xfs_btree.c +10
-0+static size_t +xfs_btree_ptr_offset ( +struct xfs_btree_cur *cur, +int index, +int level) +{ +return xfs_btree_block_len (cur) + + cur->bc_ops->get_maxrecs (cur, level) * cur->bc_ops->key_len + + (index -1 ) *xfs_btree_ptr_len (cur); +}
I'd suggest a comment here just reminding the reader about the key/ptr block structure. i.e. key space is at the start of the block, ptr space is after the key space.
Also a comment here reminding that btree indexes are 1-numbered, not 0-numbered and hence the need for 'index - 1' in the offset calculations.
fs/xfs/xfs_btree.c xfs_btree_set_ptr( · line 1146
Quoted 13 lines
fs/xfs/xfs_btree.c +12
-0STATIC void +xfs_btree_set_key ( +struct xfs_btree_cur *cur, +union xfs_btree_key *key_addr, +int index, +union xfs_btree_key *newkey) +{ +char *kp; + + kp = (char *)key_addr + (index * cur->bc_ops->key_len); + +memcpy (kp, newkey, cur->bc_ops->key_len); +}
And then for these set functions, the index has already been converted from 1-numbered to 0-numbered by the caller, hence the direct use of 'index' without correction.
Quoted 11 lines
fs/xfs/xfs_btree.c +7
-0@@ -1079,6 +1183,44 @@ xfs_btree_move_ptrs( } STATIC void +xfs_btree_move_keys ( +struct xfs_btree_cur *cur, +union xfs_btree_key *key, +int from, +int to, +int numkeys) +{
fs/xfs/xfs_btree.c xfs_btree_move_ptrs( · line 1202
Quoted 10 lines
fs/xfs/xfs_btree.c +10
-0+char *base = (char *)key; + +ASSERT (from >=0 ); +ASSERT (to >=0 ); +ASSERT (numkeys >=0 ); + +memmove (base + (to * cur->bc_ops->key_len), + base + (from * cur->bc_ops->key_len), + numkeys * cur->bc_ops->key_len); +}
Comment about from and to being logical offsets from the base, not byte counts.
Hmmm - seeing how frequently the functions like xfs_btree_key_addr() are called, should we prevent them from being inlined automatically by the compiler (i.e. make them STATIC or explictly noinline)?
Otherwise seems sane to me.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]