implement generic xfs_btree_updkey
PATCH 12/21 implement generic xfs_btree_updkey
From: Dave Chinner <[email protected]>
Note that there are many > 80 char lines introduced due to the xfs_btree_key casts. But the places where this happens is throw-away code once the whole btree code gets merged into a common implementation.
The same is true for the temporary xfs_alloc_log_keys define to the new name. All old users will be gone after a few patches.
[hch: split out from bigger patch and minor adaptions]
fs/xfs/xfs_btree.c +47 -0
@@ -1370,3 +1370,50 @@ error0:XFS_BTREE_TRACE_CURSOR (cur,XBT_ERROR );return error; } + +/* +* Update keys at all levels from here to the root along the cursor's path. +*/ +int +xfs_btree_updkey ( +struct xfs_btree_cur *cur, +union xfs_btree_key *keyp, +int level) +{ +struct xfs_btree_block *block; +struct xfs_buf *bp; +union xfs_btree_key *kp; +int ptr; +#ifdef DEBUG +int error; +#endif + +XFS_BTREE_TRACE_CURSOR (cur,XBT_ENTRY ); +XFS_BTREE_TRACE_ARGIK (cur, level, keyp); + +ASSERT (!(cur->bc_flags &XFS_BTREE_ROOT_IN_INODE ) || level >=1 ); + +/* +* Go up the tree from this level toward the root. +* At each level, update the key value to the value input. +* Stop when we reach a level where the cursor isn't pointing +* at the first entry in the block. +*/ +for (ptr =1 ; ptr ==1 && level < cur->bc_nlevels; level++) { + block =xfs_btree_get_block (cur, level, &bp); +#ifdef DEBUG + error =xfs_btree_check_block (cur, block, level, bp); +if (error) { +XFS_BTREE_TRACE_CURSOR (cur,XBT_ERROR ); +return error; + } +#endif + ptr = cur->bc_ptrs[level]; + kp = cur->bc_ops->key_addr (cur, ptr, block); + cur->bc_ops->copy_keys (cur, keyp, kp,1 ); + cur->bc_ops->log_keys (cur, bp, ptr, ptr); + } + +XFS_BTREE_TRACE_CURSOR (cur,XBT_EXIT ); +return 0 ; +}
fs/xfs/xfs_btree.h +11 -0
@@ -210,6 +210,16 @@ struct xfs_btree_ops {__int64_t (*key_diff)(struct xfs_btree_cur *cur,union xfs_btree_key *key); +/* copy bits of btree blocks between blocks */ +void (*copy_keys)(struct xfs_btree_cur *cur, +union xfs_btree_key *src_key, +union xfs_btree_key *dst_key,int numkeys); + +/* log changes to btree structures */ +void (*log_keys)(struct xfs_btree_cur *cur,struct xfs_buf *bp, +int first,int last); + +/* btree tracing */ #ifdef XFS_BTREE_TRACE void (*trace_enter)(struct xfs_btree_cur *, const char *,
@@ -528,6 +538,7 @@ xfs_btree_setbuf(int xfs_btree_increment (struct xfs_btree_cur *,int ,int *);int xfs_btree_decrement (struct xfs_btree_cur *,int ,int *);int xfs_btree_lookup (struct xfs_btree_cur *,xfs_lookup_t ,int *); +int xfs_btree_updkey (struct xfs_btree_cur *,union xfs_btree_key *,int );/*
fs/xfs/xfs_alloc_btree.c +50 -68
190 lines not on this page · raw message
fs/xfs/xfs_ialloc_btree.c +46 -67
179 lines not on this page · raw message
fs/xfs/xfs_bmap_btree.c +50 -80
190 lines not on this page · raw message
Quoted 12 lines · Christoph Hellwig
From: Dave Chinner <[email protected]>
Note that there are many > 80 char lines introduced due to the
xfs_btree_keycasts. But the places where this happens is throw-away code once the whole btree code gets merged into a common implementation.The same is true for the temporary
xfs_alloc_log_keysdefine to the new name. All old users will be gone after a few patches.[hch: split out from bigger patch and minor adaptions]
Signed-off-by Christoph Hellwig <[email protected]>
.....
Quoted 6 lines
fs/xfs/xfs_btree.c +6
-0+/* +* Update keys at all levels from here to the root along the cursor's path. +*/ +int +xfs_btree_updkey( + struct xfs_btree_cur *cur,
fs/xfs/xfs_btree.c error0: · line 1389
Quoted 10 lines
fs/xfs/xfs_btree.c +10
-0+ union xfs_btree_key *keyp, + int level) +{ +struct xfs_btree_block *block; +struct xfs_buf *bp; +union xfs_btree_key *kp; +int ptr; +#ifdef DEBUG +int error; +#endif
This can be scoped inside the for loop.
Quoted 11 lines
fs/xfs/xfs_btree.c +11
-0+ +XFS_BTREE_TRACE_CURSOR (cur,XBT_ENTRY ); +XFS_BTREE_TRACE_ARGIK (cur, level, keyp); + +ASSERT (!(cur->bc_flags &XFS_BTREE_ROOT_IN_INODE ) || level >=1 ); + +/* +* Go up the tree from this level toward the root. +* At each level, update the key value to the value input. +* Stop when we reach a level where the cursor isn't pointing +* at the first entry in the block.
fs/xfs/xfs_btree.c error0: · line 1410
Quoted 10 lines
fs/xfs/xfs_btree.c +10
-0+*/ +for (ptr =1 ; ptr ==1 && level < cur->bc_nlevels; level++) { + block =xfs_btree_get_block (cur, level, &bp); +#ifdef DEBUG + error =xfs_btree_check_block (cur, block, level, bp); +if (error) { +XFS_BTREE_TRACE_CURSOR (cur,XBT_ERROR ); +return error; + } +#endif
And even then I think we might not need an error variable - it can only return EFSCORRUPTED, so:
#ifdef DEBUG
if (xfs_btree_check_block(cur, block, level, bp)) {
XFS_BTREE_TRACE_CURSOR(cur, XBT_ERROR);
return EFSCORRUPTED;
}#endif
Would remove the need for the error variable.
Otherwise looks ok.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 6 lines · Dave Chinner
fs/xfs/xfs_btree.c error0: · line 1389
Quoted 4 lines
fs/xfs/xfs_btree.c +4
-0+int ptr; +#ifdef DEBUG +int error; +#endif This can be scoped inside the for loop.
Done.
Quoted 11 lines
And even then I think we might not need an error variable - it can only return EFSCORRUPTED, so:
#ifdef DEBUG if (xfs_btree_check_block(cur, block, level, bp)) { XFS_BTREE_TRACE_CURSOR(cur, XBT_ERROR); return EFSCORRUPTED; }#endif
Would remove the need for the error variable.
I'm not a big fan of losing detailed error information. Depending on how the bigger btree blocks work out we might return other errors here in the near future.
Quoted 11 lines · Christoph Hellwig
Quoted 10 lines · Dave Chinner
And even then I think we might not need an error variable - it can only return EFSCORRUPTED, so:
#ifdef DEBUG if (xfs_btree_check_block(cur, block, level, bp)) { XFS_BTREE_TRACE_CURSOR(cur, XBT_ERROR); return EFSCORRUPTED; }#endif
Quoted 5 lines
Quoted 1 line
Would remove the need for the error variable.
I'm not a big fan of losing detailed error information. Depending on how the bigger btree blocks work out we might return other errors here in the near future.
Fair enough.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]