提交 f905440f 编写于 作者: L Li Hong 提交者: Ryusuke Konishi

nilfs2: Combine nilfs_btree_alloc_path() and nilfs_btree_init_path()

nilfs_btree_alloc_path() and nilfs_btree_init_path() are bound into each other
tightly. Make them into one procedure to clearify the logic and avoid some
misusages.
Signed-off-by: NLi Hong <lihong.hi@gmail.com>
Signed-off-by: NRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
上级 0d9cc233
...@@ -71,23 +71,16 @@ void nilfs_btree_path_cache_destroy(void) ...@@ -71,23 +71,16 @@ 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 *nilfs_btree_alloc_path(void) static struct nilfs_btree_path *nilfs_btree_alloc_path(void)
{ {
return kmem_cache_alloc(nilfs_btree_path_cache, GFP_NOFS); struct nilfs_btree_path *path;
} int level = NILFS_BTREE_LEVEL_DATA;
static inline void nilfs_btree_free_path(struct nilfs_btree_path *path)
{
kmem_cache_free(nilfs_btree_path_cache, path);
}
static void nilfs_btree_init_path(struct nilfs_btree_path *path) path = kmem_cache_alloc(nilfs_btree_path_cache, GFP_NOFS);
{ if (path == NULL)
int level; goto out;
for (level = NILFS_BTREE_LEVEL_DATA; for (; level < NILFS_BTREE_LEVEL_MAX; level++) {
level < NILFS_BTREE_LEVEL_MAX;
level++) {
path[level].bp_bh = NULL; path[level].bp_bh = NULL;
path[level].bp_sib_bh = NULL; path[level].bp_sib_bh = NULL;
path[level].bp_index = 0; path[level].bp_index = 0;
...@@ -95,6 +88,14 @@ static void nilfs_btree_init_path(struct nilfs_btree_path *path) ...@@ -95,6 +88,14 @@ static void nilfs_btree_init_path(struct nilfs_btree_path *path)
path[level].bp_newreq.bpr_ptr = NILFS_BMAP_INVALID_PTR; path[level].bp_newreq.bpr_ptr = NILFS_BMAP_INVALID_PTR;
path[level].bp_op = NULL; path[level].bp_op = NULL;
} }
out:
return path;
}
static inline void nilfs_btree_free_path(struct nilfs_btree_path *path)
{
kmem_cache_free(nilfs_btree_path_cache, path);
} }
static void nilfs_btree_release_path(struct nilfs_btree_path *path) static void nilfs_btree_release_path(struct nilfs_btree_path *path)
...@@ -566,7 +567,6 @@ static int nilfs_btree_lookup(const struct nilfs_bmap *bmap, ...@@ -566,7 +567,6 @@ static int nilfs_btree_lookup(const struct nilfs_bmap *bmap,
path = nilfs_btree_alloc_path(); path = nilfs_btree_alloc_path();
if (path == NULL) if (path == NULL)
return -ENOMEM; return -ENOMEM;
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);
...@@ -594,7 +594,7 @@ static int nilfs_btree_lookup_contig(const struct nilfs_bmap *bmap, ...@@ -594,7 +594,7 @@ static int nilfs_btree_lookup_contig(const struct nilfs_bmap *bmap,
path = nilfs_btree_alloc_path(); path = nilfs_btree_alloc_path();
if (path == NULL) if (path == NULL)
return -ENOMEM; return -ENOMEM;
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;
...@@ -1123,7 +1123,6 @@ static int nilfs_btree_insert(struct nilfs_bmap *bmap, __u64 key, __u64 ptr) ...@@ -1123,7 +1123,6 @@ static int nilfs_btree_insert(struct nilfs_bmap *bmap, __u64 key, __u64 ptr)
path = nilfs_btree_alloc_path(); path = nilfs_btree_alloc_path();
if (path == NULL) if (path == NULL)
return -ENOMEM; return -ENOMEM;
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);
...@@ -1456,7 +1455,7 @@ static int nilfs_btree_delete(struct nilfs_bmap *bmap, __u64 key) ...@@ -1456,7 +1455,7 @@ static int nilfs_btree_delete(struct nilfs_bmap *bmap, __u64 key)
path = nilfs_btree_alloc_path(); path = nilfs_btree_alloc_path();
if (path == NULL) if (path == NULL)
return -ENOMEM; return -ENOMEM;
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)
...@@ -1488,7 +1487,6 @@ static int nilfs_btree_last_key(const struct nilfs_bmap *bmap, __u64 *keyp) ...@@ -1488,7 +1487,6 @@ static int nilfs_btree_last_key(const struct nilfs_bmap *bmap, __u64 *keyp)
path = nilfs_btree_alloc_path(); path = nilfs_btree_alloc_path();
if (path == NULL) if (path == NULL)
return -ENOMEM; return -ENOMEM;
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);
...@@ -1923,7 +1921,6 @@ static int nilfs_btree_propagate(const struct nilfs_bmap *bmap, ...@@ -1923,7 +1921,6 @@ static int nilfs_btree_propagate(const struct nilfs_bmap *bmap,
path = nilfs_btree_alloc_path(); path = nilfs_btree_alloc_path();
if (path == NULL) if (path == NULL)
return -ENOMEM; return -ENOMEM;
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;
...@@ -2108,7 +2105,6 @@ static int nilfs_btree_assign(struct nilfs_bmap *bmap, ...@@ -2108,7 +2105,6 @@ static int nilfs_btree_assign(struct nilfs_bmap *bmap,
path = nilfs_btree_alloc_path(); path = nilfs_btree_alloc_path();
if (path == NULL) if (path == NULL)
return -ENOMEM; return -ENOMEM;
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;
...@@ -2175,7 +2171,6 @@ static int nilfs_btree_mark(struct nilfs_bmap *bmap, __u64 key, int level) ...@@ -2175,7 +2171,6 @@ static int nilfs_btree_mark(struct nilfs_bmap *bmap, __u64 key, int level)
path = nilfs_btree_alloc_path(); path = nilfs_btree_alloc_path();
if (path == NULL) if (path == NULL)
return -ENOMEM; return -ENOMEM;
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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册