Commit f9c18129 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Darrick J. Wong

xfs: add a xfs_btree_init_ptr_from_cur

Inode-rooted btrees don't need to initialize the root pointer in the
->init_ptr_from_cur method as the root is found by the
xfs_btree_get_iroot method later.  Make ->init_ptr_from_cur option
for inode rooted btrees by providing a helper that does the right
thing for the given btree type and also documents the semantics.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
parent 72c2070f
...@@ -369,14 +369,6 @@ xfs_bmbt_init_rec_from_cur( ...@@ -369,14 +369,6 @@ xfs_bmbt_init_rec_from_cur(
xfs_bmbt_disk_set_all(&rec->bmbt, &cur->bc_rec.b); xfs_bmbt_disk_set_all(&rec->bmbt, &cur->bc_rec.b);
} }
STATIC void
xfs_bmbt_init_ptr_from_cur(
struct xfs_btree_cur *cur,
union xfs_btree_ptr *ptr)
{
ptr->l = 0;
}
STATIC int64_t STATIC int64_t
xfs_bmbt_key_diff( xfs_bmbt_key_diff(
struct xfs_btree_cur *cur, struct xfs_btree_cur *cur,
...@@ -544,7 +536,6 @@ const struct xfs_btree_ops xfs_bmbt_ops = { ...@@ -544,7 +536,6 @@ const struct xfs_btree_ops xfs_bmbt_ops = {
.init_key_from_rec = xfs_bmbt_init_key_from_rec, .init_key_from_rec = xfs_bmbt_init_key_from_rec,
.init_high_key_from_rec = xfs_bmbt_init_high_key_from_rec, .init_high_key_from_rec = xfs_bmbt_init_high_key_from_rec,
.init_rec_from_cur = xfs_bmbt_init_rec_from_cur, .init_rec_from_cur = xfs_bmbt_init_rec_from_cur,
.init_ptr_from_cur = xfs_bmbt_init_ptr_from_cur,
.key_diff = xfs_bmbt_key_diff, .key_diff = xfs_bmbt_key_diff,
.diff_two_keys = xfs_bmbt_diff_two_keys, .diff_two_keys = xfs_bmbt_diff_two_keys,
.buf_ops = &xfs_bmbt_buf_ops, .buf_ops = &xfs_bmbt_buf_ops,
......
...@@ -1881,6 +1881,25 @@ xfs_lookup_get_search_key( ...@@ -1881,6 +1881,25 @@ xfs_lookup_get_search_key(
return xfs_btree_key_addr(cur, keyno, block); return xfs_btree_key_addr(cur, keyno, block);
} }
/*
* Initialize a pointer to the root block.
*/
void
xfs_btree_init_ptr_from_cur(
struct xfs_btree_cur *cur,
union xfs_btree_ptr *ptr)
{
if (cur->bc_ops->type == XFS_BTREE_TYPE_INODE) {
/*
* Inode-rooted btrees call xfs_btree_get_iroot to find the root
* in xfs_btree_lookup_get_block and don't need a pointer here.
*/
ptr->l = 0;
} else {
cur->bc_ops->init_ptr_from_cur(cur, ptr);
}
}
/* /*
* Lookup the record. The cursor is made to point to it, based on dir. * Lookup the record. The cursor is made to point to it, based on dir.
* stat is set to 0 if can't find any such record, 1 for success. * stat is set to 0 if can't find any such record, 1 for success.
...@@ -1911,7 +1930,7 @@ xfs_btree_lookup( ...@@ -1911,7 +1930,7 @@ xfs_btree_lookup(
keyno = 0; keyno = 0;
/* initialise start pointer from cursor */ /* initialise start pointer from cursor */
cur->bc_ops->init_ptr_from_cur(cur, &ptr); xfs_btree_init_ptr_from_cur(cur, &ptr);
pp = &ptr; pp = &ptr;
/* /*
...@@ -3121,7 +3140,7 @@ xfs_btree_new_root( ...@@ -3121,7 +3140,7 @@ xfs_btree_new_root(
XFS_BTREE_STATS_INC(cur, newroot); XFS_BTREE_STATS_INC(cur, newroot);
/* initialise our start point from the cursor */ /* initialise our start point from the cursor */
cur->bc_ops->init_ptr_from_cur(cur, &rptr); xfs_btree_init_ptr_from_cur(cur, &rptr);
/* Allocate the new block. If we can't do it, we're toast. Give up. */ /* Allocate the new block. If we can't do it, we're toast. Give up. */
error = xfs_btree_alloc_block(cur, &rptr, &lptr, stat); error = xfs_btree_alloc_block(cur, &rptr, &lptr, stat);
...@@ -4430,7 +4449,7 @@ xfs_btree_visit_blocks( ...@@ -4430,7 +4449,7 @@ xfs_btree_visit_blocks(
struct xfs_btree_block *block = NULL; struct xfs_btree_block *block = NULL;
int error = 0; int error = 0;
cur->bc_ops->init_ptr_from_cur(cur, &lptr); xfs_btree_init_ptr_from_cur(cur, &lptr);
/* for each level */ /* for each level */
for (level = cur->bc_nlevels - 1; level >= 0; level--) { for (level = cur->bc_nlevels - 1; level >= 0; level--) {
...@@ -4852,7 +4871,7 @@ xfs_btree_overlapped_query_range( ...@@ -4852,7 +4871,7 @@ xfs_btree_overlapped_query_range(
/* Load the root of the btree. */ /* Load the root of the btree. */
level = cur->bc_nlevels - 1; level = cur->bc_nlevels - 1;
cur->bc_ops->init_ptr_from_cur(cur, &ptr); xfs_btree_init_ptr_from_cur(cur, &ptr);
error = xfs_btree_lookup_get_block(cur, level, &ptr, &block); error = xfs_btree_lookup_get_block(cur, level, &ptr, &block);
if (error) if (error)
return error; return error;
......
...@@ -714,6 +714,8 @@ void xfs_btree_copy_ptrs(struct xfs_btree_cur *cur, ...@@ -714,6 +714,8 @@ void xfs_btree_copy_ptrs(struct xfs_btree_cur *cur,
void xfs_btree_copy_keys(struct xfs_btree_cur *cur, void xfs_btree_copy_keys(struct xfs_btree_cur *cur,
union xfs_btree_key *dst_key, union xfs_btree_key *dst_key,
const union xfs_btree_key *src_key, int numkeys); const union xfs_btree_key *src_key, int numkeys);
void xfs_btree_init_ptr_from_cur(struct xfs_btree_cur *cur,
union xfs_btree_ptr *ptr);
static inline struct xfs_btree_cur * static inline struct xfs_btree_cur *
xfs_btree_alloc_cursor( xfs_btree_alloc_cursor(
......
...@@ -225,7 +225,6 @@ xfs_btree_stage_ifakeroot( ...@@ -225,7 +225,6 @@ xfs_btree_stage_ifakeroot(
memcpy(nops, cur->bc_ops, sizeof(struct xfs_btree_ops)); memcpy(nops, cur->bc_ops, sizeof(struct xfs_btree_ops));
nops->alloc_block = xfs_btree_fakeroot_alloc_block; nops->alloc_block = xfs_btree_fakeroot_alloc_block;
nops->free_block = xfs_btree_fakeroot_free_block; nops->free_block = xfs_btree_fakeroot_free_block;
nops->init_ptr_from_cur = xfs_btree_fakeroot_init_ptr_from_cur;
nops->dup_cursor = xfs_btree_fakeroot_dup_cursor; nops->dup_cursor = xfs_btree_fakeroot_dup_cursor;
cur->bc_ino.ifake = ifake; cur->bc_ino.ifake = ifake;
......
...@@ -733,7 +733,7 @@ xchk_btree( ...@@ -733,7 +733,7 @@ xchk_btree(
* error codes for us. * error codes for us.
*/ */
level = cur->bc_nlevels - 1; level = cur->bc_nlevels - 1;
cur->bc_ops->init_ptr_from_cur(cur, &ptr); xfs_btree_init_ptr_from_cur(cur, &ptr);
if (!xchk_btree_ptr_ok(bs, cur->bc_nlevels, &ptr)) if (!xchk_btree_ptr_ok(bs, cur->bc_nlevels, &ptr))
goto out; goto out;
error = xchk_btree_get_block(bs, level, &ptr, &block, &bp); error = xchk_btree_get_block(bs, level, &ptr, &block, &bp);
......
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