diff options
author | Christoph Hellwig <hch@infradead.org> | 2008-10-30 01:56:22 -0400 |
---|---|---|
committer | Lachlan McIlroy <lachlan@sgi.com> | 2008-10-30 01:56:22 -0400 |
commit | 38bb74237d2d94c1aced2ec626d7d0f317e360da (patch) | |
tree | e37dfdad942de0e98c36c0fdf781cc29cd2daf0c /fs/xfs/xfs_btree.c | |
parent | fe033cc848489851f0c7de48f0b1bab5d744ad8a (diff) |
[XFS] implement generic xfs_btree_updkey
From: Dave Chinner <dgc@sgi.com>
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]
SGI-PV: 985583
SGI-Modid: xfs-linux-melb:xfs-kern:32193a
Signed-off-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Lachlan McIlroy <lachlan@sgi.com>
Signed-off-by: Bill O'Donnell <billodo@sgi.com>
Signed-off-by: David Chinner <david@fromorbit.com>
Diffstat (limited to 'fs/xfs/xfs_btree.c')
-rw-r--r-- | fs/xfs/xfs_btree.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/fs/xfs/xfs_btree.c b/fs/xfs/xfs_btree.c index 41912a01bec7..1459a2b9a729 100644 --- a/fs/xfs/xfs_btree.c +++ b/fs/xfs/xfs_btree.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include "xfs_attr_sf.h" | 34 | #include "xfs_attr_sf.h" |
35 | #include "xfs_dinode.h" | 35 | #include "xfs_dinode.h" |
36 | #include "xfs_inode.h" | 36 | #include "xfs_inode.h" |
37 | #include "xfs_inode_item.h" | ||
37 | #include "xfs_btree.h" | 38 | #include "xfs_btree.h" |
38 | #include "xfs_btree_trace.h" | 39 | #include "xfs_btree_trace.h" |
39 | #include "xfs_ialloc.h" | 40 | #include "xfs_ialloc.h" |
@@ -1065,6 +1066,45 @@ xfs_btree_read_buf_block( | |||
1065 | } | 1066 | } |
1066 | 1067 | ||
1067 | /* | 1068 | /* |
1069 | * Copy keys from one btree block to another. | ||
1070 | */ | ||
1071 | STATIC void | ||
1072 | xfs_btree_copy_keys( | ||
1073 | struct xfs_btree_cur *cur, | ||
1074 | union xfs_btree_key *dst_key, | ||
1075 | union xfs_btree_key *src_key, | ||
1076 | int numkeys) | ||
1077 | { | ||
1078 | ASSERT(numkeys >= 0); | ||
1079 | memcpy(dst_key, src_key, numkeys * cur->bc_ops->key_len); | ||
1080 | } | ||
1081 | |||
1082 | /* | ||
1083 | * Log key values from the btree block. | ||
1084 | */ | ||
1085 | STATIC void | ||
1086 | xfs_btree_log_keys( | ||
1087 | struct xfs_btree_cur *cur, | ||
1088 | struct xfs_buf *bp, | ||
1089 | int first, | ||
1090 | int last) | ||
1091 | { | ||
1092 | XFS_BTREE_TRACE_CURSOR(cur, XBT_ENTRY); | ||
1093 | XFS_BTREE_TRACE_ARGBII(cur, bp, first, last); | ||
1094 | |||
1095 | if (bp) { | ||
1096 | xfs_trans_log_buf(cur->bc_tp, bp, | ||
1097 | xfs_btree_key_offset(cur, first), | ||
1098 | xfs_btree_key_offset(cur, last + 1) - 1); | ||
1099 | } else { | ||
1100 | xfs_trans_log_inode(cur->bc_tp, cur->bc_private.b.ip, | ||
1101 | xfs_ilog_fbroot(cur->bc_private.b.whichfork)); | ||
1102 | } | ||
1103 | |||
1104 | XFS_BTREE_TRACE_CURSOR(cur, XBT_EXIT); | ||
1105 | } | ||
1106 | |||
1107 | /* | ||
1068 | * Increment cursor by one record at the level. | 1108 | * Increment cursor by one record at the level. |
1069 | * For nonzero levels the leaf-ward information is untouched. | 1109 | * For nonzero levels the leaf-ward information is untouched. |
1070 | */ | 1110 | */ |
@@ -1489,3 +1529,50 @@ error0: | |||
1489 | XFS_BTREE_TRACE_CURSOR(cur, XBT_ERROR); | 1529 | XFS_BTREE_TRACE_CURSOR(cur, XBT_ERROR); |
1490 | return error; | 1530 | return error; |
1491 | } | 1531 | } |
1532 | |||
1533 | /* | ||
1534 | * Update keys at all levels from here to the root along the cursor's path. | ||
1535 | */ | ||
1536 | int | ||
1537 | xfs_btree_updkey( | ||
1538 | struct xfs_btree_cur *cur, | ||
1539 | union xfs_btree_key *keyp, | ||
1540 | int level) | ||
1541 | { | ||
1542 | struct xfs_btree_block *block; | ||
1543 | struct xfs_buf *bp; | ||
1544 | union xfs_btree_key *kp; | ||
1545 | int ptr; | ||
1546 | |||
1547 | XFS_BTREE_TRACE_CURSOR(cur, XBT_ENTRY); | ||
1548 | XFS_BTREE_TRACE_ARGIK(cur, level, keyp); | ||
1549 | |||
1550 | ASSERT(!(cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) || level >= 1); | ||
1551 | |||
1552 | /* | ||
1553 | * Go up the tree from this level toward the root. | ||
1554 | * At each level, update the key value to the value input. | ||
1555 | * Stop when we reach a level where the cursor isn't pointing | ||
1556 | * at the first entry in the block. | ||
1557 | */ | ||
1558 | for (ptr = 1; ptr == 1 && level < cur->bc_nlevels; level++) { | ||
1559 | #ifdef DEBUG | ||
1560 | int error; | ||
1561 | #endif | ||
1562 | block = xfs_btree_get_block(cur, level, &bp); | ||
1563 | #ifdef DEBUG | ||
1564 | error = xfs_btree_check_block(cur, block, level, bp); | ||
1565 | if (error) { | ||
1566 | XFS_BTREE_TRACE_CURSOR(cur, XBT_ERROR); | ||
1567 | return error; | ||
1568 | } | ||
1569 | #endif | ||
1570 | ptr = cur->bc_ptrs[level]; | ||
1571 | kp = xfs_btree_key_addr(cur, ptr, block); | ||
1572 | xfs_btree_copy_keys(cur, kp, keyp, 1); | ||
1573 | xfs_btree_log_keys(cur, bp, ptr, ptr); | ||
1574 | } | ||
1575 | |||
1576 | XFS_BTREE_TRACE_CURSOR(cur, XBT_EXIT); | ||
1577 | return 0; | ||
1578 | } | ||