aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nilfs2/btree.c
diff options
context:
space:
mode:
authorLi Hong <lihong.hi@gmail.com>2010-04-02 05:36:34 -0400
committerRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>2010-05-09 22:32:29 -0400
commitf905440f5edfa70a07e64bdbc973cbdd55dd001d (patch)
tree83f27e8f4ebd473c00e758bb0a52a4949b342a9a /fs/nilfs2/btree.c
parent0d9cc2332df24d3e81060c782b2ecb87c28443f9 (diff)
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: Li Hong <lihong.hi@gmail.com> Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Diffstat (limited to 'fs/nilfs2/btree.c')
-rw-r--r--fs/nilfs2/btree.c39
1 files changed, 17 insertions, 22 deletions
diff --git a/fs/nilfs2/btree.c b/fs/nilfs2/btree.c
index 76c38e3e19d2..f47984987465 100644
--- a/fs/nilfs2/btree.c
+++ b/fs/nilfs2/btree.c
@@ -71,23 +71,16 @@ void nilfs_btree_path_cache_destroy(void)
71 kmem_cache_destroy(nilfs_btree_path_cache); 71 kmem_cache_destroy(nilfs_btree_path_cache);
72} 72}
73 73
74static inline struct nilfs_btree_path *nilfs_btree_alloc_path(void) 74static struct nilfs_btree_path *nilfs_btree_alloc_path(void)
75{ 75{
76 return kmem_cache_alloc(nilfs_btree_path_cache, GFP_NOFS); 76 struct nilfs_btree_path *path;
77} 77 int level = NILFS_BTREE_LEVEL_DATA;
78
79static inline void nilfs_btree_free_path(struct nilfs_btree_path *path)
80{
81 kmem_cache_free(nilfs_btree_path_cache, path);
82}
83 78
84static void nilfs_btree_init_path(struct nilfs_btree_path *path) 79 path = kmem_cache_alloc(nilfs_btree_path_cache, GFP_NOFS);
85{ 80 if (path == NULL)
86 int level; 81 goto out;
87 82
88 for (level = NILFS_BTREE_LEVEL_DATA; 83 for (; level < NILFS_BTREE_LEVEL_MAX; level++) {
89 level < NILFS_BTREE_LEVEL_MAX;
90 level++) {
91 path[level].bp_bh = NULL; 84 path[level].bp_bh = NULL;
92 path[level].bp_sib_bh = NULL; 85 path[level].bp_sib_bh = NULL;
93 path[level].bp_index = 0; 86 path[level].bp_index = 0;
@@ -95,6 +88,14 @@ static void nilfs_btree_init_path(struct nilfs_btree_path *path)
95 path[level].bp_newreq.bpr_ptr = NILFS_BMAP_INVALID_PTR; 88 path[level].bp_newreq.bpr_ptr = NILFS_BMAP_INVALID_PTR;
96 path[level].bp_op = NULL; 89 path[level].bp_op = NULL;
97 } 90 }
91
92out:
93 return path;
94}
95
96static inline void nilfs_btree_free_path(struct nilfs_btree_path *path)
97{
98 kmem_cache_free(nilfs_btree_path_cache, path);
98} 99}
99 100
100static void nilfs_btree_release_path(struct nilfs_btree_path *path) 101static 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 path = nilfs_btree_alloc_path(); 567 path = nilfs_btree_alloc_path();
567 if (path == NULL) 568 if (path == NULL)
568 return -ENOMEM; 569 return -ENOMEM;
569 nilfs_btree_init_path(path);
570 570
571 ret = nilfs_btree_do_lookup(btree, path, key, &ptr, level); 571 ret = nilfs_btree_do_lookup(btree, path, key, &ptr, level);
572 572
@@ -594,7 +594,7 @@ static int nilfs_btree_lookup_contig(const struct nilfs_bmap *bmap,
594 path = nilfs_btree_alloc_path(); 594 path = nilfs_btree_alloc_path();
595 if (path == NULL) 595 if (path == NULL)
596 return -ENOMEM; 596 return -ENOMEM;
597 nilfs_btree_init_path(path); 597
598 ret = nilfs_btree_do_lookup(btree, path, key, &ptr, level); 598 ret = nilfs_btree_do_lookup(btree, path, key, &ptr, level);
599 if (ret < 0) 599 if (ret < 0)
600 goto out; 600 goto out;
@@ -1123,7 +1123,6 @@ static int nilfs_btree_insert(struct nilfs_bmap *bmap, __u64 key, __u64 ptr)
1123 path = nilfs_btree_alloc_path(); 1123 path = nilfs_btree_alloc_path();
1124 if (path == NULL) 1124 if (path == NULL)
1125 return -ENOMEM; 1125 return -ENOMEM;
1126 nilfs_btree_init_path(path);
1127 1126
1128 ret = nilfs_btree_do_lookup(btree, path, key, NULL, 1127 ret = nilfs_btree_do_lookup(btree, path, key, NULL,
1129 NILFS_BTREE_LEVEL_NODE_MIN); 1128 NILFS_BTREE_LEVEL_NODE_MIN);
@@ -1456,7 +1455,7 @@ static int nilfs_btree_delete(struct nilfs_bmap *bmap, __u64 key)
1456 path = nilfs_btree_alloc_path(); 1455 path = nilfs_btree_alloc_path();
1457 if (path == NULL) 1456 if (path == NULL)
1458 return -ENOMEM; 1457 return -ENOMEM;
1459 nilfs_btree_init_path(path); 1458
1460 ret = nilfs_btree_do_lookup(btree, path, key, NULL, 1459 ret = nilfs_btree_do_lookup(btree, path, key, NULL,
1461 NILFS_BTREE_LEVEL_NODE_MIN); 1460 NILFS_BTREE_LEVEL_NODE_MIN);
1462 if (ret < 0) 1461 if (ret < 0)
@@ -1488,7 +1487,6 @@ static int nilfs_btree_last_key(const struct nilfs_bmap *bmap, __u64 *keyp)
1488 path = nilfs_btree_alloc_path(); 1487 path = nilfs_btree_alloc_path();
1489 if (path == NULL) 1488 if (path == NULL)
1490 return -ENOMEM; 1489 return -ENOMEM;
1491 nilfs_btree_init_path(path);
1492 1490
1493 ret = nilfs_btree_do_lookup_last(btree, path, keyp, NULL); 1491 ret = nilfs_btree_do_lookup_last(btree, path, keyp, NULL);
1494 1492
@@ -1923,7 +1921,6 @@ static int nilfs_btree_propagate(const struct nilfs_bmap *bmap,
1923 path = nilfs_btree_alloc_path(); 1921 path = nilfs_btree_alloc_path();
1924 if (path == NULL) 1922 if (path == NULL)
1925 return -ENOMEM; 1923 return -ENOMEM;
1926 nilfs_btree_init_path(path);
1927 1924
1928 if (buffer_nilfs_node(bh)) { 1925 if (buffer_nilfs_node(bh)) {
1929 node = (struct nilfs_btree_node *)bh->b_data; 1926 node = (struct nilfs_btree_node *)bh->b_data;
@@ -2108,7 +2105,6 @@ static int nilfs_btree_assign(struct nilfs_bmap *bmap,
2108 path = nilfs_btree_alloc_path(); 2105 path = nilfs_btree_alloc_path();
2109 if (path == NULL) 2106 if (path == NULL)
2110 return -ENOMEM; 2107 return -ENOMEM;
2111 nilfs_btree_init_path(path);
2112 2108
2113 if (buffer_nilfs_node(*bh)) { 2109 if (buffer_nilfs_node(*bh)) {
2114 node = (struct nilfs_btree_node *)(*bh)->b_data; 2110 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 path = nilfs_btree_alloc_path(); 2171 path = nilfs_btree_alloc_path();
2176 if (path == NULL) 2172 if (path == NULL)
2177 return -ENOMEM; 2173 return -ENOMEM;
2178 nilfs_btree_init_path(path);
2179 2174
2180 ret = nilfs_btree_do_lookup(btree, path, key, &ptr, level + 1); 2175 ret = nilfs_btree_do_lookup(btree, path, key, &ptr, level + 1);
2181 if (ret < 0) { 2176 if (ret < 0) {