Commit 6d28f7ea authored by Ryusuke Konishi's avatar Ryusuke Konishi

nilfs2: remove unused btree argument from btree functions

Even though many btree functions take a btree object as their first
argument, most of them are not used in their functions.

This sticky use of the btree argument is hurting code readability and
giving the possibility of inefficient code generation.

So, this removes the unnecessary btree arguments.
Signed-off-by: default avatarRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
parent 9ead9863
...@@ -71,21 +71,17 @@ void nilfs_btree_path_cache_destroy(void) ...@@ -71,21 +71,17 @@ void nilfs_btree_path_cache_destroy(void)
kmem_cache_destroy(nilfs_btree_path_cache); kmem_cache_destroy(nilfs_btree_path_cache);
} }
static inline struct nilfs_btree_path * static inline struct nilfs_btree_path *nilfs_btree_alloc_path(void)
nilfs_btree_alloc_path(const struct nilfs_btree *btree)
{ {
return (struct nilfs_btree_path *) return kmem_cache_alloc(nilfs_btree_path_cache, GFP_NOFS);
kmem_cache_alloc(nilfs_btree_path_cache, GFP_NOFS);
} }
static inline void nilfs_btree_free_path(const struct nilfs_btree *btree, static inline void nilfs_btree_free_path(struct nilfs_btree_path *path)
struct nilfs_btree_path *path)
{ {
kmem_cache_free(nilfs_btree_path_cache, path); kmem_cache_free(nilfs_btree_path_cache, path);
} }
static void nilfs_btree_init_path(const struct nilfs_btree *btree, static void nilfs_btree_init_path(struct nilfs_btree_path *path)
struct nilfs_btree_path *path)
{ {
int level; int level;
...@@ -101,8 +97,7 @@ static void nilfs_btree_init_path(const struct nilfs_btree *btree, ...@@ -101,8 +97,7 @@ static void nilfs_btree_init_path(const struct nilfs_btree *btree,
} }
} }
static void nilfs_btree_clear_path(const struct nilfs_btree *btree, static void nilfs_btree_clear_path(struct nilfs_btree_path *path)
struct nilfs_btree_path *path)
{ {
int level; int level;
...@@ -148,129 +143,110 @@ static int nilfs_btree_get_new_block(const struct nilfs_btree *btree, ...@@ -148,129 +143,110 @@ static int nilfs_btree_get_new_block(const struct nilfs_btree *btree,
} }
static inline int static inline int
nilfs_btree_node_get_flags(const struct nilfs_btree *btree, nilfs_btree_node_get_flags(const struct nilfs_btree_node *node)
const struct nilfs_btree_node *node)
{ {
return node->bn_flags; return node->bn_flags;
} }
static inline void static inline void
nilfs_btree_node_set_flags(struct nilfs_btree *btree, nilfs_btree_node_set_flags(struct nilfs_btree_node *node, int flags)
struct nilfs_btree_node *node,
int flags)
{ {
node->bn_flags = flags; node->bn_flags = flags;
} }
static inline int nilfs_btree_node_root(const struct nilfs_btree *btree, static inline int nilfs_btree_node_root(const struct nilfs_btree_node *node)
const struct nilfs_btree_node *node)
{ {
return nilfs_btree_node_get_flags(btree, node) & NILFS_BTREE_NODE_ROOT; return nilfs_btree_node_get_flags(node) & NILFS_BTREE_NODE_ROOT;
} }
static inline int static inline int
nilfs_btree_node_get_level(const struct nilfs_btree *btree, nilfs_btree_node_get_level(const struct nilfs_btree_node *node)
const struct nilfs_btree_node *node)
{ {
return node->bn_level; return node->bn_level;
} }
static inline void static inline void
nilfs_btree_node_set_level(struct nilfs_btree *btree, nilfs_btree_node_set_level(struct nilfs_btree_node *node, int level)
struct nilfs_btree_node *node,
int level)
{ {
node->bn_level = level; node->bn_level = level;
} }
static inline int static inline int
nilfs_btree_node_get_nchildren(const struct nilfs_btree *btree, nilfs_btree_node_get_nchildren(const struct nilfs_btree_node *node)
const struct nilfs_btree_node *node)
{ {
return le16_to_cpu(node->bn_nchildren); return le16_to_cpu(node->bn_nchildren);
} }
static inline void static inline void
nilfs_btree_node_set_nchildren(struct nilfs_btree *btree, nilfs_btree_node_set_nchildren(struct nilfs_btree_node *node, int nchildren)
struct nilfs_btree_node *node,
int nchildren)
{ {
node->bn_nchildren = cpu_to_le16(nchildren); node->bn_nchildren = cpu_to_le16(nchildren);
} }
static inline int static inline int nilfs_btree_node_size(const struct nilfs_btree *btree)
nilfs_btree_node_size(const struct nilfs_btree *btree)
{ {
return 1 << btree->bt_bmap.b_inode->i_blkbits; return 1 << btree->bt_bmap.b_inode->i_blkbits;
} }
static inline int static inline int
nilfs_btree_node_nchildren_min(const struct nilfs_btree *btree, nilfs_btree_node_nchildren_min(const struct nilfs_btree_node *node,
const struct nilfs_btree_node *node) const struct nilfs_btree *btree)
{ {
return nilfs_btree_node_root(btree, node) ? return nilfs_btree_node_root(node) ?
NILFS_BTREE_ROOT_NCHILDREN_MIN : NILFS_BTREE_ROOT_NCHILDREN_MIN :
NILFS_BTREE_NODE_NCHILDREN_MIN(nilfs_btree_node_size(btree)); NILFS_BTREE_NODE_NCHILDREN_MIN(nilfs_btree_node_size(btree));
} }
static inline int static inline int
nilfs_btree_node_nchildren_max(const struct nilfs_btree *btree, nilfs_btree_node_nchildren_max(const struct nilfs_btree_node *node,
const struct nilfs_btree_node *node) const struct nilfs_btree *btree)
{ {
return nilfs_btree_node_root(btree, node) ? return nilfs_btree_node_root(node) ?
NILFS_BTREE_ROOT_NCHILDREN_MAX : NILFS_BTREE_ROOT_NCHILDREN_MAX :
NILFS_BTREE_NODE_NCHILDREN_MAX(nilfs_btree_node_size(btree)); NILFS_BTREE_NODE_NCHILDREN_MAX(nilfs_btree_node_size(btree));
} }
static inline __le64 * static inline __le64 *
nilfs_btree_node_dkeys(const struct nilfs_btree *btree, nilfs_btree_node_dkeys(const struct nilfs_btree_node *node)
const struct nilfs_btree_node *node)
{ {
return (__le64 *)((char *)(node + 1) + return (__le64 *)((char *)(node + 1) +
(nilfs_btree_node_root(btree, node) ? (nilfs_btree_node_root(node) ?
0 : NILFS_BTREE_NODE_EXTRA_PAD_SIZE)); 0 : NILFS_BTREE_NODE_EXTRA_PAD_SIZE));
} }
static inline __le64 * static inline __le64 *
nilfs_btree_node_dptrs(const struct nilfs_btree *btree, nilfs_btree_node_dptrs(const struct nilfs_btree_node *node,
const struct nilfs_btree_node *node) const struct nilfs_btree *btree)
{ {
return (__le64 *)(nilfs_btree_node_dkeys(btree, node) + return (__le64 *)(nilfs_btree_node_dkeys(node) +
nilfs_btree_node_nchildren_max(btree, node)); nilfs_btree_node_nchildren_max(node, btree));
} }
static inline __u64 static inline __u64
nilfs_btree_node_get_key(const struct nilfs_btree *btree, nilfs_btree_node_get_key(const struct nilfs_btree_node *node, int index)
const struct nilfs_btree_node *node, int index)
{ {
return nilfs_bmap_dkey_to_key(*(nilfs_btree_node_dkeys(btree, node) + return nilfs_bmap_dkey_to_key(*(nilfs_btree_node_dkeys(node) + index));
index));
} }
static inline void static inline void
nilfs_btree_node_set_key(struct nilfs_btree *btree, nilfs_btree_node_set_key(struct nilfs_btree_node *node, int index, __u64 key)
struct nilfs_btree_node *node, int index, __u64 key)
{ {
*(nilfs_btree_node_dkeys(btree, node) + index) = *(nilfs_btree_node_dkeys(node) + index) = nilfs_bmap_key_to_dkey(key);
nilfs_bmap_key_to_dkey(key);
} }
static inline __u64 static inline __u64
nilfs_btree_node_get_ptr(const struct nilfs_btree *btree, nilfs_btree_node_get_ptr(const struct nilfs_btree *btree,
const struct nilfs_btree_node *node, const struct nilfs_btree_node *node, int index)
int index)
{ {
return nilfs_bmap_dptr_to_ptr(*(nilfs_btree_node_dptrs(btree, node) + return nilfs_bmap_dptr_to_ptr(*(nilfs_btree_node_dptrs(node, btree) +
index)); index));
} }
static inline void static inline void
nilfs_btree_node_set_ptr(struct nilfs_btree *btree, nilfs_btree_node_set_ptr(struct nilfs_btree *btree,
struct nilfs_btree_node *node, struct nilfs_btree_node *node, int index, __u64 ptr)
int index,
__u64 ptr)
{ {
*(nilfs_btree_node_dptrs(btree, node) + index) = *(nilfs_btree_node_dptrs(node, btree) + index) =
nilfs_bmap_ptr_to_dptr(ptr); nilfs_bmap_ptr_to_dptr(ptr);
} }
...@@ -283,12 +259,12 @@ static void nilfs_btree_node_init(struct nilfs_btree *btree, ...@@ -283,12 +259,12 @@ static void nilfs_btree_node_init(struct nilfs_btree *btree,
__le64 *dptrs; __le64 *dptrs;
int i; int i;
nilfs_btree_node_set_flags(btree, node, flags); nilfs_btree_node_set_flags(node, flags);
nilfs_btree_node_set_level(btree, node, level); nilfs_btree_node_set_level(node, level);
nilfs_btree_node_set_nchildren(btree, node, nchildren); nilfs_btree_node_set_nchildren(node, nchildren);
dkeys = nilfs_btree_node_dkeys(btree, node); dkeys = nilfs_btree_node_dkeys(node);
dptrs = nilfs_btree_node_dptrs(btree, node); dptrs = nilfs_btree_node_dptrs(node, btree);
for (i = 0; i < nchildren; i++) { for (i = 0; i < nchildren; i++) {
dkeys[i] = nilfs_bmap_key_to_dkey(keys[i]); dkeys[i] = nilfs_bmap_key_to_dkey(keys[i]);
dptrs[i] = nilfs_bmap_ptr_to_dptr(ptrs[i]); dptrs[i] = nilfs_bmap_ptr_to_dptr(ptrs[i]);
...@@ -305,13 +281,13 @@ static void nilfs_btree_node_move_left(struct nilfs_btree *btree, ...@@ -305,13 +281,13 @@ static void nilfs_btree_node_move_left(struct nilfs_btree *btree,
__le64 *ldptrs, *rdptrs; __le64 *ldptrs, *rdptrs;
int lnchildren, rnchildren; int lnchildren, rnchildren;
ldkeys = nilfs_btree_node_dkeys(btree, left); ldkeys = nilfs_btree_node_dkeys(left);
ldptrs = nilfs_btree_node_dptrs(btree, left); ldptrs = nilfs_btree_node_dptrs(left, btree);
lnchildren = nilfs_btree_node_get_nchildren(btree, left); lnchildren = nilfs_btree_node_get_nchildren(left);
rdkeys = nilfs_btree_node_dkeys(btree, right); rdkeys = nilfs_btree_node_dkeys(right);
rdptrs = nilfs_btree_node_dptrs(btree, right); rdptrs = nilfs_btree_node_dptrs(right, btree);
rnchildren = nilfs_btree_node_get_nchildren(btree, right); rnchildren = nilfs_btree_node_get_nchildren(right);
memcpy(ldkeys + lnchildren, rdkeys, n * sizeof(*rdkeys)); memcpy(ldkeys + lnchildren, rdkeys, n * sizeof(*rdkeys));
memcpy(ldptrs + lnchildren, rdptrs, n * sizeof(*rdptrs)); memcpy(ldptrs + lnchildren, rdptrs, n * sizeof(*rdptrs));
...@@ -320,8 +296,8 @@ static void nilfs_btree_node_move_left(struct nilfs_btree *btree, ...@@ -320,8 +296,8 @@ static void nilfs_btree_node_move_left(struct nilfs_btree *btree,
lnchildren += n; lnchildren += n;
rnchildren -= n; rnchildren -= n;
nilfs_btree_node_set_nchildren(btree, left, lnchildren); nilfs_btree_node_set_nchildren(left, lnchildren);
nilfs_btree_node_set_nchildren(btree, right, rnchildren); nilfs_btree_node_set_nchildren(right, rnchildren);
} }
/* Assume that the buffer heads corresponding to left and right are locked. */ /* Assume that the buffer heads corresponding to left and right are locked. */
...@@ -334,13 +310,13 @@ static void nilfs_btree_node_move_right(struct nilfs_btree *btree, ...@@ -334,13 +310,13 @@ static void nilfs_btree_node_move_right(struct nilfs_btree *btree,
__le64 *ldptrs, *rdptrs; __le64 *ldptrs, *rdptrs;
int lnchildren, rnchildren; int lnchildren, rnchildren;
ldkeys = nilfs_btree_node_dkeys(btree, left); ldkeys = nilfs_btree_node_dkeys(left);
ldptrs = nilfs_btree_node_dptrs(btree, left); ldptrs = nilfs_btree_node_dptrs(left, btree);
lnchildren = nilfs_btree_node_get_nchildren(btree, left); lnchildren = nilfs_btree_node_get_nchildren(left);
rdkeys = nilfs_btree_node_dkeys(btree, right); rdkeys = nilfs_btree_node_dkeys(right);
rdptrs = nilfs_btree_node_dptrs(btree, right); rdptrs = nilfs_btree_node_dptrs(right, btree);
rnchildren = nilfs_btree_node_get_nchildren(btree, right); rnchildren = nilfs_btree_node_get_nchildren(right);
memmove(rdkeys + n, rdkeys, rnchildren * sizeof(*rdkeys)); memmove(rdkeys + n, rdkeys, rnchildren * sizeof(*rdkeys));
memmove(rdptrs + n, rdptrs, rnchildren * sizeof(*rdptrs)); memmove(rdptrs + n, rdptrs, rnchildren * sizeof(*rdptrs));
...@@ -349,8 +325,8 @@ static void nilfs_btree_node_move_right(struct nilfs_btree *btree, ...@@ -349,8 +325,8 @@ static void nilfs_btree_node_move_right(struct nilfs_btree *btree,
lnchildren -= n; lnchildren -= n;
rnchildren += n; rnchildren += n;
nilfs_btree_node_set_nchildren(btree, left, lnchildren); nilfs_btree_node_set_nchildren(left, lnchildren);
nilfs_btree_node_set_nchildren(btree, right, rnchildren); nilfs_btree_node_set_nchildren(right, rnchildren);
} }
/* Assume that the buffer head corresponding to node is locked. */ /* Assume that the buffer head corresponding to node is locked. */
...@@ -362,9 +338,9 @@ static void nilfs_btree_node_insert(struct nilfs_btree *btree, ...@@ -362,9 +338,9 @@ static void nilfs_btree_node_insert(struct nilfs_btree *btree,
__le64 *dptrs; __le64 *dptrs;
int nchildren; int nchildren;
dkeys = nilfs_btree_node_dkeys(btree, node); dkeys = nilfs_btree_node_dkeys(node);
dptrs = nilfs_btree_node_dptrs(btree, node); dptrs = nilfs_btree_node_dptrs(node, btree);
nchildren = nilfs_btree_node_get_nchildren(btree, node); nchildren = nilfs_btree_node_get_nchildren(node);
if (index < nchildren) { if (index < nchildren) {
memmove(dkeys + index + 1, dkeys + index, memmove(dkeys + index + 1, dkeys + index,
(nchildren - index) * sizeof(*dkeys)); (nchildren - index) * sizeof(*dkeys));
...@@ -374,7 +350,7 @@ static void nilfs_btree_node_insert(struct nilfs_btree *btree, ...@@ -374,7 +350,7 @@ static void nilfs_btree_node_insert(struct nilfs_btree *btree,
dkeys[index] = nilfs_bmap_key_to_dkey(key); dkeys[index] = nilfs_bmap_key_to_dkey(key);
dptrs[index] = nilfs_bmap_ptr_to_dptr(ptr); dptrs[index] = nilfs_bmap_ptr_to_dptr(ptr);
nchildren++; nchildren++;
nilfs_btree_node_set_nchildren(btree, node, nchildren); nilfs_btree_node_set_nchildren(node, nchildren);
} }
/* Assume that the buffer head corresponding to node is locked. */ /* Assume that the buffer head corresponding to node is locked. */
...@@ -388,11 +364,11 @@ static void nilfs_btree_node_delete(struct nilfs_btree *btree, ...@@ -388,11 +364,11 @@ static void nilfs_btree_node_delete(struct nilfs_btree *btree,
__le64 *dptrs; __le64 *dptrs;
int nchildren; int nchildren;
dkeys = nilfs_btree_node_dkeys(btree, node); dkeys = nilfs_btree_node_dkeys(node);
dptrs = nilfs_btree_node_dptrs(btree, node); dptrs = nilfs_btree_node_dptrs(node, btree);
key = nilfs_bmap_dkey_to_key(dkeys[index]); key = nilfs_bmap_dkey_to_key(dkeys[index]);
ptr = nilfs_bmap_dptr_to_ptr(dptrs[index]); ptr = nilfs_bmap_dptr_to_ptr(dptrs[index]);
nchildren = nilfs_btree_node_get_nchildren(btree, node); nchildren = nilfs_btree_node_get_nchildren(node);
if (keyp != NULL) if (keyp != NULL)
*keyp = key; *keyp = key;
if (ptrp != NULL) if (ptrp != NULL)
...@@ -405,11 +381,10 @@ static void nilfs_btree_node_delete(struct nilfs_btree *btree, ...@@ -405,11 +381,10 @@ static void nilfs_btree_node_delete(struct nilfs_btree *btree,
(nchildren - index - 1) * sizeof(*dptrs)); (nchildren - index - 1) * sizeof(*dptrs));
} }
nchildren--; nchildren--;
nilfs_btree_node_set_nchildren(btree, node, nchildren); nilfs_btree_node_set_nchildren(node, nchildren);
} }
static int nilfs_btree_node_lookup(const struct nilfs_btree *btree, static int nilfs_btree_node_lookup(const struct nilfs_btree_node *node,
const struct nilfs_btree_node *node,
__u64 key, int *indexp) __u64 key, int *indexp)
{ {
__u64 nkey; __u64 nkey;
...@@ -417,12 +392,12 @@ static int nilfs_btree_node_lookup(const struct nilfs_btree *btree, ...@@ -417,12 +392,12 @@ static int nilfs_btree_node_lookup(const struct nilfs_btree *btree,
/* binary search */ /* binary search */
low = 0; low = 0;
high = nilfs_btree_node_get_nchildren(btree, node) - 1; high = nilfs_btree_node_get_nchildren(node) - 1;
index = 0; index = 0;
s = 0; s = 0;
while (low <= high) { while (low <= high) {
index = (low + high) / 2; index = (low + high) / 2;
nkey = nilfs_btree_node_get_key(btree, node, index); nkey = nilfs_btree_node_get_key(node, index);
if (nkey == key) { if (nkey == key) {
s = 0; s = 0;
goto out; goto out;
...@@ -436,9 +411,8 @@ static int nilfs_btree_node_lookup(const struct nilfs_btree *btree, ...@@ -436,9 +411,8 @@ static int nilfs_btree_node_lookup(const struct nilfs_btree *btree,
} }
/* adjust index */ /* adjust index */
if (nilfs_btree_node_get_level(btree, node) > if (nilfs_btree_node_get_level(node) > NILFS_BTREE_LEVEL_NODE_MIN) {
NILFS_BTREE_LEVEL_NODE_MIN) { if (s > 0 && index > 0)
if ((s > 0) && (index > 0))
index--; index--;
} else if (s < 0) } else if (s < 0)
index++; index++;
...@@ -456,25 +430,20 @@ nilfs_btree_get_root(const struct nilfs_btree *btree) ...@@ -456,25 +430,20 @@ nilfs_btree_get_root(const struct nilfs_btree *btree)
} }
static inline struct nilfs_btree_node * static inline struct nilfs_btree_node *
nilfs_btree_get_nonroot_node(const struct nilfs_btree *btree, nilfs_btree_get_nonroot_node(const struct nilfs_btree_path *path, int level)
const struct nilfs_btree_path *path,
int level)
{ {
return (struct nilfs_btree_node *)path[level].bp_bh->b_data; return (struct nilfs_btree_node *)path[level].bp_bh->b_data;
} }
static inline struct nilfs_btree_node * static inline struct nilfs_btree_node *
nilfs_btree_get_sib_node(const struct nilfs_btree *btree, nilfs_btree_get_sib_node(const struct nilfs_btree_path *path, int level)
const struct nilfs_btree_path *path,
int level)
{ {
return (struct nilfs_btree_node *)path[level].bp_sib_bh->b_data; return (struct nilfs_btree_node *)path[level].bp_sib_bh->b_data;
} }
static inline int nilfs_btree_height(const struct nilfs_btree *btree) static inline int nilfs_btree_height(const struct nilfs_btree *btree)
{ {
return nilfs_btree_node_get_level(btree, nilfs_btree_get_root(btree)) return nilfs_btree_node_get_level(nilfs_btree_get_root(btree)) + 1;
+ 1;
} }
static inline struct nilfs_btree_node * static inline struct nilfs_btree_node *
...@@ -484,7 +453,7 @@ nilfs_btree_get_node(const struct nilfs_btree *btree, ...@@ -484,7 +453,7 @@ nilfs_btree_get_node(const struct nilfs_btree *btree,
{ {
return (level == nilfs_btree_height(btree) - 1) ? return (level == nilfs_btree_height(btree) - 1) ?
nilfs_btree_get_root(btree) : nilfs_btree_get_root(btree) :
nilfs_btree_get_nonroot_node(btree, path, level); nilfs_btree_get_nonroot_node(path, level);
} }
static int nilfs_btree_do_lookup(const struct nilfs_btree *btree, static int nilfs_btree_do_lookup(const struct nilfs_btree *btree,
...@@ -496,12 +465,11 @@ static int nilfs_btree_do_lookup(const struct nilfs_btree *btree, ...@@ -496,12 +465,11 @@ static int nilfs_btree_do_lookup(const struct nilfs_btree *btree,
int level, index, found, ret; int level, index, found, ret;
node = nilfs_btree_get_root(btree); node = nilfs_btree_get_root(btree);
level = nilfs_btree_node_get_level(btree, node); level = nilfs_btree_node_get_level(node);
if ((level < minlevel) || if (level < minlevel || nilfs_btree_node_get_nchildren(node) <= 0)
(nilfs_btree_node_get_nchildren(btree, node) <= 0))
return -ENOENT; return -ENOENT;
found = nilfs_btree_node_lookup(btree, node, key, &index); found = nilfs_btree_node_lookup(node, key, &index);
ptr = nilfs_btree_node_get_ptr(btree, node, index); ptr = nilfs_btree_node_get_ptr(btree, node, index);
path[level].bp_bh = NULL; path[level].bp_bh = NULL;
path[level].bp_index = index; path[level].bp_index = index;
...@@ -510,14 +478,13 @@ static int nilfs_btree_do_lookup(const struct nilfs_btree *btree, ...@@ -510,14 +478,13 @@ static int nilfs_btree_do_lookup(const struct nilfs_btree *btree,
ret = nilfs_btree_get_block(btree, ptr, &path[level].bp_bh); ret = nilfs_btree_get_block(btree, ptr, &path[level].bp_bh);
if (ret < 0) if (ret < 0)
return ret; return ret;
node = nilfs_btree_get_nonroot_node(btree, path, level); node = nilfs_btree_get_nonroot_node(path, level);
BUG_ON(level != nilfs_btree_node_get_level(btree, node)); BUG_ON(level != nilfs_btree_node_get_level(node));
if (!found) if (!found)
found = nilfs_btree_node_lookup(btree, node, key, found = nilfs_btree_node_lookup(node, key, &index);
&index);
else else
index = 0; index = 0;
if (index < nilfs_btree_node_nchildren_max(btree, node)) if (index < nilfs_btree_node_nchildren_max(node, btree))
ptr = nilfs_btree_node_get_ptr(btree, node, index); ptr = nilfs_btree_node_get_ptr(btree, node, index);
else { else {
WARN_ON(found || level != NILFS_BTREE_LEVEL_NODE_MIN); WARN_ON(found || level != NILFS_BTREE_LEVEL_NODE_MIN);
...@@ -544,10 +511,10 @@ static int nilfs_btree_do_lookup_last(const struct nilfs_btree *btree, ...@@ -544,10 +511,10 @@ static int nilfs_btree_do_lookup_last(const struct nilfs_btree *btree,
int index, level, ret; int index, level, ret;
node = nilfs_btree_get_root(btree); node = nilfs_btree_get_root(btree);
index = nilfs_btree_node_get_nchildren(btree, node) - 1; index = nilfs_btree_node_get_nchildren(node) - 1;
if (index < 0) if (index < 0)
return -ENOENT; return -ENOENT;
level = nilfs_btree_node_get_level(btree, node); level = nilfs_btree_node_get_level(node);
ptr = nilfs_btree_node_get_ptr(btree, node, index); ptr = nilfs_btree_node_get_ptr(btree, node, index);
path[level].bp_bh = NULL; path[level].bp_bh = NULL;
path[level].bp_index = index; path[level].bp_index = index;
...@@ -556,15 +523,15 @@ static int nilfs_btree_do_lookup_last(const struct nilfs_btree *btree, ...@@ -556,15 +523,15 @@ static int nilfs_btree_do_lookup_last(const struct nilfs_btree *btree,
ret = nilfs_btree_get_block(btree, ptr, &path[level].bp_bh); ret = nilfs_btree_get_block(btree, ptr, &path[level].bp_bh);
if (ret < 0) if (ret < 0)
return ret; return ret;
node = nilfs_btree_get_nonroot_node(btree, path, level); node = nilfs_btree_get_nonroot_node(path, level);
BUG_ON(level != nilfs_btree_node_get_level(btree, node)); BUG_ON(level != nilfs_btree_node_get_level(node));
index = nilfs_btree_node_get_nchildren(btree, node) - 1; index = nilfs_btree_node_get_nchildren(node) - 1;
ptr = nilfs_btree_node_get_ptr(btree, node, index); ptr = nilfs_btree_node_get_ptr(btree, node, index);
path[level].bp_index = index; path[level].bp_index = index;
} }
if (keyp != NULL) if (keyp != NULL)
*keyp = nilfs_btree_node_get_key(btree, node, index); *keyp = nilfs_btree_node_get_key(node, index);
if (ptrp != NULL) if (ptrp != NULL)
*ptrp = ptr; *ptrp = ptr;
...@@ -580,18 +547,18 @@ static int nilfs_btree_lookup(const struct nilfs_bmap *bmap, ...@@ -580,18 +547,18 @@ static int nilfs_btree_lookup(const struct nilfs_bmap *bmap,
int ret; int ret;
btree = (struct nilfs_btree *)bmap; btree = (struct nilfs_btree *)bmap;
path = nilfs_btree_alloc_path(btree); path = nilfs_btree_alloc_path();
if (path == NULL) if (path == NULL)
return -ENOMEM; return -ENOMEM;
nilfs_btree_init_path(btree, path); nilfs_btree_init_path(path);
ret = nilfs_btree_do_lookup(btree, path, key, &ptr, level); ret = nilfs_btree_do_lookup(btree, path, key, &ptr, level);
if (ptrp != NULL) if (ptrp != NULL)
*ptrp = ptr; *ptrp = ptr;
nilfs_btree_clear_path(btree, path); nilfs_btree_clear_path(path);
nilfs_btree_free_path(btree, path); nilfs_btree_free_path(path);
return ret; return ret;
} }
...@@ -608,10 +575,10 @@ static int nilfs_btree_lookup_contig(const struct nilfs_bmap *bmap, ...@@ -608,10 +575,10 @@ static int nilfs_btree_lookup_contig(const struct nilfs_bmap *bmap,
int level = NILFS_BTREE_LEVEL_NODE_MIN; int level = NILFS_BTREE_LEVEL_NODE_MIN;
int ret, cnt, index, maxlevel; int ret, cnt, index, maxlevel;
path = nilfs_btree_alloc_path(btree); path = nilfs_btree_alloc_path();
if (path == NULL) if (path == NULL)
return -ENOMEM; return -ENOMEM;
nilfs_btree_init_path(btree, path); nilfs_btree_init_path(path);
ret = nilfs_btree_do_lookup(btree, path, key, &ptr, level); ret = nilfs_btree_do_lookup(btree, path, key, &ptr, level);
if (ret < 0) if (ret < 0)
goto out; goto out;
...@@ -631,8 +598,8 @@ static int nilfs_btree_lookup_contig(const struct nilfs_bmap *bmap, ...@@ -631,8 +598,8 @@ static int nilfs_btree_lookup_contig(const struct nilfs_bmap *bmap,
node = nilfs_btree_get_node(btree, path, level); node = nilfs_btree_get_node(btree, path, level);
index = path[level].bp_index + 1; index = path[level].bp_index + 1;
for (;;) { for (;;) {
while (index < nilfs_btree_node_get_nchildren(btree, node)) { while (index < nilfs_btree_node_get_nchildren(node)) {
if (nilfs_btree_node_get_key(btree, node, index) != if (nilfs_btree_node_get_key(node, index) !=
key + cnt) key + cnt)
goto end; goto end;
ptr2 = nilfs_btree_node_get_ptr(btree, node, index); ptr2 = nilfs_btree_node_get_ptr(btree, node, index);
...@@ -653,8 +620,8 @@ static int nilfs_btree_lookup_contig(const struct nilfs_bmap *bmap, ...@@ -653,8 +620,8 @@ static int nilfs_btree_lookup_contig(const struct nilfs_bmap *bmap,
/* look-up right sibling node */ /* look-up right sibling node */
node = nilfs_btree_get_node(btree, path, level + 1); node = nilfs_btree_get_node(btree, path, level + 1);
index = path[level + 1].bp_index + 1; index = path[level + 1].bp_index + 1;
if (index >= nilfs_btree_node_get_nchildren(btree, node) || if (index >= nilfs_btree_node_get_nchildren(node) ||
nilfs_btree_node_get_key(btree, node, index) != key + cnt) nilfs_btree_node_get_key(node, index) != key + cnt)
break; break;
ptr2 = nilfs_btree_node_get_ptr(btree, node, index); ptr2 = nilfs_btree_node_get_ptr(btree, node, index);
path[level + 1].bp_index = index; path[level + 1].bp_index = index;
...@@ -664,7 +631,7 @@ static int nilfs_btree_lookup_contig(const struct nilfs_bmap *bmap, ...@@ -664,7 +631,7 @@ static int nilfs_btree_lookup_contig(const struct nilfs_bmap *bmap,
ret = nilfs_btree_get_block(btree, ptr2, &path[level].bp_bh); ret = nilfs_btree_get_block(btree, ptr2, &path[level].bp_bh);
if (ret < 0) if (ret < 0)
goto out; goto out;
node = nilfs_btree_get_nonroot_node(btree, path, level); node = nilfs_btree_get_nonroot_node(path, level);
index = 0; index = 0;
path[level].bp_index = index; path[level].bp_index = index;
} }
...@@ -672,8 +639,8 @@ static int nilfs_btree_lookup_contig(const struct nilfs_bmap *bmap, ...@@ -672,8 +639,8 @@ static int nilfs_btree_lookup_contig(const struct nilfs_bmap *bmap,
*ptrp = ptr; *ptrp = ptr;
ret = cnt; ret = cnt;
out: out:
nilfs_btree_clear_path(btree, path); nilfs_btree_clear_path(path);
nilfs_btree_free_path(btree, path); nilfs_btree_free_path(path);
return ret; return ret;
} }
...@@ -685,9 +652,7 @@ static void nilfs_btree_promote_key(struct nilfs_btree *btree, ...@@ -685,9 +652,7 @@ static void nilfs_btree_promote_key(struct nilfs_btree *btree,
do { do {
lock_buffer(path[level].bp_bh); lock_buffer(path[level].bp_bh);
nilfs_btree_node_set_key( nilfs_btree_node_set_key(
btree, nilfs_btree_get_nonroot_node(path, level),
nilfs_btree_get_nonroot_node(
btree, path, level),
path[level].bp_index, key); path[level].bp_index, key);
if (!buffer_dirty(path[level].bp_bh)) if (!buffer_dirty(path[level].bp_bh))
nilfs_btnode_mark_dirty(path[level].bp_bh); nilfs_btnode_mark_dirty(path[level].bp_bh);
...@@ -698,8 +663,7 @@ static void nilfs_btree_promote_key(struct nilfs_btree *btree, ...@@ -698,8 +663,7 @@ static void nilfs_btree_promote_key(struct nilfs_btree *btree,
/* root */ /* root */
if (level == nilfs_btree_height(btree) - 1) { if (level == nilfs_btree_height(btree) - 1) {
nilfs_btree_node_set_key(btree, nilfs_btree_node_set_key(nilfs_btree_get_root(btree),
nilfs_btree_get_root(btree),
path[level].bp_index, key); path[level].bp_index, key);
} }
} }
...@@ -712,7 +676,7 @@ static void nilfs_btree_do_insert(struct nilfs_btree *btree, ...@@ -712,7 +676,7 @@ static void nilfs_btree_do_insert(struct nilfs_btree *btree,
if (level < nilfs_btree_height(btree) - 1) { if (level < nilfs_btree_height(btree) - 1) {
lock_buffer(path[level].bp_bh); lock_buffer(path[level].bp_bh);
node = nilfs_btree_get_nonroot_node(btree, path, level); node = nilfs_btree_get_nonroot_node(path, level);
nilfs_btree_node_insert(btree, node, *keyp, *ptrp, nilfs_btree_node_insert(btree, node, *keyp, *ptrp,
path[level].bp_index); path[level].bp_index);
if (!buffer_dirty(path[level].bp_bh)) if (!buffer_dirty(path[level].bp_bh))
...@@ -721,8 +685,8 @@ static void nilfs_btree_do_insert(struct nilfs_btree *btree, ...@@ -721,8 +685,8 @@ static void nilfs_btree_do_insert(struct nilfs_btree *btree,
if (path[level].bp_index == 0) if (path[level].bp_index == 0)
nilfs_btree_promote_key(btree, path, level + 1, nilfs_btree_promote_key(btree, path, level + 1,
nilfs_btree_node_get_key( nilfs_btree_node_get_key(node,
btree, node, 0)); 0));
} else { } else {
node = nilfs_btree_get_root(btree); node = nilfs_btree_get_root(btree);
nilfs_btree_node_insert(btree, node, *keyp, *ptrp, nilfs_btree_node_insert(btree, node, *keyp, *ptrp,
...@@ -740,10 +704,10 @@ static void nilfs_btree_carry_left(struct nilfs_btree *btree, ...@@ -740,10 +704,10 @@ static void nilfs_btree_carry_left(struct nilfs_btree *btree,
lock_buffer(path[level].bp_bh); lock_buffer(path[level].bp_bh);
lock_buffer(path[level].bp_sib_bh); lock_buffer(path[level].bp_sib_bh);
node = nilfs_btree_get_nonroot_node(btree, path, level); node = nilfs_btree_get_nonroot_node(path, level);
left = nilfs_btree_get_sib_node(btree, path, level); left = nilfs_btree_get_sib_node(path, level);
nchildren = nilfs_btree_node_get_nchildren(btree, node); nchildren = nilfs_btree_node_get_nchildren(node);
lnchildren = nilfs_btree_node_get_nchildren(btree, left); lnchildren = nilfs_btree_node_get_nchildren(left);
move = 0; move = 0;
n = (nchildren + lnchildren + 1) / 2 - lnchildren; n = (nchildren + lnchildren + 1) / 2 - lnchildren;
...@@ -764,7 +728,7 @@ static void nilfs_btree_carry_left(struct nilfs_btree *btree, ...@@ -764,7 +728,7 @@ static void nilfs_btree_carry_left(struct nilfs_btree *btree,
unlock_buffer(path[level].bp_sib_bh); unlock_buffer(path[level].bp_sib_bh);
nilfs_btree_promote_key(btree, path, level + 1, nilfs_btree_promote_key(btree, path, level + 1,
nilfs_btree_node_get_key(btree, node, 0)); nilfs_btree_node_get_key(node, 0));
if (move) { if (move) {
brelse(path[level].bp_bh); brelse(path[level].bp_bh);
...@@ -791,10 +755,10 @@ static void nilfs_btree_carry_right(struct nilfs_btree *btree, ...@@ -791,10 +755,10 @@ static void nilfs_btree_carry_right(struct nilfs_btree *btree,
lock_buffer(path[level].bp_bh); lock_buffer(path[level].bp_bh);
lock_buffer(path[level].bp_sib_bh); lock_buffer(path[level].bp_sib_bh);
node = nilfs_btree_get_nonroot_node(btree, path, level); node = nilfs_btree_get_nonroot_node(path, level);
right = nilfs_btree_get_sib_node(btree, path, level); right = nilfs_btree_get_sib_node(path, level);
nchildren = nilfs_btree_node_get_nchildren(btree, node); nchildren = nilfs_btree_node_get_nchildren(node);
rnchildren = nilfs_btree_node_get_nchildren(btree, right); rnchildren = nilfs_btree_node_get_nchildren(right);
move = 0; move = 0;
n = (nchildren + rnchildren + 1) / 2 - rnchildren; n = (nchildren + rnchildren + 1) / 2 - rnchildren;
...@@ -816,15 +780,14 @@ static void nilfs_btree_carry_right(struct nilfs_btree *btree, ...@@ -816,15 +780,14 @@ static void nilfs_btree_carry_right(struct nilfs_btree *btree,
path[level + 1].bp_index++; path[level + 1].bp_index++;
nilfs_btree_promote_key(btree, path, level + 1, nilfs_btree_promote_key(btree, path, level + 1,
nilfs_btree_node_get_key(btree, right, 0)); nilfs_btree_node_get_key(right, 0));
path[level + 1].bp_index--; path[level + 1].bp_index--;
if (move) { if (move) {
brelse(path[level].bp_bh); brelse(path[level].bp_bh);
path[level].bp_bh = path[level].bp_sib_bh; path[level].bp_bh = path[level].bp_sib_bh;
path[level].bp_sib_bh = NULL; path[level].bp_sib_bh = NULL;
path[level].bp_index -= path[level].bp_index -= nilfs_btree_node_get_nchildren(node);
nilfs_btree_node_get_nchildren(btree, node);
path[level + 1].bp_index++; path[level + 1].bp_index++;
} else { } else {
brelse(path[level].bp_sib_bh); brelse(path[level].bp_sib_bh);
...@@ -846,9 +809,9 @@ static void nilfs_btree_split(struct nilfs_btree *btree, ...@@ -846,9 +809,9 @@ static void nilfs_btree_split(struct nilfs_btree *btree,
lock_buffer(path[level].bp_bh); lock_buffer(path[level].bp_bh);
lock_buffer(path[level].bp_sib_bh); lock_buffer(path[level].bp_sib_bh);
node = nilfs_btree_get_nonroot_node(btree, path, level); node = nilfs_btree_get_nonroot_node(path, level);
right = nilfs_btree_get_sib_node(btree, path, level); right = nilfs_btree_get_sib_node(path, level);
nchildren = nilfs_btree_node_get_nchildren(btree, node); nchildren = nilfs_btree_node_get_nchildren(node);
move = 0; move = 0;
n = (nchildren + 1) / 2; n = (nchildren + 1) / 2;
...@@ -867,16 +830,15 @@ static void nilfs_btree_split(struct nilfs_btree *btree, ...@@ -867,16 +830,15 @@ static void nilfs_btree_split(struct nilfs_btree *btree,
unlock_buffer(path[level].bp_bh); unlock_buffer(path[level].bp_bh);
unlock_buffer(path[level].bp_sib_bh); unlock_buffer(path[level].bp_sib_bh);
newkey = nilfs_btree_node_get_key(btree, right, 0); newkey = nilfs_btree_node_get_key(right, 0);
newptr = path[level].bp_newreq.bpr_ptr; newptr = path[level].bp_newreq.bpr_ptr;
if (move) { if (move) {
path[level].bp_index -= path[level].bp_index -= nilfs_btree_node_get_nchildren(node);
nilfs_btree_node_get_nchildren(btree, node);
nilfs_btree_node_insert(btree, right, *keyp, *ptrp, nilfs_btree_node_insert(btree, right, *keyp, *ptrp,
path[level].bp_index); path[level].bp_index);
*keyp = nilfs_btree_node_get_key(btree, right, 0); *keyp = nilfs_btree_node_get_key(right, 0);
*ptrp = path[level].bp_newreq.bpr_ptr; *ptrp = path[level].bp_newreq.bpr_ptr;
brelse(path[level].bp_bh); brelse(path[level].bp_bh);
...@@ -885,7 +847,7 @@ static void nilfs_btree_split(struct nilfs_btree *btree, ...@@ -885,7 +847,7 @@ static void nilfs_btree_split(struct nilfs_btree *btree,
} else { } else {
nilfs_btree_do_insert(btree, path, level, keyp, ptrp); nilfs_btree_do_insert(btree, path, level, keyp, ptrp);
*keyp = nilfs_btree_node_get_key(btree, right, 0); *keyp = nilfs_btree_node_get_key(right, 0);
*ptrp = path[level].bp_newreq.bpr_ptr; *ptrp = path[level].bp_newreq.bpr_ptr;
brelse(path[level].bp_sib_bh); brelse(path[level].bp_sib_bh);
...@@ -905,12 +867,12 @@ static void nilfs_btree_grow(struct nilfs_btree *btree, ...@@ -905,12 +867,12 @@ static void nilfs_btree_grow(struct nilfs_btree *btree,
lock_buffer(path[level].bp_sib_bh); lock_buffer(path[level].bp_sib_bh);
root = nilfs_btree_get_root(btree); root = nilfs_btree_get_root(btree);
child = nilfs_btree_get_sib_node(btree, path, level); child = nilfs_btree_get_sib_node(path, level);
n = nilfs_btree_node_get_nchildren(btree, root); n = nilfs_btree_node_get_nchildren(root);
nilfs_btree_node_move_right(btree, root, child, n); nilfs_btree_node_move_right(btree, root, child, n);
nilfs_btree_node_set_level(btree, root, level + 1); nilfs_btree_node_set_level(root, level + 1);
if (!buffer_dirty(path[level].bp_sib_bh)) if (!buffer_dirty(path[level].bp_sib_bh))
nilfs_btnode_mark_dirty(path[level].bp_sib_bh); nilfs_btnode_mark_dirty(path[level].bp_sib_bh);
...@@ -922,7 +884,7 @@ static void nilfs_btree_grow(struct nilfs_btree *btree, ...@@ -922,7 +884,7 @@ static void nilfs_btree_grow(struct nilfs_btree *btree,
nilfs_btree_do_insert(btree, path, level, keyp, ptrp); nilfs_btree_do_insert(btree, path, level, keyp, ptrp);
*keyp = nilfs_btree_node_get_key(btree, child, 0); *keyp = nilfs_btree_node_get_key(child, 0);
*ptrp = path[level].bp_newreq.bpr_ptr; *ptrp = path[level].bp_newreq.bpr_ptr;
} }
...@@ -1007,9 +969,9 @@ static int nilfs_btree_prepare_insert(struct nilfs_btree *btree, ...@@ -1007,9 +969,9 @@ static int nilfs_btree_prepare_insert(struct nilfs_btree *btree,
for (level = NILFS_BTREE_LEVEL_NODE_MIN; for (level = NILFS_BTREE_LEVEL_NODE_MIN;
level < nilfs_btree_height(btree) - 1; level < nilfs_btree_height(btree) - 1;
level++) { level++) {
node = nilfs_btree_get_nonroot_node(btree, path, level); node = nilfs_btree_get_nonroot_node(path, level);
if (nilfs_btree_node_get_nchildren(btree, node) < if (nilfs_btree_node_get_nchildren(node) <
nilfs_btree_node_nchildren_max(btree, node)) { nilfs_btree_node_nchildren_max(node, btree)) {
path[level].bp_op = nilfs_btree_do_insert; path[level].bp_op = nilfs_btree_do_insert;
stats->bs_nblocks++; stats->bs_nblocks++;
goto out; goto out;
...@@ -1026,8 +988,8 @@ static int nilfs_btree_prepare_insert(struct nilfs_btree *btree, ...@@ -1026,8 +988,8 @@ static int nilfs_btree_prepare_insert(struct nilfs_btree *btree,
if (ret < 0) if (ret < 0)
goto err_out_child_node; goto err_out_child_node;
sib = (struct nilfs_btree_node *)bh->b_data; sib = (struct nilfs_btree_node *)bh->b_data;
if (nilfs_btree_node_get_nchildren(btree, sib) < if (nilfs_btree_node_get_nchildren(sib) <
nilfs_btree_node_nchildren_max(btree, sib)) { nilfs_btree_node_nchildren_max(sib, btree)) {
path[level].bp_sib_bh = bh; path[level].bp_sib_bh = bh;
path[level].bp_op = nilfs_btree_carry_left; path[level].bp_op = nilfs_btree_carry_left;
stats->bs_nblocks++; stats->bs_nblocks++;
...@@ -1038,15 +1000,15 @@ static int nilfs_btree_prepare_insert(struct nilfs_btree *btree, ...@@ -1038,15 +1000,15 @@ static int nilfs_btree_prepare_insert(struct nilfs_btree *btree,
/* right sibling */ /* right sibling */
if (pindex < if (pindex <
nilfs_btree_node_get_nchildren(btree, parent) - 1) { nilfs_btree_node_get_nchildren(parent) - 1) {
sibptr = nilfs_btree_node_get_ptr(btree, parent, sibptr = nilfs_btree_node_get_ptr(btree, parent,
pindex + 1); pindex + 1);
ret = nilfs_btree_get_block(btree, sibptr, &bh); ret = nilfs_btree_get_block(btree, sibptr, &bh);
if (ret < 0) if (ret < 0)
goto err_out_child_node; goto err_out_child_node;
sib = (struct nilfs_btree_node *)bh->b_data; sib = (struct nilfs_btree_node *)bh->b_data;
if (nilfs_btree_node_get_nchildren(btree, sib) < if (nilfs_btree_node_get_nchildren(sib) <
nilfs_btree_node_nchildren_max(btree, sib)) { nilfs_btree_node_nchildren_max(sib, btree)) {
path[level].bp_sib_bh = bh; path[level].bp_sib_bh = bh;
path[level].bp_op = nilfs_btree_carry_right; path[level].bp_op = nilfs_btree_carry_right;
stats->bs_nblocks++; stats->bs_nblocks++;
...@@ -1081,8 +1043,8 @@ static int nilfs_btree_prepare_insert(struct nilfs_btree *btree, ...@@ -1081,8 +1043,8 @@ static int nilfs_btree_prepare_insert(struct nilfs_btree *btree,
/* root */ /* root */
node = nilfs_btree_get_root(btree); node = nilfs_btree_get_root(btree);
if (nilfs_btree_node_get_nchildren(btree, node) < if (nilfs_btree_node_get_nchildren(node) <
nilfs_btree_node_nchildren_max(btree, node)) { nilfs_btree_node_nchildren_max(node, btree)) {
path[level].bp_op = nilfs_btree_do_insert; path[level].bp_op = nilfs_btree_do_insert;
stats->bs_nblocks++; stats->bs_nblocks++;
goto out; goto out;
...@@ -1164,10 +1126,10 @@ static int nilfs_btree_insert(struct nilfs_bmap *bmap, __u64 key, __u64 ptr) ...@@ -1164,10 +1126,10 @@ static int nilfs_btree_insert(struct nilfs_bmap *bmap, __u64 key, __u64 ptr)
int level, ret; int level, ret;
btree = (struct nilfs_btree *)bmap; btree = (struct nilfs_btree *)bmap;
path = nilfs_btree_alloc_path(btree); path = nilfs_btree_alloc_path();
if (path == NULL) if (path == NULL)
return -ENOMEM; return -ENOMEM;
nilfs_btree_init_path(btree, path); nilfs_btree_init_path(path);
ret = nilfs_btree_do_lookup(btree, path, key, NULL, ret = nilfs_btree_do_lookup(btree, path, key, NULL,
NILFS_BTREE_LEVEL_NODE_MIN); NILFS_BTREE_LEVEL_NODE_MIN);
...@@ -1184,8 +1146,8 @@ static int nilfs_btree_insert(struct nilfs_bmap *bmap, __u64 key, __u64 ptr) ...@@ -1184,8 +1146,8 @@ static int nilfs_btree_insert(struct nilfs_bmap *bmap, __u64 key, __u64 ptr)
nilfs_bmap_add_blocks(bmap, stats.bs_nblocks); nilfs_bmap_add_blocks(bmap, stats.bs_nblocks);
out: out:
nilfs_btree_clear_path(btree, path); nilfs_btree_clear_path(path);
nilfs_btree_free_path(btree, path); nilfs_btree_free_path(path);
return ret; return ret;
} }
...@@ -1197,7 +1159,7 @@ static void nilfs_btree_do_delete(struct nilfs_btree *btree, ...@@ -1197,7 +1159,7 @@ static void nilfs_btree_do_delete(struct nilfs_btree *btree,
if (level < nilfs_btree_height(btree) - 1) { if (level < nilfs_btree_height(btree) - 1) {
lock_buffer(path[level].bp_bh); lock_buffer(path[level].bp_bh);
node = nilfs_btree_get_nonroot_node(btree, path, level); node = nilfs_btree_get_nonroot_node(path, level);
nilfs_btree_node_delete(btree, node, keyp, ptrp, nilfs_btree_node_delete(btree, node, keyp, ptrp,
path[level].bp_index); path[level].bp_index);
if (!buffer_dirty(path[level].bp_bh)) if (!buffer_dirty(path[level].bp_bh))
...@@ -1205,7 +1167,7 @@ static void nilfs_btree_do_delete(struct nilfs_btree *btree, ...@@ -1205,7 +1167,7 @@ static void nilfs_btree_do_delete(struct nilfs_btree *btree,
unlock_buffer(path[level].bp_bh); unlock_buffer(path[level].bp_bh);
if (path[level].bp_index == 0) if (path[level].bp_index == 0)
nilfs_btree_promote_key(btree, path, level + 1, nilfs_btree_promote_key(btree, path, level + 1,
nilfs_btree_node_get_key(btree, node, 0)); nilfs_btree_node_get_key(node, 0));
} else { } else {
node = nilfs_btree_get_root(btree); node = nilfs_btree_get_root(btree);
nilfs_btree_node_delete(btree, node, keyp, ptrp, nilfs_btree_node_delete(btree, node, keyp, ptrp,
...@@ -1225,10 +1187,10 @@ static void nilfs_btree_borrow_left(struct nilfs_btree *btree, ...@@ -1225,10 +1187,10 @@ static void nilfs_btree_borrow_left(struct nilfs_btree *btree,
lock_buffer(path[level].bp_bh); lock_buffer(path[level].bp_bh);
lock_buffer(path[level].bp_sib_bh); lock_buffer(path[level].bp_sib_bh);
node = nilfs_btree_get_nonroot_node(btree, path, level); node = nilfs_btree_get_nonroot_node(path, level);
left = nilfs_btree_get_sib_node(btree, path, level); left = nilfs_btree_get_sib_node(path, level);
nchildren = nilfs_btree_node_get_nchildren(btree, node); nchildren = nilfs_btree_node_get_nchildren(node);
lnchildren = nilfs_btree_node_get_nchildren(btree, left); lnchildren = nilfs_btree_node_get_nchildren(left);
n = (nchildren + lnchildren) / 2 - nchildren; n = (nchildren + lnchildren) / 2 - nchildren;
...@@ -1243,7 +1205,7 @@ static void nilfs_btree_borrow_left(struct nilfs_btree *btree, ...@@ -1243,7 +1205,7 @@ static void nilfs_btree_borrow_left(struct nilfs_btree *btree,
unlock_buffer(path[level].bp_sib_bh); unlock_buffer(path[level].bp_sib_bh);
nilfs_btree_promote_key(btree, path, level + 1, nilfs_btree_promote_key(btree, path, level + 1,
nilfs_btree_node_get_key(btree, node, 0)); nilfs_btree_node_get_key(node, 0));
brelse(path[level].bp_sib_bh); brelse(path[level].bp_sib_bh);
path[level].bp_sib_bh = NULL; path[level].bp_sib_bh = NULL;
...@@ -1262,10 +1224,10 @@ static void nilfs_btree_borrow_right(struct nilfs_btree *btree, ...@@ -1262,10 +1224,10 @@ static void nilfs_btree_borrow_right(struct nilfs_btree *btree,
lock_buffer(path[level].bp_bh); lock_buffer(path[level].bp_bh);
lock_buffer(path[level].bp_sib_bh); lock_buffer(path[level].bp_sib_bh);
node = nilfs_btree_get_nonroot_node(btree, path, level); node = nilfs_btree_get_nonroot_node(path, level);
right = nilfs_btree_get_sib_node(btree, path, level); right = nilfs_btree_get_sib_node(path, level);
nchildren = nilfs_btree_node_get_nchildren(btree, node); nchildren = nilfs_btree_node_get_nchildren(node);
rnchildren = nilfs_btree_node_get_nchildren(btree, right); rnchildren = nilfs_btree_node_get_nchildren(right);
n = (nchildren + rnchildren) / 2 - nchildren; n = (nchildren + rnchildren) / 2 - nchildren;
...@@ -1281,7 +1243,7 @@ static void nilfs_btree_borrow_right(struct nilfs_btree *btree, ...@@ -1281,7 +1243,7 @@ static void nilfs_btree_borrow_right(struct nilfs_btree *btree,
path[level + 1].bp_index++; path[level + 1].bp_index++;
nilfs_btree_promote_key(btree, path, level + 1, nilfs_btree_promote_key(btree, path, level + 1,
nilfs_btree_node_get_key(btree, right, 0)); nilfs_btree_node_get_key(right, 0));
path[level + 1].bp_index--; path[level + 1].bp_index--;
brelse(path[level].bp_sib_bh); brelse(path[level].bp_sib_bh);
...@@ -1300,10 +1262,10 @@ static void nilfs_btree_concat_left(struct nilfs_btree *btree, ...@@ -1300,10 +1262,10 @@ static void nilfs_btree_concat_left(struct nilfs_btree *btree,
lock_buffer(path[level].bp_bh); lock_buffer(path[level].bp_bh);
lock_buffer(path[level].bp_sib_bh); lock_buffer(path[level].bp_sib_bh);
node = nilfs_btree_get_nonroot_node(btree, path, level); node = nilfs_btree_get_nonroot_node(path, level);
left = nilfs_btree_get_sib_node(btree, path, level); left = nilfs_btree_get_sib_node(path, level);
n = nilfs_btree_node_get_nchildren(btree, node); n = nilfs_btree_node_get_nchildren(node);
nilfs_btree_node_move_left(btree, left, node, n); nilfs_btree_node_move_left(btree, left, node, n);
...@@ -1316,7 +1278,7 @@ static void nilfs_btree_concat_left(struct nilfs_btree *btree, ...@@ -1316,7 +1278,7 @@ static void nilfs_btree_concat_left(struct nilfs_btree *btree,
nilfs_btnode_delete(path[level].bp_bh); nilfs_btnode_delete(path[level].bp_bh);
path[level].bp_bh = path[level].bp_sib_bh; path[level].bp_bh = path[level].bp_sib_bh;
path[level].bp_sib_bh = NULL; path[level].bp_sib_bh = NULL;
path[level].bp_index += nilfs_btree_node_get_nchildren(btree, left); path[level].bp_index += nilfs_btree_node_get_nchildren(left);
} }
static void nilfs_btree_concat_right(struct nilfs_btree *btree, static void nilfs_btree_concat_right(struct nilfs_btree *btree,
...@@ -1331,10 +1293,10 @@ static void nilfs_btree_concat_right(struct nilfs_btree *btree, ...@@ -1331,10 +1293,10 @@ static void nilfs_btree_concat_right(struct nilfs_btree *btree,
lock_buffer(path[level].bp_bh); lock_buffer(path[level].bp_bh);
lock_buffer(path[level].bp_sib_bh); lock_buffer(path[level].bp_sib_bh);
node = nilfs_btree_get_nonroot_node(btree, path, level); node = nilfs_btree_get_nonroot_node(path, level);
right = nilfs_btree_get_sib_node(btree, path, level); right = nilfs_btree_get_sib_node(path, level);
n = nilfs_btree_node_get_nchildren(btree, right); n = nilfs_btree_node_get_nchildren(right);
nilfs_btree_node_move_left(btree, node, right, n); nilfs_btree_node_move_left(btree, node, right, n);
...@@ -1360,11 +1322,11 @@ static void nilfs_btree_shrink(struct nilfs_btree *btree, ...@@ -1360,11 +1322,11 @@ static void nilfs_btree_shrink(struct nilfs_btree *btree,
lock_buffer(path[level].bp_bh); lock_buffer(path[level].bp_bh);
root = nilfs_btree_get_root(btree); root = nilfs_btree_get_root(btree);
child = nilfs_btree_get_nonroot_node(btree, path, level); child = nilfs_btree_get_nonroot_node(path, level);
nilfs_btree_node_delete(btree, root, NULL, NULL, 0); nilfs_btree_node_delete(btree, root, NULL, NULL, 0);
nilfs_btree_node_set_level(btree, root, level); nilfs_btree_node_set_level(root, level);
n = nilfs_btree_node_get_nchildren(btree, child); n = nilfs_btree_node_get_nchildren(child);
nilfs_btree_node_move_left(btree, root, child, n); nilfs_btree_node_move_left(btree, root, child, n);
unlock_buffer(path[level].bp_bh); unlock_buffer(path[level].bp_bh);
...@@ -1388,7 +1350,7 @@ static int nilfs_btree_prepare_delete(struct nilfs_btree *btree, ...@@ -1388,7 +1350,7 @@ static int nilfs_btree_prepare_delete(struct nilfs_btree *btree,
for (level = NILFS_BTREE_LEVEL_NODE_MIN; for (level = NILFS_BTREE_LEVEL_NODE_MIN;
level < nilfs_btree_height(btree) - 1; level < nilfs_btree_height(btree) - 1;
level++) { level++) {
node = nilfs_btree_get_nonroot_node(btree, path, level); node = nilfs_btree_get_nonroot_node(path, level);
path[level].bp_oldreq.bpr_ptr = path[level].bp_oldreq.bpr_ptr =
nilfs_btree_node_get_ptr(btree, node, nilfs_btree_node_get_ptr(btree, node,
path[level].bp_index); path[level].bp_index);
...@@ -1397,8 +1359,8 @@ static int nilfs_btree_prepare_delete(struct nilfs_btree *btree, ...@@ -1397,8 +1359,8 @@ static int nilfs_btree_prepare_delete(struct nilfs_btree *btree,
if (ret < 0) if (ret < 0)
goto err_out_child_node; goto err_out_child_node;
if (nilfs_btree_node_get_nchildren(btree, node) > if (nilfs_btree_node_get_nchildren(node) >
nilfs_btree_node_nchildren_min(btree, node)) { nilfs_btree_node_nchildren_min(node, btree)) {
path[level].bp_op = nilfs_btree_do_delete; path[level].bp_op = nilfs_btree_do_delete;
stats->bs_nblocks++; stats->bs_nblocks++;
goto out; goto out;
...@@ -1415,8 +1377,8 @@ static int nilfs_btree_prepare_delete(struct nilfs_btree *btree, ...@@ -1415,8 +1377,8 @@ static int nilfs_btree_prepare_delete(struct nilfs_btree *btree,
if (ret < 0) if (ret < 0)
goto err_out_curr_node; goto err_out_curr_node;
sib = (struct nilfs_btree_node *)bh->b_data; sib = (struct nilfs_btree_node *)bh->b_data;
if (nilfs_btree_node_get_nchildren(btree, sib) > if (nilfs_btree_node_get_nchildren(sib) >
nilfs_btree_node_nchildren_min(btree, sib)) { nilfs_btree_node_nchildren_min(sib, btree)) {
path[level].bp_sib_bh = bh; path[level].bp_sib_bh = bh;
path[level].bp_op = nilfs_btree_borrow_left; path[level].bp_op = nilfs_btree_borrow_left;
stats->bs_nblocks++; stats->bs_nblocks++;
...@@ -1428,7 +1390,7 @@ static int nilfs_btree_prepare_delete(struct nilfs_btree *btree, ...@@ -1428,7 +1390,7 @@ static int nilfs_btree_prepare_delete(struct nilfs_btree *btree,
/* continue; */ /* continue; */
} }
} else if (pindex < } else if (pindex <
nilfs_btree_node_get_nchildren(btree, parent) - 1) { nilfs_btree_node_get_nchildren(parent) - 1) {
/* right sibling */ /* right sibling */
sibptr = nilfs_btree_node_get_ptr(btree, parent, sibptr = nilfs_btree_node_get_ptr(btree, parent,
pindex + 1); pindex + 1);
...@@ -1436,8 +1398,8 @@ static int nilfs_btree_prepare_delete(struct nilfs_btree *btree, ...@@ -1436,8 +1398,8 @@ static int nilfs_btree_prepare_delete(struct nilfs_btree *btree,
if (ret < 0) if (ret < 0)
goto err_out_curr_node; goto err_out_curr_node;
sib = (struct nilfs_btree_node *)bh->b_data; sib = (struct nilfs_btree_node *)bh->b_data;
if (nilfs_btree_node_get_nchildren(btree, sib) > if (nilfs_btree_node_get_nchildren(sib) >
nilfs_btree_node_nchildren_min(btree, sib)) { nilfs_btree_node_nchildren_min(sib, btree)) {
path[level].bp_sib_bh = bh; path[level].bp_sib_bh = bh;
path[level].bp_op = nilfs_btree_borrow_right; path[level].bp_op = nilfs_btree_borrow_right;
stats->bs_nblocks++; stats->bs_nblocks++;
...@@ -1452,7 +1414,7 @@ static int nilfs_btree_prepare_delete(struct nilfs_btree *btree, ...@@ -1452,7 +1414,7 @@ static int nilfs_btree_prepare_delete(struct nilfs_btree *btree,
/* no siblings */ /* no siblings */
/* the only child of the root node */ /* the only child of the root node */
WARN_ON(level != nilfs_btree_height(btree) - 2); WARN_ON(level != nilfs_btree_height(btree) - 2);
if (nilfs_btree_node_get_nchildren(btree, node) - 1 <= if (nilfs_btree_node_get_nchildren(node) - 1 <=
NILFS_BTREE_ROOT_NCHILDREN_MAX) { NILFS_BTREE_ROOT_NCHILDREN_MAX) {
path[level].bp_op = nilfs_btree_shrink; path[level].bp_op = nilfs_btree_shrink;
stats->bs_nblocks += 2; stats->bs_nblocks += 2;
...@@ -1523,10 +1485,10 @@ static int nilfs_btree_delete(struct nilfs_bmap *bmap, __u64 key) ...@@ -1523,10 +1485,10 @@ static int nilfs_btree_delete(struct nilfs_bmap *bmap, __u64 key)
int level, ret; int level, ret;
btree = (struct nilfs_btree *)bmap; btree = (struct nilfs_btree *)bmap;
path = nilfs_btree_alloc_path(btree); path = nilfs_btree_alloc_path();
if (path == NULL) if (path == NULL)
return -ENOMEM; return -ENOMEM;
nilfs_btree_init_path(btree, path); nilfs_btree_init_path(path);
ret = nilfs_btree_do_lookup(btree, path, key, NULL, ret = nilfs_btree_do_lookup(btree, path, key, NULL,
NILFS_BTREE_LEVEL_NODE_MIN); NILFS_BTREE_LEVEL_NODE_MIN);
if (ret < 0) if (ret < 0)
...@@ -1539,8 +1501,8 @@ static int nilfs_btree_delete(struct nilfs_bmap *bmap, __u64 key) ...@@ -1539,8 +1501,8 @@ static int nilfs_btree_delete(struct nilfs_bmap *bmap, __u64 key)
nilfs_bmap_sub_blocks(bmap, stats.bs_nblocks); nilfs_bmap_sub_blocks(bmap, stats.bs_nblocks);
out: out:
nilfs_btree_clear_path(btree, path); nilfs_btree_clear_path(path);
nilfs_btree_free_path(btree, path); nilfs_btree_free_path(path);
return ret; return ret;
} }
...@@ -1551,15 +1513,15 @@ static int nilfs_btree_last_key(const struct nilfs_bmap *bmap, __u64 *keyp) ...@@ -1551,15 +1513,15 @@ static int nilfs_btree_last_key(const struct nilfs_bmap *bmap, __u64 *keyp)
int ret; int ret;
btree = (struct nilfs_btree *)bmap; btree = (struct nilfs_btree *)bmap;
path = nilfs_btree_alloc_path(btree); path = nilfs_btree_alloc_path();
if (path == NULL) if (path == NULL)
return -ENOMEM; return -ENOMEM;
nilfs_btree_init_path(btree, path); nilfs_btree_init_path(path);
ret = nilfs_btree_do_lookup_last(btree, path, keyp, NULL); ret = nilfs_btree_do_lookup_last(btree, path, keyp, NULL);
nilfs_btree_clear_path(btree, path); nilfs_btree_clear_path(path);
nilfs_btree_free_path(btree, path); nilfs_btree_free_path(path);
return ret; return ret;
} }
...@@ -1581,7 +1543,7 @@ static int nilfs_btree_check_delete(struct nilfs_bmap *bmap, __u64 key) ...@@ -1581,7 +1543,7 @@ static int nilfs_btree_check_delete(struct nilfs_bmap *bmap, __u64 key)
node = root; node = root;
break; break;
case 3: case 3:
nchildren = nilfs_btree_node_get_nchildren(btree, root); nchildren = nilfs_btree_node_get_nchildren(root);
if (nchildren > 1) if (nchildren > 1)
return 0; return 0;
ptr = nilfs_btree_node_get_ptr(btree, root, nchildren - 1); ptr = nilfs_btree_node_get_ptr(btree, root, nchildren - 1);
...@@ -1594,10 +1556,10 @@ static int nilfs_btree_check_delete(struct nilfs_bmap *bmap, __u64 key) ...@@ -1594,10 +1556,10 @@ static int nilfs_btree_check_delete(struct nilfs_bmap *bmap, __u64 key)
return 0; return 0;
} }
nchildren = nilfs_btree_node_get_nchildren(btree, node); nchildren = nilfs_btree_node_get_nchildren(node);
maxkey = nilfs_btree_node_get_key(btree, node, nchildren - 1); maxkey = nilfs_btree_node_get_key(node, nchildren - 1);
nextmaxkey = (nchildren > 1) ? nextmaxkey = (nchildren > 1) ?
nilfs_btree_node_get_key(btree, node, nchildren - 2) : 0; nilfs_btree_node_get_key(node, nchildren - 2) : 0;
if (bh != NULL) if (bh != NULL)
brelse(bh); brelse(bh);
...@@ -1623,7 +1585,7 @@ static int nilfs_btree_gather_data(struct nilfs_bmap *bmap, ...@@ -1623,7 +1585,7 @@ static int nilfs_btree_gather_data(struct nilfs_bmap *bmap,
node = root; node = root;
break; break;
case 3: case 3:
nchildren = nilfs_btree_node_get_nchildren(btree, root); nchildren = nilfs_btree_node_get_nchildren(root);
WARN_ON(nchildren > 1); WARN_ON(nchildren > 1);
ptr = nilfs_btree_node_get_ptr(btree, root, nchildren - 1); ptr = nilfs_btree_node_get_ptr(btree, root, nchildren - 1);
ret = nilfs_btree_get_block(btree, ptr, &bh); ret = nilfs_btree_get_block(btree, ptr, &bh);
...@@ -1636,11 +1598,11 @@ static int nilfs_btree_gather_data(struct nilfs_bmap *bmap, ...@@ -1636,11 +1598,11 @@ static int nilfs_btree_gather_data(struct nilfs_bmap *bmap,
return -EINVAL; return -EINVAL;
} }
nchildren = nilfs_btree_node_get_nchildren(btree, node); nchildren = nilfs_btree_node_get_nchildren(node);
if (nchildren < nitems) if (nchildren < nitems)
nitems = nchildren; nitems = nchildren;
dkeys = nilfs_btree_node_dkeys(btree, node); dkeys = nilfs_btree_node_dkeys(node);
dptrs = nilfs_btree_node_dptrs(btree, node); dptrs = nilfs_btree_node_dptrs(node, btree);
for (i = 0; i < nitems; i++) { for (i = 0; i < nitems; i++) {
keys[i] = nilfs_bmap_dkey_to_key(dkeys[i]); keys[i] = nilfs_bmap_dkey_to_key(dkeys[i]);
ptrs[i] = nilfs_bmap_dptr_to_ptr(dptrs[i]); ptrs[i] = nilfs_bmap_dptr_to_ptr(dptrs[i]);
...@@ -1986,15 +1948,15 @@ static int nilfs_btree_propagate(const struct nilfs_bmap *bmap, ...@@ -1986,15 +1948,15 @@ static int nilfs_btree_propagate(const struct nilfs_bmap *bmap,
WARN_ON(!buffer_dirty(bh)); WARN_ON(!buffer_dirty(bh));
btree = (struct nilfs_btree *)bmap; btree = (struct nilfs_btree *)bmap;
path = nilfs_btree_alloc_path(btree); path = nilfs_btree_alloc_path();
if (path == NULL) if (path == NULL)
return -ENOMEM; return -ENOMEM;
nilfs_btree_init_path(btree, path); nilfs_btree_init_path(path);
if (buffer_nilfs_node(bh)) { if (buffer_nilfs_node(bh)) {
node = (struct nilfs_btree_node *)bh->b_data; node = (struct nilfs_btree_node *)bh->b_data;
key = nilfs_btree_node_get_key(btree, node, 0); key = nilfs_btree_node_get_key(node, 0);
level = nilfs_btree_node_get_level(btree, node); level = nilfs_btree_node_get_level(node);
} else { } else {
key = nilfs_bmap_data_get_key(bmap, bh); key = nilfs_bmap_data_get_key(bmap, bh);
level = NILFS_BTREE_LEVEL_DATA; level = NILFS_BTREE_LEVEL_DATA;
...@@ -2013,8 +1975,8 @@ static int nilfs_btree_propagate(const struct nilfs_bmap *bmap, ...@@ -2013,8 +1975,8 @@ static int nilfs_btree_propagate(const struct nilfs_bmap *bmap,
nilfs_btree_propagate_p(btree, path, level, bh); nilfs_btree_propagate_p(btree, path, level, bh);
out: out:
nilfs_btree_clear_path(btree, path); nilfs_btree_clear_path(path);
nilfs_btree_free_path(btree, path); nilfs_btree_free_path(path);
return ret; return ret;
} }
...@@ -2037,12 +1999,12 @@ static void nilfs_btree_add_dirty_buffer(struct nilfs_btree *btree, ...@@ -2037,12 +1999,12 @@ static void nilfs_btree_add_dirty_buffer(struct nilfs_btree *btree,
get_bh(bh); get_bh(bh);
node = (struct nilfs_btree_node *)bh->b_data; node = (struct nilfs_btree_node *)bh->b_data;
key = nilfs_btree_node_get_key(btree, node, 0); key = nilfs_btree_node_get_key(node, 0);
level = nilfs_btree_node_get_level(btree, node); level = nilfs_btree_node_get_level(node);
list_for_each(head, &lists[level]) { list_for_each(head, &lists[level]) {
cbh = list_entry(head, struct buffer_head, b_assoc_buffers); cbh = list_entry(head, struct buffer_head, b_assoc_buffers);
cnode = (struct nilfs_btree_node *)cbh->b_data; cnode = (struct nilfs_btree_node *)cbh->b_data;
ckey = nilfs_btree_node_get_key(btree, cnode, 0); ckey = nilfs_btree_node_get_key(cnode, 0);
if (key < ckey) if (key < ckey)
break; break;
} }
...@@ -2120,8 +2082,7 @@ static int nilfs_btree_assign_p(struct nilfs_btree *btree, ...@@ -2120,8 +2082,7 @@ static int nilfs_btree_assign_p(struct nilfs_btree *btree,
nilfs_btree_node_set_ptr(btree, parent, nilfs_btree_node_set_ptr(btree, parent,
path[level + 1].bp_index, blocknr); path[level + 1].bp_index, blocknr);
key = nilfs_btree_node_get_key(btree, parent, key = nilfs_btree_node_get_key(parent, path[level + 1].bp_index);
path[level + 1].bp_index);
/* on-disk format */ /* on-disk format */
binfo->bi_dat.bi_blkoff = nilfs_bmap_key_to_dkey(key); binfo->bi_dat.bi_blkoff = nilfs_bmap_key_to_dkey(key);
binfo->bi_dat.bi_level = level; binfo->bi_dat.bi_level = level;
...@@ -2150,8 +2111,7 @@ static int nilfs_btree_assign_v(struct nilfs_btree *btree, ...@@ -2150,8 +2111,7 @@ static int nilfs_btree_assign_v(struct nilfs_btree *btree,
if (unlikely(ret < 0)) if (unlikely(ret < 0))
return ret; return ret;
key = nilfs_btree_node_get_key(btree, parent, key = nilfs_btree_node_get_key(parent, path[level + 1].bp_index);
path[level + 1].bp_index);
/* on-disk format */ /* on-disk format */
binfo->bi_v.bi_vblocknr = nilfs_bmap_ptr_to_dptr(ptr); binfo->bi_v.bi_vblocknr = nilfs_bmap_ptr_to_dptr(ptr);
binfo->bi_v.bi_blkoff = nilfs_bmap_key_to_dkey(key); binfo->bi_v.bi_blkoff = nilfs_bmap_key_to_dkey(key);
...@@ -2171,15 +2131,15 @@ static int nilfs_btree_assign(struct nilfs_bmap *bmap, ...@@ -2171,15 +2131,15 @@ static int nilfs_btree_assign(struct nilfs_bmap *bmap,
int level, ret; int level, ret;
btree = (struct nilfs_btree *)bmap; btree = (struct nilfs_btree *)bmap;
path = nilfs_btree_alloc_path(btree); path = nilfs_btree_alloc_path();
if (path == NULL) if (path == NULL)
return -ENOMEM; return -ENOMEM;
nilfs_btree_init_path(btree, path); nilfs_btree_init_path(path);
if (buffer_nilfs_node(*bh)) { if (buffer_nilfs_node(*bh)) {
node = (struct nilfs_btree_node *)(*bh)->b_data; node = (struct nilfs_btree_node *)(*bh)->b_data;
key = nilfs_btree_node_get_key(btree, node, 0); key = nilfs_btree_node_get_key(node, 0);
level = nilfs_btree_node_get_level(btree, node); level = nilfs_btree_node_get_level(node);
} else { } else {
key = nilfs_bmap_data_get_key(bmap, *bh); key = nilfs_bmap_data_get_key(bmap, *bh);
level = NILFS_BTREE_LEVEL_DATA; level = NILFS_BTREE_LEVEL_DATA;
...@@ -2196,8 +2156,8 @@ static int nilfs_btree_assign(struct nilfs_bmap *bmap, ...@@ -2196,8 +2156,8 @@ static int nilfs_btree_assign(struct nilfs_bmap *bmap,
nilfs_btree_assign_p(btree, path, level, bh, blocknr, binfo); nilfs_btree_assign_p(btree, path, level, bh, blocknr, binfo);
out: out:
nilfs_btree_clear_path(btree, path); nilfs_btree_clear_path(path);
nilfs_btree_free_path(btree, path); nilfs_btree_free_path(path);
return ret; return ret;
} }
...@@ -2219,7 +2179,7 @@ static int nilfs_btree_assign_gc(struct nilfs_bmap *bmap, ...@@ -2219,7 +2179,7 @@ static int nilfs_btree_assign_gc(struct nilfs_bmap *bmap,
if (buffer_nilfs_node(*bh)) { if (buffer_nilfs_node(*bh)) {
node = (struct nilfs_btree_node *)(*bh)->b_data; node = (struct nilfs_btree_node *)(*bh)->b_data;
key = nilfs_btree_node_get_key(btree, node, 0); key = nilfs_btree_node_get_key(node, 0);
} else } else
key = nilfs_bmap_data_get_key(bmap, *bh); key = nilfs_bmap_data_get_key(bmap, *bh);
...@@ -2239,10 +2199,10 @@ static int nilfs_btree_mark(struct nilfs_bmap *bmap, __u64 key, int level) ...@@ -2239,10 +2199,10 @@ static int nilfs_btree_mark(struct nilfs_bmap *bmap, __u64 key, int level)
int ret; int ret;
btree = (struct nilfs_btree *)bmap; btree = (struct nilfs_btree *)bmap;
path = nilfs_btree_alloc_path(btree); path = nilfs_btree_alloc_path();
if (path == NULL) if (path == NULL)
return -ENOMEM; return -ENOMEM;
nilfs_btree_init_path(btree, path); nilfs_btree_init_path(path);
ret = nilfs_btree_do_lookup(btree, path, key, &ptr, level + 1); ret = nilfs_btree_do_lookup(btree, path, key, &ptr, level + 1);
if (ret < 0) { if (ret < 0) {
...@@ -2262,8 +2222,8 @@ static int nilfs_btree_mark(struct nilfs_bmap *bmap, __u64 key, int level) ...@@ -2262,8 +2222,8 @@ static int nilfs_btree_mark(struct nilfs_bmap *bmap, __u64 key, int level)
nilfs_bmap_set_dirty(&btree->bt_bmap); nilfs_bmap_set_dirty(&btree->bt_bmap);
out: out:
nilfs_btree_clear_path(btree, path); nilfs_btree_clear_path(path);
nilfs_btree_free_path(btree, path); nilfs_btree_free_path(path);
return ret; return ret;
} }
......
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