diff options
author | Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> | 2010-07-10 06:09:49 -0400 |
---|---|---|
committer | Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> | 2010-07-22 21:02:13 -0400 |
commit | e7c274f8083793f8f861def63c02a0839b34d26d (patch) | |
tree | a03bfd25a6b2736a0fec40c9282bb235691ccc0c /fs/nilfs2/btree.c | |
parent | 10ff885ba6f56bf7480ce3b5daf38c07600ecea3 (diff) |
nilfs2: get rid of nilfs_btree uses
This replaces all uses of nilfs_btree struct in implementation of
btree mapping with nilfs_bmap struct.
Name of local variable "btree" is kept not to bloat amount of change.
And, a part of local variables "bmap" is renamed to "btree" to uniform
naming rule.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Diffstat (limited to 'fs/nilfs2/btree.c')
-rw-r--r-- | fs/nilfs2/btree.c | 316 |
1 files changed, 140 insertions, 176 deletions
diff --git a/fs/nilfs2/btree.c b/fs/nilfs2/btree.c index a2dc36cb6ef7..81e871645b5f 100644 --- a/fs/nilfs2/btree.c +++ b/fs/nilfs2/btree.c | |||
@@ -66,11 +66,10 @@ static void nilfs_btree_free_path(struct nilfs_btree_path *path) | |||
66 | /* | 66 | /* |
67 | * B-tree node operations | 67 | * B-tree node operations |
68 | */ | 68 | */ |
69 | static int nilfs_btree_get_block(const struct nilfs_btree *btree, __u64 ptr, | 69 | static int nilfs_btree_get_block(const struct nilfs_bmap *btree, __u64 ptr, |
70 | struct buffer_head **bhp) | 70 | struct buffer_head **bhp) |
71 | { | 71 | { |
72 | struct address_space *btnc = | 72 | struct address_space *btnc = &NILFS_BMAP_I(btree)->i_btnode_cache; |
73 | &NILFS_BMAP_I((struct nilfs_bmap *)btree)->i_btnode_cache; | ||
74 | struct buffer_head *bh; | 73 | struct buffer_head *bh; |
75 | int err; | 74 | int err; |
76 | 75 | ||
@@ -92,11 +91,10 @@ static int nilfs_btree_get_block(const struct nilfs_btree *btree, __u64 ptr, | |||
92 | return 0; | 91 | return 0; |
93 | } | 92 | } |
94 | 93 | ||
95 | static int nilfs_btree_get_new_block(const struct nilfs_btree *btree, | 94 | static int nilfs_btree_get_new_block(const struct nilfs_bmap *btree, |
96 | __u64 ptr, struct buffer_head **bhp) | 95 | __u64 ptr, struct buffer_head **bhp) |
97 | { | 96 | { |
98 | struct address_space *btnc = | 97 | struct address_space *btnc = &NILFS_BMAP_I(btree)->i_btnode_cache; |
99 | &NILFS_BMAP_I((struct nilfs_bmap *)btree)->i_btnode_cache; | ||
100 | struct buffer_head *bh; | 98 | struct buffer_head *bh; |
101 | 99 | ||
102 | bh = nilfs_btnode_create_block(btnc, ptr); | 100 | bh = nilfs_btnode_create_block(btnc, ptr); |
@@ -149,14 +147,14 @@ nilfs_btree_node_set_nchildren(struct nilfs_btree_node *node, int nchildren) | |||
149 | node->bn_nchildren = cpu_to_le16(nchildren); | 147 | node->bn_nchildren = cpu_to_le16(nchildren); |
150 | } | 148 | } |
151 | 149 | ||
152 | static inline int nilfs_btree_node_size(const struct nilfs_btree *btree) | 150 | static inline int nilfs_btree_node_size(const struct nilfs_bmap *btree) |
153 | { | 151 | { |
154 | return 1 << btree->bt_bmap.b_inode->i_blkbits; | 152 | return 1 << btree->b_inode->i_blkbits; |
155 | } | 153 | } |
156 | 154 | ||
157 | static inline int | 155 | static inline int |
158 | nilfs_btree_node_nchildren_min(const struct nilfs_btree_node *node, | 156 | nilfs_btree_node_nchildren_min(const struct nilfs_btree_node *node, |
159 | const struct nilfs_btree *btree) | 157 | const struct nilfs_bmap *btree) |
160 | { | 158 | { |
161 | return nilfs_btree_node_root(node) ? | 159 | return nilfs_btree_node_root(node) ? |
162 | NILFS_BTREE_ROOT_NCHILDREN_MIN : | 160 | NILFS_BTREE_ROOT_NCHILDREN_MIN : |
@@ -165,7 +163,7 @@ nilfs_btree_node_nchildren_min(const struct nilfs_btree_node *node, | |||
165 | 163 | ||
166 | static inline int | 164 | static inline int |
167 | nilfs_btree_node_nchildren_max(const struct nilfs_btree_node *node, | 165 | nilfs_btree_node_nchildren_max(const struct nilfs_btree_node *node, |
168 | const struct nilfs_btree *btree) | 166 | const struct nilfs_bmap *btree) |
169 | { | 167 | { |
170 | return nilfs_btree_node_root(node) ? | 168 | return nilfs_btree_node_root(node) ? |
171 | NILFS_BTREE_ROOT_NCHILDREN_MAX : | 169 | NILFS_BTREE_ROOT_NCHILDREN_MAX : |
@@ -182,7 +180,7 @@ nilfs_btree_node_dkeys(const struct nilfs_btree_node *node) | |||
182 | 180 | ||
183 | static inline __le64 * | 181 | static inline __le64 * |
184 | nilfs_btree_node_dptrs(const struct nilfs_btree_node *node, | 182 | nilfs_btree_node_dptrs(const struct nilfs_btree_node *node, |
185 | const struct nilfs_btree *btree) | 183 | const struct nilfs_bmap *btree) |
186 | { | 184 | { |
187 | return (__le64 *)(nilfs_btree_node_dkeys(node) + | 185 | return (__le64 *)(nilfs_btree_node_dkeys(node) + |
188 | nilfs_btree_node_nchildren_max(node, btree)); | 186 | nilfs_btree_node_nchildren_max(node, btree)); |
@@ -201,20 +199,20 @@ nilfs_btree_node_set_key(struct nilfs_btree_node *node, int index, __u64 key) | |||
201 | } | 199 | } |
202 | 200 | ||
203 | static inline __u64 | 201 | static inline __u64 |
204 | nilfs_btree_node_get_ptr(const struct nilfs_btree *btree, | 202 | nilfs_btree_node_get_ptr(const struct nilfs_bmap *btree, |
205 | const struct nilfs_btree_node *node, int index) | 203 | const struct nilfs_btree_node *node, int index) |
206 | { | 204 | { |
207 | return le64_to_cpu(*(nilfs_btree_node_dptrs(node, btree) + index)); | 205 | return le64_to_cpu(*(nilfs_btree_node_dptrs(node, btree) + index)); |
208 | } | 206 | } |
209 | 207 | ||
210 | static inline void | 208 | static inline void |
211 | nilfs_btree_node_set_ptr(struct nilfs_btree *btree, | 209 | nilfs_btree_node_set_ptr(struct nilfs_bmap *btree, |
212 | struct nilfs_btree_node *node, int index, __u64 ptr) | 210 | struct nilfs_btree_node *node, int index, __u64 ptr) |
213 | { | 211 | { |
214 | *(nilfs_btree_node_dptrs(node, btree) + index) = cpu_to_le64(ptr); | 212 | *(nilfs_btree_node_dptrs(node, btree) + index) = cpu_to_le64(ptr); |
215 | } | 213 | } |
216 | 214 | ||
217 | static void nilfs_btree_node_init(struct nilfs_btree *btree, | 215 | static void nilfs_btree_node_init(struct nilfs_bmap *btree, |
218 | struct nilfs_btree_node *node, | 216 | struct nilfs_btree_node *node, |
219 | int flags, int level, int nchildren, | 217 | int flags, int level, int nchildren, |
220 | const __u64 *keys, const __u64 *ptrs) | 218 | const __u64 *keys, const __u64 *ptrs) |
@@ -236,7 +234,7 @@ static void nilfs_btree_node_init(struct nilfs_btree *btree, | |||
236 | } | 234 | } |
237 | 235 | ||
238 | /* Assume the buffer heads corresponding to left and right are locked. */ | 236 | /* Assume the buffer heads corresponding to left and right are locked. */ |
239 | static void nilfs_btree_node_move_left(struct nilfs_btree *btree, | 237 | static void nilfs_btree_node_move_left(struct nilfs_bmap *btree, |
240 | struct nilfs_btree_node *left, | 238 | struct nilfs_btree_node *left, |
241 | struct nilfs_btree_node *right, | 239 | struct nilfs_btree_node *right, |
242 | int n) | 240 | int n) |
@@ -265,7 +263,7 @@ static void nilfs_btree_node_move_left(struct nilfs_btree *btree, | |||
265 | } | 263 | } |
266 | 264 | ||
267 | /* Assume that the buffer heads corresponding to left and right are locked. */ | 265 | /* Assume that the buffer heads corresponding to left and right are locked. */ |
268 | static void nilfs_btree_node_move_right(struct nilfs_btree *btree, | 266 | static void nilfs_btree_node_move_right(struct nilfs_bmap *btree, |
269 | struct nilfs_btree_node *left, | 267 | struct nilfs_btree_node *left, |
270 | struct nilfs_btree_node *right, | 268 | struct nilfs_btree_node *right, |
271 | int n) | 269 | int n) |
@@ -294,7 +292,7 @@ static void nilfs_btree_node_move_right(struct nilfs_btree *btree, | |||
294 | } | 292 | } |
295 | 293 | ||
296 | /* Assume that the buffer head corresponding to node is locked. */ | 294 | /* Assume that the buffer head corresponding to node is locked. */ |
297 | static void nilfs_btree_node_insert(struct nilfs_btree *btree, | 295 | static void nilfs_btree_node_insert(struct nilfs_bmap *btree, |
298 | struct nilfs_btree_node *node, | 296 | struct nilfs_btree_node *node, |
299 | __u64 key, __u64 ptr, int index) | 297 | __u64 key, __u64 ptr, int index) |
300 | { | 298 | { |
@@ -318,7 +316,7 @@ static void nilfs_btree_node_insert(struct nilfs_btree *btree, | |||
318 | } | 316 | } |
319 | 317 | ||
320 | /* Assume that the buffer head corresponding to node is locked. */ | 318 | /* Assume that the buffer head corresponding to node is locked. */ |
321 | static void nilfs_btree_node_delete(struct nilfs_btree *btree, | 319 | static void nilfs_btree_node_delete(struct nilfs_bmap *btree, |
322 | struct nilfs_btree_node *node, | 320 | struct nilfs_btree_node *node, |
323 | __u64 *keyp, __u64 *ptrp, int index) | 321 | __u64 *keyp, __u64 *ptrp, int index) |
324 | { | 322 | { |
@@ -425,9 +423,9 @@ int nilfs_btree_broken_node_block(struct buffer_head *bh) | |||
425 | } | 423 | } |
426 | 424 | ||
427 | static inline struct nilfs_btree_node * | 425 | static inline struct nilfs_btree_node * |
428 | nilfs_btree_get_root(const struct nilfs_btree *btree) | 426 | nilfs_btree_get_root(const struct nilfs_bmap *btree) |
429 | { | 427 | { |
430 | return (struct nilfs_btree_node *)btree->bt_bmap.b_u.u_data; | 428 | return (struct nilfs_btree_node *)btree->b_u.u_data; |
431 | } | 429 | } |
432 | 430 | ||
433 | static inline struct nilfs_btree_node * | 431 | static inline struct nilfs_btree_node * |
@@ -442,13 +440,13 @@ nilfs_btree_get_sib_node(const struct nilfs_btree_path *path, int level) | |||
442 | return (struct nilfs_btree_node *)path[level].bp_sib_bh->b_data; | 440 | return (struct nilfs_btree_node *)path[level].bp_sib_bh->b_data; |
443 | } | 441 | } |
444 | 442 | ||
445 | static inline int nilfs_btree_height(const struct nilfs_btree *btree) | 443 | static inline int nilfs_btree_height(const struct nilfs_bmap *btree) |
446 | { | 444 | { |
447 | return nilfs_btree_node_get_level(nilfs_btree_get_root(btree)) + 1; | 445 | return nilfs_btree_node_get_level(nilfs_btree_get_root(btree)) + 1; |
448 | } | 446 | } |
449 | 447 | ||
450 | static inline struct nilfs_btree_node * | 448 | static inline struct nilfs_btree_node * |
451 | nilfs_btree_get_node(const struct nilfs_btree *btree, | 449 | nilfs_btree_get_node(const struct nilfs_bmap *btree, |
452 | const struct nilfs_btree_path *path, | 450 | const struct nilfs_btree_path *path, |
453 | int level) | 451 | int level) |
454 | { | 452 | { |
@@ -469,7 +467,7 @@ nilfs_btree_bad_node(struct nilfs_btree_node *node, int level) | |||
469 | return 0; | 467 | return 0; |
470 | } | 468 | } |
471 | 469 | ||
472 | static int nilfs_btree_do_lookup(const struct nilfs_btree *btree, | 470 | static int nilfs_btree_do_lookup(const struct nilfs_bmap *btree, |
473 | struct nilfs_btree_path *path, | 471 | struct nilfs_btree_path *path, |
474 | __u64 key, __u64 *ptrp, int minlevel) | 472 | __u64 key, __u64 *ptrp, int minlevel) |
475 | { | 473 | { |
@@ -516,7 +514,7 @@ static int nilfs_btree_do_lookup(const struct nilfs_btree *btree, | |||
516 | return 0; | 514 | return 0; |
517 | } | 515 | } |
518 | 516 | ||
519 | static int nilfs_btree_do_lookup_last(const struct nilfs_btree *btree, | 517 | static int nilfs_btree_do_lookup_last(const struct nilfs_bmap *btree, |
520 | struct nilfs_btree_path *path, | 518 | struct nilfs_btree_path *path, |
521 | __u64 *keyp, __u64 *ptrp) | 519 | __u64 *keyp, __u64 *ptrp) |
522 | { | 520 | { |
@@ -553,15 +551,13 @@ static int nilfs_btree_do_lookup_last(const struct nilfs_btree *btree, | |||
553 | return 0; | 551 | return 0; |
554 | } | 552 | } |
555 | 553 | ||
556 | static int nilfs_btree_lookup(const struct nilfs_bmap *bmap, | 554 | static int nilfs_btree_lookup(const struct nilfs_bmap *btree, |
557 | __u64 key, int level, __u64 *ptrp) | 555 | __u64 key, int level, __u64 *ptrp) |
558 | { | 556 | { |
559 | struct nilfs_btree *btree; | ||
560 | struct nilfs_btree_path *path; | 557 | struct nilfs_btree_path *path; |
561 | __u64 ptr; | 558 | __u64 ptr; |
562 | int ret; | 559 | int ret; |
563 | 560 | ||
564 | btree = (struct nilfs_btree *)bmap; | ||
565 | path = nilfs_btree_alloc_path(); | 561 | path = nilfs_btree_alloc_path(); |
566 | if (path == NULL) | 562 | if (path == NULL) |
567 | return -ENOMEM; | 563 | return -ENOMEM; |
@@ -576,10 +572,9 @@ static int nilfs_btree_lookup(const struct nilfs_bmap *bmap, | |||
576 | return ret; | 572 | return ret; |
577 | } | 573 | } |
578 | 574 | ||
579 | static int nilfs_btree_lookup_contig(const struct nilfs_bmap *bmap, | 575 | static int nilfs_btree_lookup_contig(const struct nilfs_bmap *btree, |
580 | __u64 key, __u64 *ptrp, unsigned maxblocks) | 576 | __u64 key, __u64 *ptrp, unsigned maxblocks) |
581 | { | 577 | { |
582 | struct nilfs_btree *btree = (struct nilfs_btree *)bmap; | ||
583 | struct nilfs_btree_path *path; | 578 | struct nilfs_btree_path *path; |
584 | struct nilfs_btree_node *node; | 579 | struct nilfs_btree_node *node; |
585 | struct inode *dat = NULL; | 580 | struct inode *dat = NULL; |
@@ -596,8 +591,8 @@ static int nilfs_btree_lookup_contig(const struct nilfs_bmap *bmap, | |||
596 | if (ret < 0) | 591 | if (ret < 0) |
597 | goto out; | 592 | goto out; |
598 | 593 | ||
599 | if (NILFS_BMAP_USE_VBN(bmap)) { | 594 | if (NILFS_BMAP_USE_VBN(btree)) { |
600 | dat = nilfs_bmap_get_dat(bmap); | 595 | dat = nilfs_bmap_get_dat(btree); |
601 | ret = nilfs_dat_translate(dat, ptr, &blocknr); | 596 | ret = nilfs_dat_translate(dat, ptr, &blocknr); |
602 | if (ret < 0) | 597 | if (ret < 0) |
603 | goto out; | 598 | goto out; |
@@ -656,7 +651,7 @@ static int nilfs_btree_lookup_contig(const struct nilfs_bmap *bmap, | |||
656 | return ret; | 651 | return ret; |
657 | } | 652 | } |
658 | 653 | ||
659 | static void nilfs_btree_promote_key(struct nilfs_btree *btree, | 654 | static void nilfs_btree_promote_key(struct nilfs_bmap *btree, |
660 | struct nilfs_btree_path *path, | 655 | struct nilfs_btree_path *path, |
661 | int level, __u64 key) | 656 | int level, __u64 key) |
662 | { | 657 | { |
@@ -678,7 +673,7 @@ static void nilfs_btree_promote_key(struct nilfs_btree *btree, | |||
678 | } | 673 | } |
679 | } | 674 | } |
680 | 675 | ||
681 | static void nilfs_btree_do_insert(struct nilfs_btree *btree, | 676 | static void nilfs_btree_do_insert(struct nilfs_bmap *btree, |
682 | struct nilfs_btree_path *path, | 677 | struct nilfs_btree_path *path, |
683 | int level, __u64 *keyp, __u64 *ptrp) | 678 | int level, __u64 *keyp, __u64 *ptrp) |
684 | { | 679 | { |
@@ -702,7 +697,7 @@ static void nilfs_btree_do_insert(struct nilfs_btree *btree, | |||
702 | } | 697 | } |
703 | } | 698 | } |
704 | 699 | ||
705 | static void nilfs_btree_carry_left(struct nilfs_btree *btree, | 700 | static void nilfs_btree_carry_left(struct nilfs_bmap *btree, |
706 | struct nilfs_btree_path *path, | 701 | struct nilfs_btree_path *path, |
707 | int level, __u64 *keyp, __u64 *ptrp) | 702 | int level, __u64 *keyp, __u64 *ptrp) |
708 | { | 703 | { |
@@ -747,7 +742,7 @@ static void nilfs_btree_carry_left(struct nilfs_btree *btree, | |||
747 | nilfs_btree_do_insert(btree, path, level, keyp, ptrp); | 742 | nilfs_btree_do_insert(btree, path, level, keyp, ptrp); |
748 | } | 743 | } |
749 | 744 | ||
750 | static void nilfs_btree_carry_right(struct nilfs_btree *btree, | 745 | static void nilfs_btree_carry_right(struct nilfs_bmap *btree, |
751 | struct nilfs_btree_path *path, | 746 | struct nilfs_btree_path *path, |
752 | int level, __u64 *keyp, __u64 *ptrp) | 747 | int level, __u64 *keyp, __u64 *ptrp) |
753 | { | 748 | { |
@@ -793,7 +788,7 @@ static void nilfs_btree_carry_right(struct nilfs_btree *btree, | |||
793 | nilfs_btree_do_insert(btree, path, level, keyp, ptrp); | 788 | nilfs_btree_do_insert(btree, path, level, keyp, ptrp); |
794 | } | 789 | } |
795 | 790 | ||
796 | static void nilfs_btree_split(struct nilfs_btree *btree, | 791 | static void nilfs_btree_split(struct nilfs_bmap *btree, |
797 | struct nilfs_btree_path *path, | 792 | struct nilfs_btree_path *path, |
798 | int level, __u64 *keyp, __u64 *ptrp) | 793 | int level, __u64 *keyp, __u64 *ptrp) |
799 | { | 794 | { |
@@ -847,7 +842,7 @@ static void nilfs_btree_split(struct nilfs_btree *btree, | |||
847 | path[level + 1].bp_index++; | 842 | path[level + 1].bp_index++; |
848 | } | 843 | } |
849 | 844 | ||
850 | static void nilfs_btree_grow(struct nilfs_btree *btree, | 845 | static void nilfs_btree_grow(struct nilfs_bmap *btree, |
851 | struct nilfs_btree_path *path, | 846 | struct nilfs_btree_path *path, |
852 | int level, __u64 *keyp, __u64 *ptrp) | 847 | int level, __u64 *keyp, __u64 *ptrp) |
853 | { | 848 | { |
@@ -874,7 +869,7 @@ static void nilfs_btree_grow(struct nilfs_btree *btree, | |||
874 | *ptrp = path[level].bp_newreq.bpr_ptr; | 869 | *ptrp = path[level].bp_newreq.bpr_ptr; |
875 | } | 870 | } |
876 | 871 | ||
877 | static __u64 nilfs_btree_find_near(const struct nilfs_btree *btree, | 872 | static __u64 nilfs_btree_find_near(const struct nilfs_bmap *btree, |
878 | const struct nilfs_btree_path *path) | 873 | const struct nilfs_btree_path *path) |
879 | { | 874 | { |
880 | struct nilfs_btree_node *node; | 875 | struct nilfs_btree_node *node; |
@@ -902,13 +897,13 @@ static __u64 nilfs_btree_find_near(const struct nilfs_btree *btree, | |||
902 | return NILFS_BMAP_INVALID_PTR; | 897 | return NILFS_BMAP_INVALID_PTR; |
903 | } | 898 | } |
904 | 899 | ||
905 | static __u64 nilfs_btree_find_target_v(const struct nilfs_btree *btree, | 900 | static __u64 nilfs_btree_find_target_v(const struct nilfs_bmap *btree, |
906 | const struct nilfs_btree_path *path, | 901 | const struct nilfs_btree_path *path, |
907 | __u64 key) | 902 | __u64 key) |
908 | { | 903 | { |
909 | __u64 ptr; | 904 | __u64 ptr; |
910 | 905 | ||
911 | ptr = nilfs_bmap_find_target_seq(&btree->bt_bmap, key); | 906 | ptr = nilfs_bmap_find_target_seq(btree, key); |
912 | if (ptr != NILFS_BMAP_INVALID_PTR) | 907 | if (ptr != NILFS_BMAP_INVALID_PTR) |
913 | /* sequential access */ | 908 | /* sequential access */ |
914 | return ptr; | 909 | return ptr; |
@@ -919,17 +914,17 @@ static __u64 nilfs_btree_find_target_v(const struct nilfs_btree *btree, | |||
919 | return ptr; | 914 | return ptr; |
920 | } | 915 | } |
921 | /* block group */ | 916 | /* block group */ |
922 | return nilfs_bmap_find_target_in_group(&btree->bt_bmap); | 917 | return nilfs_bmap_find_target_in_group(btree); |
923 | } | 918 | } |
924 | 919 | ||
925 | static void nilfs_btree_set_target_v(struct nilfs_btree *btree, __u64 key, | 920 | static void nilfs_btree_set_target_v(struct nilfs_bmap *btree, __u64 key, |
926 | __u64 ptr) | 921 | __u64 ptr) |
927 | { | 922 | { |
928 | btree->bt_bmap.b_last_allocated_key = key; | 923 | btree->b_last_allocated_key = key; |
929 | btree->bt_bmap.b_last_allocated_ptr = ptr; | 924 | btree->b_last_allocated_ptr = ptr; |
930 | } | 925 | } |
931 | 926 | ||
932 | static int nilfs_btree_prepare_insert(struct nilfs_btree *btree, | 927 | static int nilfs_btree_prepare_insert(struct nilfs_bmap *btree, |
933 | struct nilfs_btree_path *path, | 928 | struct nilfs_btree_path *path, |
934 | int *levelp, __u64 key, __u64 ptr, | 929 | int *levelp, __u64 key, __u64 ptr, |
935 | struct nilfs_bmap_stats *stats) | 930 | struct nilfs_bmap_stats *stats) |
@@ -944,14 +939,13 @@ static int nilfs_btree_prepare_insert(struct nilfs_btree *btree, | |||
944 | level = NILFS_BTREE_LEVEL_DATA; | 939 | level = NILFS_BTREE_LEVEL_DATA; |
945 | 940 | ||
946 | /* allocate a new ptr for data block */ | 941 | /* allocate a new ptr for data block */ |
947 | if (NILFS_BMAP_USE_VBN(&btree->bt_bmap)) { | 942 | if (NILFS_BMAP_USE_VBN(btree)) { |
948 | path[level].bp_newreq.bpr_ptr = | 943 | path[level].bp_newreq.bpr_ptr = |
949 | nilfs_btree_find_target_v(btree, path, key); | 944 | nilfs_btree_find_target_v(btree, path, key); |
950 | dat = nilfs_bmap_get_dat(&btree->bt_bmap); | 945 | dat = nilfs_bmap_get_dat(btree); |
951 | } | 946 | } |
952 | 947 | ||
953 | ret = nilfs_bmap_prepare_alloc_ptr(&btree->bt_bmap, | 948 | ret = nilfs_bmap_prepare_alloc_ptr(btree, &path[level].bp_newreq, dat); |
954 | &path[level].bp_newreq, dat); | ||
955 | if (ret < 0) | 949 | if (ret < 0) |
956 | goto err_out_data; | 950 | goto err_out_data; |
957 | 951 | ||
@@ -1009,7 +1003,7 @@ static int nilfs_btree_prepare_insert(struct nilfs_btree *btree, | |||
1009 | /* split */ | 1003 | /* split */ |
1010 | path[level].bp_newreq.bpr_ptr = | 1004 | path[level].bp_newreq.bpr_ptr = |
1011 | path[level - 1].bp_newreq.bpr_ptr + 1; | 1005 | path[level - 1].bp_newreq.bpr_ptr + 1; |
1012 | ret = nilfs_bmap_prepare_alloc_ptr(&btree->bt_bmap, | 1006 | ret = nilfs_bmap_prepare_alloc_ptr(btree, |
1013 | &path[level].bp_newreq, dat); | 1007 | &path[level].bp_newreq, dat); |
1014 | if (ret < 0) | 1008 | if (ret < 0) |
1015 | goto err_out_child_node; | 1009 | goto err_out_child_node; |
@@ -1039,8 +1033,7 @@ static int nilfs_btree_prepare_insert(struct nilfs_btree *btree, | |||
1039 | 1033 | ||
1040 | /* grow */ | 1034 | /* grow */ |
1041 | path[level].bp_newreq.bpr_ptr = path[level - 1].bp_newreq.bpr_ptr + 1; | 1035 | path[level].bp_newreq.bpr_ptr = path[level - 1].bp_newreq.bpr_ptr + 1; |
1042 | ret = nilfs_bmap_prepare_alloc_ptr(&btree->bt_bmap, | 1036 | ret = nilfs_bmap_prepare_alloc_ptr(btree, &path[level].bp_newreq, dat); |
1043 | &path[level].bp_newreq, dat); | ||
1044 | if (ret < 0) | 1037 | if (ret < 0) |
1045 | goto err_out_child_node; | 1038 | goto err_out_child_node; |
1046 | ret = nilfs_btree_get_new_block(btree, path[level].bp_newreq.bpr_ptr, | 1039 | ret = nilfs_btree_get_new_block(btree, path[level].bp_newreq.bpr_ptr, |
@@ -1066,25 +1059,22 @@ static int nilfs_btree_prepare_insert(struct nilfs_btree *btree, | |||
1066 | 1059 | ||
1067 | /* error */ | 1060 | /* error */ |
1068 | err_out_curr_node: | 1061 | err_out_curr_node: |
1069 | nilfs_bmap_abort_alloc_ptr(&btree->bt_bmap, &path[level].bp_newreq, | 1062 | nilfs_bmap_abort_alloc_ptr(btree, &path[level].bp_newreq, dat); |
1070 | dat); | ||
1071 | err_out_child_node: | 1063 | err_out_child_node: |
1072 | for (level--; level > NILFS_BTREE_LEVEL_DATA; level--) { | 1064 | for (level--; level > NILFS_BTREE_LEVEL_DATA; level--) { |
1073 | nilfs_btnode_delete(path[level].bp_sib_bh); | 1065 | nilfs_btnode_delete(path[level].bp_sib_bh); |
1074 | nilfs_bmap_abort_alloc_ptr(&btree->bt_bmap, | 1066 | nilfs_bmap_abort_alloc_ptr(btree, &path[level].bp_newreq, dat); |
1075 | &path[level].bp_newreq, dat); | ||
1076 | 1067 | ||
1077 | } | 1068 | } |
1078 | 1069 | ||
1079 | nilfs_bmap_abort_alloc_ptr(&btree->bt_bmap, &path[level].bp_newreq, | 1070 | nilfs_bmap_abort_alloc_ptr(btree, &path[level].bp_newreq, dat); |
1080 | dat); | ||
1081 | err_out_data: | 1071 | err_out_data: |
1082 | *levelp = level; | 1072 | *levelp = level; |
1083 | stats->bs_nblocks = 0; | 1073 | stats->bs_nblocks = 0; |
1084 | return ret; | 1074 | return ret; |
1085 | } | 1075 | } |
1086 | 1076 | ||
1087 | static void nilfs_btree_commit_insert(struct nilfs_btree *btree, | 1077 | static void nilfs_btree_commit_insert(struct nilfs_bmap *btree, |
1088 | struct nilfs_btree_path *path, | 1078 | struct nilfs_btree_path *path, |
1089 | int maxlevel, __u64 key, __u64 ptr) | 1079 | int maxlevel, __u64 key, __u64 ptr) |
1090 | { | 1080 | { |
@@ -1093,29 +1083,27 @@ static void nilfs_btree_commit_insert(struct nilfs_btree *btree, | |||
1093 | 1083 | ||
1094 | set_buffer_nilfs_volatile((struct buffer_head *)((unsigned long)ptr)); | 1084 | set_buffer_nilfs_volatile((struct buffer_head *)((unsigned long)ptr)); |
1095 | ptr = path[NILFS_BTREE_LEVEL_DATA].bp_newreq.bpr_ptr; | 1085 | ptr = path[NILFS_BTREE_LEVEL_DATA].bp_newreq.bpr_ptr; |
1096 | if (NILFS_BMAP_USE_VBN(&btree->bt_bmap)) { | 1086 | if (NILFS_BMAP_USE_VBN(btree)) { |
1097 | nilfs_btree_set_target_v(btree, key, ptr); | 1087 | nilfs_btree_set_target_v(btree, key, ptr); |
1098 | dat = nilfs_bmap_get_dat(&btree->bt_bmap); | 1088 | dat = nilfs_bmap_get_dat(btree); |
1099 | } | 1089 | } |
1100 | 1090 | ||
1101 | for (level = NILFS_BTREE_LEVEL_NODE_MIN; level <= maxlevel; level++) { | 1091 | for (level = NILFS_BTREE_LEVEL_NODE_MIN; level <= maxlevel; level++) { |
1102 | nilfs_bmap_commit_alloc_ptr(&btree->bt_bmap, | 1092 | nilfs_bmap_commit_alloc_ptr(btree, |
1103 | &path[level - 1].bp_newreq, dat); | 1093 | &path[level - 1].bp_newreq, dat); |
1104 | path[level].bp_op(btree, path, level, &key, &ptr); | 1094 | path[level].bp_op(btree, path, level, &key, &ptr); |
1105 | } | 1095 | } |
1106 | 1096 | ||
1107 | if (!nilfs_bmap_dirty(&btree->bt_bmap)) | 1097 | if (!nilfs_bmap_dirty(btree)) |
1108 | nilfs_bmap_set_dirty(&btree->bt_bmap); | 1098 | nilfs_bmap_set_dirty(btree); |
1109 | } | 1099 | } |
1110 | 1100 | ||
1111 | static int nilfs_btree_insert(struct nilfs_bmap *bmap, __u64 key, __u64 ptr) | 1101 | static int nilfs_btree_insert(struct nilfs_bmap *btree, __u64 key, __u64 ptr) |
1112 | { | 1102 | { |
1113 | struct nilfs_btree *btree; | ||
1114 | struct nilfs_btree_path *path; | 1103 | struct nilfs_btree_path *path; |
1115 | struct nilfs_bmap_stats stats; | 1104 | struct nilfs_bmap_stats stats; |
1116 | int level, ret; | 1105 | int level, ret; |
1117 | 1106 | ||
1118 | btree = (struct nilfs_btree *)bmap; | ||
1119 | path = nilfs_btree_alloc_path(); | 1107 | path = nilfs_btree_alloc_path(); |
1120 | if (path == NULL) | 1108 | if (path == NULL) |
1121 | return -ENOMEM; | 1109 | return -ENOMEM; |
@@ -1132,14 +1120,14 @@ static int nilfs_btree_insert(struct nilfs_bmap *bmap, __u64 key, __u64 ptr) | |||
1132 | if (ret < 0) | 1120 | if (ret < 0) |
1133 | goto out; | 1121 | goto out; |
1134 | nilfs_btree_commit_insert(btree, path, level, key, ptr); | 1122 | nilfs_btree_commit_insert(btree, path, level, key, ptr); |
1135 | nilfs_bmap_add_blocks(bmap, stats.bs_nblocks); | 1123 | nilfs_bmap_add_blocks(btree, stats.bs_nblocks); |
1136 | 1124 | ||
1137 | out: | 1125 | out: |
1138 | nilfs_btree_free_path(path); | 1126 | nilfs_btree_free_path(path); |
1139 | return ret; | 1127 | return ret; |
1140 | } | 1128 | } |
1141 | 1129 | ||
1142 | static void nilfs_btree_do_delete(struct nilfs_btree *btree, | 1130 | static void nilfs_btree_do_delete(struct nilfs_bmap *btree, |
1143 | struct nilfs_btree_path *path, | 1131 | struct nilfs_btree_path *path, |
1144 | int level, __u64 *keyp, __u64 *ptrp) | 1132 | int level, __u64 *keyp, __u64 *ptrp) |
1145 | { | 1133 | { |
@@ -1161,7 +1149,7 @@ static void nilfs_btree_do_delete(struct nilfs_btree *btree, | |||
1161 | } | 1149 | } |
1162 | } | 1150 | } |
1163 | 1151 | ||
1164 | static void nilfs_btree_borrow_left(struct nilfs_btree *btree, | 1152 | static void nilfs_btree_borrow_left(struct nilfs_bmap *btree, |
1165 | struct nilfs_btree_path *path, | 1153 | struct nilfs_btree_path *path, |
1166 | int level, __u64 *keyp, __u64 *ptrp) | 1154 | int level, __u64 *keyp, __u64 *ptrp) |
1167 | { | 1155 | { |
@@ -1192,7 +1180,7 @@ static void nilfs_btree_borrow_left(struct nilfs_btree *btree, | |||
1192 | path[level].bp_index += n; | 1180 | path[level].bp_index += n; |
1193 | } | 1181 | } |
1194 | 1182 | ||
1195 | static void nilfs_btree_borrow_right(struct nilfs_btree *btree, | 1183 | static void nilfs_btree_borrow_right(struct nilfs_bmap *btree, |
1196 | struct nilfs_btree_path *path, | 1184 | struct nilfs_btree_path *path, |
1197 | int level, __u64 *keyp, __u64 *ptrp) | 1185 | int level, __u64 *keyp, __u64 *ptrp) |
1198 | { | 1186 | { |
@@ -1224,7 +1212,7 @@ static void nilfs_btree_borrow_right(struct nilfs_btree *btree, | |||
1224 | path[level].bp_sib_bh = NULL; | 1212 | path[level].bp_sib_bh = NULL; |
1225 | } | 1213 | } |
1226 | 1214 | ||
1227 | static void nilfs_btree_concat_left(struct nilfs_btree *btree, | 1215 | static void nilfs_btree_concat_left(struct nilfs_bmap *btree, |
1228 | struct nilfs_btree_path *path, | 1216 | struct nilfs_btree_path *path, |
1229 | int level, __u64 *keyp, __u64 *ptrp) | 1217 | int level, __u64 *keyp, __u64 *ptrp) |
1230 | { | 1218 | { |
@@ -1249,7 +1237,7 @@ static void nilfs_btree_concat_left(struct nilfs_btree *btree, | |||
1249 | path[level].bp_index += nilfs_btree_node_get_nchildren(left); | 1237 | path[level].bp_index += nilfs_btree_node_get_nchildren(left); |
1250 | } | 1238 | } |
1251 | 1239 | ||
1252 | static void nilfs_btree_concat_right(struct nilfs_btree *btree, | 1240 | static void nilfs_btree_concat_right(struct nilfs_bmap *btree, |
1253 | struct nilfs_btree_path *path, | 1241 | struct nilfs_btree_path *path, |
1254 | int level, __u64 *keyp, __u64 *ptrp) | 1242 | int level, __u64 *keyp, __u64 *ptrp) |
1255 | { | 1243 | { |
@@ -1273,7 +1261,7 @@ static void nilfs_btree_concat_right(struct nilfs_btree *btree, | |||
1273 | path[level + 1].bp_index++; | 1261 | path[level + 1].bp_index++; |
1274 | } | 1262 | } |
1275 | 1263 | ||
1276 | static void nilfs_btree_shrink(struct nilfs_btree *btree, | 1264 | static void nilfs_btree_shrink(struct nilfs_bmap *btree, |
1277 | struct nilfs_btree_path *path, | 1265 | struct nilfs_btree_path *path, |
1278 | int level, __u64 *keyp, __u64 *ptrp) | 1266 | int level, __u64 *keyp, __u64 *ptrp) |
1279 | { | 1267 | { |
@@ -1295,7 +1283,7 @@ static void nilfs_btree_shrink(struct nilfs_btree *btree, | |||
1295 | } | 1283 | } |
1296 | 1284 | ||
1297 | 1285 | ||
1298 | static int nilfs_btree_prepare_delete(struct nilfs_btree *btree, | 1286 | static int nilfs_btree_prepare_delete(struct nilfs_bmap *btree, |
1299 | struct nilfs_btree_path *path, | 1287 | struct nilfs_btree_path *path, |
1300 | int *levelp, | 1288 | int *levelp, |
1301 | struct nilfs_bmap_stats *stats, | 1289 | struct nilfs_bmap_stats *stats, |
@@ -1315,7 +1303,7 @@ static int nilfs_btree_prepare_delete(struct nilfs_btree *btree, | |||
1315 | path[level].bp_oldreq.bpr_ptr = | 1303 | path[level].bp_oldreq.bpr_ptr = |
1316 | nilfs_btree_node_get_ptr(btree, node, | 1304 | nilfs_btree_node_get_ptr(btree, node, |
1317 | path[level].bp_index); | 1305 | path[level].bp_index); |
1318 | ret = nilfs_bmap_prepare_end_ptr(&btree->bt_bmap, | 1306 | ret = nilfs_bmap_prepare_end_ptr(btree, |
1319 | &path[level].bp_oldreq, dat); | 1307 | &path[level].bp_oldreq, dat); |
1320 | if (ret < 0) | 1308 | if (ret < 0) |
1321 | goto err_out_child_node; | 1309 | goto err_out_child_node; |
@@ -1393,8 +1381,7 @@ static int nilfs_btree_prepare_delete(struct nilfs_btree *btree, | |||
1393 | path[level].bp_oldreq.bpr_ptr = | 1381 | path[level].bp_oldreq.bpr_ptr = |
1394 | nilfs_btree_node_get_ptr(btree, node, path[level].bp_index); | 1382 | nilfs_btree_node_get_ptr(btree, node, path[level].bp_index); |
1395 | 1383 | ||
1396 | ret = nilfs_bmap_prepare_end_ptr(&btree->bt_bmap, | 1384 | ret = nilfs_bmap_prepare_end_ptr(btree, &path[level].bp_oldreq, dat); |
1397 | &path[level].bp_oldreq, dat); | ||
1398 | if (ret < 0) | 1385 | if (ret < 0) |
1399 | goto err_out_child_node; | 1386 | goto err_out_child_node; |
1400 | 1387 | ||
@@ -1409,44 +1396,40 @@ static int nilfs_btree_prepare_delete(struct nilfs_btree *btree, | |||
1409 | 1396 | ||
1410 | /* error */ | 1397 | /* error */ |
1411 | err_out_curr_node: | 1398 | err_out_curr_node: |
1412 | nilfs_bmap_abort_end_ptr(&btree->bt_bmap, &path[level].bp_oldreq, dat); | 1399 | nilfs_bmap_abort_end_ptr(btree, &path[level].bp_oldreq, dat); |
1413 | err_out_child_node: | 1400 | err_out_child_node: |
1414 | for (level--; level >= NILFS_BTREE_LEVEL_NODE_MIN; level--) { | 1401 | for (level--; level >= NILFS_BTREE_LEVEL_NODE_MIN; level--) { |
1415 | brelse(path[level].bp_sib_bh); | 1402 | brelse(path[level].bp_sib_bh); |
1416 | nilfs_bmap_abort_end_ptr(&btree->bt_bmap, | 1403 | nilfs_bmap_abort_end_ptr(btree, &path[level].bp_oldreq, dat); |
1417 | &path[level].bp_oldreq, dat); | ||
1418 | } | 1404 | } |
1419 | *levelp = level; | 1405 | *levelp = level; |
1420 | stats->bs_nblocks = 0; | 1406 | stats->bs_nblocks = 0; |
1421 | return ret; | 1407 | return ret; |
1422 | } | 1408 | } |
1423 | 1409 | ||
1424 | static void nilfs_btree_commit_delete(struct nilfs_btree *btree, | 1410 | static void nilfs_btree_commit_delete(struct nilfs_bmap *btree, |
1425 | struct nilfs_btree_path *path, | 1411 | struct nilfs_btree_path *path, |
1426 | int maxlevel, struct inode *dat) | 1412 | int maxlevel, struct inode *dat) |
1427 | { | 1413 | { |
1428 | int level; | 1414 | int level; |
1429 | 1415 | ||
1430 | for (level = NILFS_BTREE_LEVEL_NODE_MIN; level <= maxlevel; level++) { | 1416 | for (level = NILFS_BTREE_LEVEL_NODE_MIN; level <= maxlevel; level++) { |
1431 | nilfs_bmap_commit_end_ptr(&btree->bt_bmap, | 1417 | nilfs_bmap_commit_end_ptr(btree, &path[level].bp_oldreq, dat); |
1432 | &path[level].bp_oldreq, dat); | ||
1433 | path[level].bp_op(btree, path, level, NULL, NULL); | 1418 | path[level].bp_op(btree, path, level, NULL, NULL); |
1434 | } | 1419 | } |
1435 | 1420 | ||
1436 | if (!nilfs_bmap_dirty(&btree->bt_bmap)) | 1421 | if (!nilfs_bmap_dirty(btree)) |
1437 | nilfs_bmap_set_dirty(&btree->bt_bmap); | 1422 | nilfs_bmap_set_dirty(btree); |
1438 | } | 1423 | } |
1439 | 1424 | ||
1440 | static int nilfs_btree_delete(struct nilfs_bmap *bmap, __u64 key) | 1425 | static int nilfs_btree_delete(struct nilfs_bmap *btree, __u64 key) |
1441 | 1426 | ||
1442 | { | 1427 | { |
1443 | struct nilfs_btree *btree; | ||
1444 | struct nilfs_btree_path *path; | 1428 | struct nilfs_btree_path *path; |
1445 | struct nilfs_bmap_stats stats; | 1429 | struct nilfs_bmap_stats stats; |
1446 | struct inode *dat; | 1430 | struct inode *dat; |
1447 | int level, ret; | 1431 | int level, ret; |
1448 | 1432 | ||
1449 | btree = (struct nilfs_btree *)bmap; | ||
1450 | path = nilfs_btree_alloc_path(); | 1433 | path = nilfs_btree_alloc_path(); |
1451 | if (path == NULL) | 1434 | if (path == NULL) |
1452 | return -ENOMEM; | 1435 | return -ENOMEM; |
@@ -1457,27 +1440,24 @@ static int nilfs_btree_delete(struct nilfs_bmap *bmap, __u64 key) | |||
1457 | goto out; | 1440 | goto out; |
1458 | 1441 | ||
1459 | 1442 | ||
1460 | dat = NILFS_BMAP_USE_VBN(&btree->bt_bmap) ? | 1443 | dat = NILFS_BMAP_USE_VBN(btree) ? nilfs_bmap_get_dat(btree) : NULL; |
1461 | nilfs_bmap_get_dat(&btree->bt_bmap) : NULL; | ||
1462 | 1444 | ||
1463 | ret = nilfs_btree_prepare_delete(btree, path, &level, &stats, dat); | 1445 | ret = nilfs_btree_prepare_delete(btree, path, &level, &stats, dat); |
1464 | if (ret < 0) | 1446 | if (ret < 0) |
1465 | goto out; | 1447 | goto out; |
1466 | nilfs_btree_commit_delete(btree, path, level, dat); | 1448 | nilfs_btree_commit_delete(btree, path, level, dat); |
1467 | nilfs_bmap_sub_blocks(bmap, stats.bs_nblocks); | 1449 | nilfs_bmap_sub_blocks(btree, stats.bs_nblocks); |
1468 | 1450 | ||
1469 | out: | 1451 | out: |
1470 | nilfs_btree_free_path(path); | 1452 | nilfs_btree_free_path(path); |
1471 | return ret; | 1453 | return ret; |
1472 | } | 1454 | } |
1473 | 1455 | ||
1474 | static int nilfs_btree_last_key(const struct nilfs_bmap *bmap, __u64 *keyp) | 1456 | static int nilfs_btree_last_key(const struct nilfs_bmap *btree, __u64 *keyp) |
1475 | { | 1457 | { |
1476 | struct nilfs_btree *btree; | ||
1477 | struct nilfs_btree_path *path; | 1458 | struct nilfs_btree_path *path; |
1478 | int ret; | 1459 | int ret; |
1479 | 1460 | ||
1480 | btree = (struct nilfs_btree *)bmap; | ||
1481 | path = nilfs_btree_alloc_path(); | 1461 | path = nilfs_btree_alloc_path(); |
1482 | if (path == NULL) | 1462 | if (path == NULL) |
1483 | return -ENOMEM; | 1463 | return -ENOMEM; |
@@ -1489,16 +1469,14 @@ static int nilfs_btree_last_key(const struct nilfs_bmap *bmap, __u64 *keyp) | |||
1489 | return ret; | 1469 | return ret; |
1490 | } | 1470 | } |
1491 | 1471 | ||
1492 | static int nilfs_btree_check_delete(struct nilfs_bmap *bmap, __u64 key) | 1472 | static int nilfs_btree_check_delete(struct nilfs_bmap *btree, __u64 key) |
1493 | { | 1473 | { |
1494 | struct buffer_head *bh; | 1474 | struct buffer_head *bh; |
1495 | struct nilfs_btree *btree; | ||
1496 | struct nilfs_btree_node *root, *node; | 1475 | struct nilfs_btree_node *root, *node; |
1497 | __u64 maxkey, nextmaxkey; | 1476 | __u64 maxkey, nextmaxkey; |
1498 | __u64 ptr; | 1477 | __u64 ptr; |
1499 | int nchildren, ret; | 1478 | int nchildren, ret; |
1500 | 1479 | ||
1501 | btree = (struct nilfs_btree *)bmap; | ||
1502 | root = nilfs_btree_get_root(btree); | 1480 | root = nilfs_btree_get_root(btree); |
1503 | switch (nilfs_btree_height(btree)) { | 1481 | switch (nilfs_btree_height(btree)) { |
1504 | case 2: | 1482 | case 2: |
@@ -1529,18 +1507,16 @@ static int nilfs_btree_check_delete(struct nilfs_bmap *bmap, __u64 key) | |||
1529 | return (maxkey == key) && (nextmaxkey < NILFS_BMAP_LARGE_LOW); | 1507 | return (maxkey == key) && (nextmaxkey < NILFS_BMAP_LARGE_LOW); |
1530 | } | 1508 | } |
1531 | 1509 | ||
1532 | static int nilfs_btree_gather_data(struct nilfs_bmap *bmap, | 1510 | static int nilfs_btree_gather_data(struct nilfs_bmap *btree, |
1533 | __u64 *keys, __u64 *ptrs, int nitems) | 1511 | __u64 *keys, __u64 *ptrs, int nitems) |
1534 | { | 1512 | { |
1535 | struct buffer_head *bh; | 1513 | struct buffer_head *bh; |
1536 | struct nilfs_btree *btree; | ||
1537 | struct nilfs_btree_node *node, *root; | 1514 | struct nilfs_btree_node *node, *root; |
1538 | __le64 *dkeys; | 1515 | __le64 *dkeys; |
1539 | __le64 *dptrs; | 1516 | __le64 *dptrs; |
1540 | __u64 ptr; | 1517 | __u64 ptr; |
1541 | int nchildren, i, ret; | 1518 | int nchildren, i, ret; |
1542 | 1519 | ||
1543 | btree = (struct nilfs_btree *)bmap; | ||
1544 | root = nilfs_btree_get_root(btree); | 1520 | root = nilfs_btree_get_root(btree); |
1545 | switch (nilfs_btree_height(btree)) { | 1521 | switch (nilfs_btree_height(btree)) { |
1546 | case 2: | 1522 | case 2: |
@@ -1578,14 +1554,13 @@ static int nilfs_btree_gather_data(struct nilfs_bmap *bmap, | |||
1578 | } | 1554 | } |
1579 | 1555 | ||
1580 | static int | 1556 | static int |
1581 | nilfs_btree_prepare_convert_and_insert(struct nilfs_bmap *bmap, __u64 key, | 1557 | nilfs_btree_prepare_convert_and_insert(struct nilfs_bmap *btree, __u64 key, |
1582 | union nilfs_bmap_ptr_req *dreq, | 1558 | union nilfs_bmap_ptr_req *dreq, |
1583 | union nilfs_bmap_ptr_req *nreq, | 1559 | union nilfs_bmap_ptr_req *nreq, |
1584 | struct buffer_head **bhp, | 1560 | struct buffer_head **bhp, |
1585 | struct nilfs_bmap_stats *stats) | 1561 | struct nilfs_bmap_stats *stats) |
1586 | { | 1562 | { |
1587 | struct buffer_head *bh; | 1563 | struct buffer_head *bh; |
1588 | struct nilfs_btree *btree = (struct nilfs_btree *)bmap; | ||
1589 | struct inode *dat = NULL; | 1564 | struct inode *dat = NULL; |
1590 | int ret; | 1565 | int ret; |
1591 | 1566 | ||
@@ -1593,12 +1568,12 @@ nilfs_btree_prepare_convert_and_insert(struct nilfs_bmap *bmap, __u64 key, | |||
1593 | 1568 | ||
1594 | /* for data */ | 1569 | /* for data */ |
1595 | /* cannot find near ptr */ | 1570 | /* cannot find near ptr */ |
1596 | if (NILFS_BMAP_USE_VBN(bmap)) { | 1571 | if (NILFS_BMAP_USE_VBN(btree)) { |
1597 | dreq->bpr_ptr = nilfs_btree_find_target_v(btree, NULL, key); | 1572 | dreq->bpr_ptr = nilfs_btree_find_target_v(btree, NULL, key); |
1598 | dat = nilfs_bmap_get_dat(bmap); | 1573 | dat = nilfs_bmap_get_dat(btree); |
1599 | } | 1574 | } |
1600 | 1575 | ||
1601 | ret = nilfs_bmap_prepare_alloc_ptr(bmap, dreq, dat); | 1576 | ret = nilfs_bmap_prepare_alloc_ptr(btree, dreq, dat); |
1602 | if (ret < 0) | 1577 | if (ret < 0) |
1603 | return ret; | 1578 | return ret; |
1604 | 1579 | ||
@@ -1606,7 +1581,7 @@ nilfs_btree_prepare_convert_and_insert(struct nilfs_bmap *bmap, __u64 key, | |||
1606 | stats->bs_nblocks++; | 1581 | stats->bs_nblocks++; |
1607 | if (nreq != NULL) { | 1582 | if (nreq != NULL) { |
1608 | nreq->bpr_ptr = dreq->bpr_ptr + 1; | 1583 | nreq->bpr_ptr = dreq->bpr_ptr + 1; |
1609 | ret = nilfs_bmap_prepare_alloc_ptr(bmap, nreq, dat); | 1584 | ret = nilfs_bmap_prepare_alloc_ptr(btree, nreq, dat); |
1610 | if (ret < 0) | 1585 | if (ret < 0) |
1611 | goto err_out_dreq; | 1586 | goto err_out_dreq; |
1612 | 1587 | ||
@@ -1623,16 +1598,16 @@ nilfs_btree_prepare_convert_and_insert(struct nilfs_bmap *bmap, __u64 key, | |||
1623 | 1598 | ||
1624 | /* error */ | 1599 | /* error */ |
1625 | err_out_nreq: | 1600 | err_out_nreq: |
1626 | nilfs_bmap_abort_alloc_ptr(bmap, nreq, dat); | 1601 | nilfs_bmap_abort_alloc_ptr(btree, nreq, dat); |
1627 | err_out_dreq: | 1602 | err_out_dreq: |
1628 | nilfs_bmap_abort_alloc_ptr(bmap, dreq, dat); | 1603 | nilfs_bmap_abort_alloc_ptr(btree, dreq, dat); |
1629 | stats->bs_nblocks = 0; | 1604 | stats->bs_nblocks = 0; |
1630 | return ret; | 1605 | return ret; |
1631 | 1606 | ||
1632 | } | 1607 | } |
1633 | 1608 | ||
1634 | static void | 1609 | static void |
1635 | nilfs_btree_commit_convert_and_insert(struct nilfs_bmap *bmap, | 1610 | nilfs_btree_commit_convert_and_insert(struct nilfs_bmap *btree, |
1636 | __u64 key, __u64 ptr, | 1611 | __u64 key, __u64 ptr, |
1637 | const __u64 *keys, const __u64 *ptrs, | 1612 | const __u64 *keys, const __u64 *ptrs, |
1638 | int n, | 1613 | int n, |
@@ -1640,34 +1615,32 @@ nilfs_btree_commit_convert_and_insert(struct nilfs_bmap *bmap, | |||
1640 | union nilfs_bmap_ptr_req *nreq, | 1615 | union nilfs_bmap_ptr_req *nreq, |
1641 | struct buffer_head *bh) | 1616 | struct buffer_head *bh) |
1642 | { | 1617 | { |
1643 | struct nilfs_btree *btree = (struct nilfs_btree *)bmap; | ||
1644 | struct nilfs_btree_node *node; | 1618 | struct nilfs_btree_node *node; |
1645 | struct inode *dat; | 1619 | struct inode *dat; |
1646 | __u64 tmpptr; | 1620 | __u64 tmpptr; |
1647 | 1621 | ||
1648 | /* free resources */ | 1622 | /* free resources */ |
1649 | if (bmap->b_ops->bop_clear != NULL) | 1623 | if (btree->b_ops->bop_clear != NULL) |
1650 | bmap->b_ops->bop_clear(bmap); | 1624 | btree->b_ops->bop_clear(btree); |
1651 | 1625 | ||
1652 | /* ptr must be a pointer to a buffer head. */ | 1626 | /* ptr must be a pointer to a buffer head. */ |
1653 | set_buffer_nilfs_volatile((struct buffer_head *)((unsigned long)ptr)); | 1627 | set_buffer_nilfs_volatile((struct buffer_head *)((unsigned long)ptr)); |
1654 | 1628 | ||
1655 | /* convert and insert */ | 1629 | /* convert and insert */ |
1656 | dat = NILFS_BMAP_USE_VBN(bmap) ? nilfs_bmap_get_dat(bmap) : NULL; | 1630 | dat = NILFS_BMAP_USE_VBN(btree) ? nilfs_bmap_get_dat(btree) : NULL; |
1657 | nilfs_btree_init(bmap); | 1631 | nilfs_btree_init(btree); |
1658 | if (nreq != NULL) { | 1632 | if (nreq != NULL) { |
1659 | nilfs_bmap_commit_alloc_ptr(bmap, dreq, dat); | 1633 | nilfs_bmap_commit_alloc_ptr(btree, dreq, dat); |
1660 | nilfs_bmap_commit_alloc_ptr(bmap, nreq, dat); | 1634 | nilfs_bmap_commit_alloc_ptr(btree, nreq, dat); |
1661 | 1635 | ||
1662 | /* create child node at level 1 */ | 1636 | /* create child node at level 1 */ |
1663 | node = (struct nilfs_btree_node *)bh->b_data; | 1637 | node = (struct nilfs_btree_node *)bh->b_data; |
1664 | nilfs_btree_node_init(btree, node, 0, 1, n, keys, ptrs); | 1638 | nilfs_btree_node_init(btree, node, 0, 1, n, keys, ptrs); |
1665 | nilfs_btree_node_insert(btree, node, | 1639 | nilfs_btree_node_insert(btree, node, key, dreq->bpr_ptr, n); |
1666 | key, dreq->bpr_ptr, n); | ||
1667 | if (!buffer_dirty(bh)) | 1640 | if (!buffer_dirty(bh)) |
1668 | nilfs_btnode_mark_dirty(bh); | 1641 | nilfs_btnode_mark_dirty(bh); |
1669 | if (!nilfs_bmap_dirty(bmap)) | 1642 | if (!nilfs_bmap_dirty(btree)) |
1670 | nilfs_bmap_set_dirty(bmap); | 1643 | nilfs_bmap_set_dirty(btree); |
1671 | 1644 | ||
1672 | brelse(bh); | 1645 | brelse(bh); |
1673 | 1646 | ||
@@ -1677,19 +1650,18 @@ nilfs_btree_commit_convert_and_insert(struct nilfs_bmap *bmap, | |||
1677 | nilfs_btree_node_init(btree, node, NILFS_BTREE_NODE_ROOT, | 1650 | nilfs_btree_node_init(btree, node, NILFS_BTREE_NODE_ROOT, |
1678 | 2, 1, &keys[0], &tmpptr); | 1651 | 2, 1, &keys[0], &tmpptr); |
1679 | } else { | 1652 | } else { |
1680 | nilfs_bmap_commit_alloc_ptr(bmap, dreq, dat); | 1653 | nilfs_bmap_commit_alloc_ptr(btree, dreq, dat); |
1681 | 1654 | ||
1682 | /* create root node at level 1 */ | 1655 | /* create root node at level 1 */ |
1683 | node = nilfs_btree_get_root(btree); | 1656 | node = nilfs_btree_get_root(btree); |
1684 | nilfs_btree_node_init(btree, node, NILFS_BTREE_NODE_ROOT, | 1657 | nilfs_btree_node_init(btree, node, NILFS_BTREE_NODE_ROOT, |
1685 | 1, n, keys, ptrs); | 1658 | 1, n, keys, ptrs); |
1686 | nilfs_btree_node_insert(btree, node, | 1659 | nilfs_btree_node_insert(btree, node, key, dreq->bpr_ptr, n); |
1687 | key, dreq->bpr_ptr, n); | 1660 | if (!nilfs_bmap_dirty(btree)) |
1688 | if (!nilfs_bmap_dirty(bmap)) | 1661 | nilfs_bmap_set_dirty(btree); |
1689 | nilfs_bmap_set_dirty(bmap); | ||
1690 | } | 1662 | } |
1691 | 1663 | ||
1692 | if (NILFS_BMAP_USE_VBN(bmap)) | 1664 | if (NILFS_BMAP_USE_VBN(btree)) |
1693 | nilfs_btree_set_target_v(btree, key, dreq->bpr_ptr); | 1665 | nilfs_btree_set_target_v(btree, key, dreq->bpr_ptr); |
1694 | } | 1666 | } |
1695 | 1667 | ||
@@ -1702,7 +1674,7 @@ nilfs_btree_commit_convert_and_insert(struct nilfs_bmap *bmap, | |||
1702 | * @ptrs: | 1674 | * @ptrs: |
1703 | * @n: | 1675 | * @n: |
1704 | */ | 1676 | */ |
1705 | int nilfs_btree_convert_and_insert(struct nilfs_bmap *bmap, | 1677 | int nilfs_btree_convert_and_insert(struct nilfs_bmap *btree, |
1706 | __u64 key, __u64 ptr, | 1678 | __u64 key, __u64 ptr, |
1707 | const __u64 *keys, const __u64 *ptrs, int n) | 1679 | const __u64 *keys, const __u64 *ptrs, int n) |
1708 | { | 1680 | { |
@@ -1715,7 +1687,7 @@ int nilfs_btree_convert_and_insert(struct nilfs_bmap *bmap, | |||
1715 | di = &dreq; | 1687 | di = &dreq; |
1716 | ni = NULL; | 1688 | ni = NULL; |
1717 | } else if ((n + 1) <= NILFS_BTREE_NODE_NCHILDREN_MAX( | 1689 | } else if ((n + 1) <= NILFS_BTREE_NODE_NCHILDREN_MAX( |
1718 | 1 << bmap->b_inode->i_blkbits)) { | 1690 | 1 << btree->b_inode->i_blkbits)) { |
1719 | di = &dreq; | 1691 | di = &dreq; |
1720 | ni = &nreq; | 1692 | ni = &nreq; |
1721 | } else { | 1693 | } else { |
@@ -1724,17 +1696,17 @@ int nilfs_btree_convert_and_insert(struct nilfs_bmap *bmap, | |||
1724 | BUG(); | 1696 | BUG(); |
1725 | } | 1697 | } |
1726 | 1698 | ||
1727 | ret = nilfs_btree_prepare_convert_and_insert(bmap, key, di, ni, &bh, | 1699 | ret = nilfs_btree_prepare_convert_and_insert(btree, key, di, ni, &bh, |
1728 | &stats); | 1700 | &stats); |
1729 | if (ret < 0) | 1701 | if (ret < 0) |
1730 | return ret; | 1702 | return ret; |
1731 | nilfs_btree_commit_convert_and_insert(bmap, key, ptr, keys, ptrs, n, | 1703 | nilfs_btree_commit_convert_and_insert(btree, key, ptr, keys, ptrs, n, |
1732 | di, ni, bh); | 1704 | di, ni, bh); |
1733 | nilfs_bmap_add_blocks(bmap, stats.bs_nblocks); | 1705 | nilfs_bmap_add_blocks(btree, stats.bs_nblocks); |
1734 | return 0; | 1706 | return 0; |
1735 | } | 1707 | } |
1736 | 1708 | ||
1737 | static int nilfs_btree_propagate_p(struct nilfs_btree *btree, | 1709 | static int nilfs_btree_propagate_p(struct nilfs_bmap *btree, |
1738 | struct nilfs_btree_path *path, | 1710 | struct nilfs_btree_path *path, |
1739 | int level, | 1711 | int level, |
1740 | struct buffer_head *bh) | 1712 | struct buffer_head *bh) |
@@ -1746,7 +1718,7 @@ static int nilfs_btree_propagate_p(struct nilfs_btree *btree, | |||
1746 | return 0; | 1718 | return 0; |
1747 | } | 1719 | } |
1748 | 1720 | ||
1749 | static int nilfs_btree_prepare_update_v(struct nilfs_btree *btree, | 1721 | static int nilfs_btree_prepare_update_v(struct nilfs_bmap *btree, |
1750 | struct nilfs_btree_path *path, | 1722 | struct nilfs_btree_path *path, |
1751 | int level, struct inode *dat) | 1723 | int level, struct inode *dat) |
1752 | { | 1724 | { |
@@ -1768,7 +1740,7 @@ static int nilfs_btree_prepare_update_v(struct nilfs_btree *btree, | |||
1768 | path[level].bp_ctxt.newkey = path[level].bp_newreq.bpr_ptr; | 1740 | path[level].bp_ctxt.newkey = path[level].bp_newreq.bpr_ptr; |
1769 | path[level].bp_ctxt.bh = path[level].bp_bh; | 1741 | path[level].bp_ctxt.bh = path[level].bp_bh; |
1770 | ret = nilfs_btnode_prepare_change_key( | 1742 | ret = nilfs_btnode_prepare_change_key( |
1771 | &NILFS_BMAP_I(&btree->bt_bmap)->i_btnode_cache, | 1743 | &NILFS_BMAP_I(btree)->i_btnode_cache, |
1772 | &path[level].bp_ctxt); | 1744 | &path[level].bp_ctxt); |
1773 | if (ret < 0) { | 1745 | if (ret < 0) { |
1774 | nilfs_dat_abort_update(dat, | 1746 | nilfs_dat_abort_update(dat, |
@@ -1781,7 +1753,7 @@ static int nilfs_btree_prepare_update_v(struct nilfs_btree *btree, | |||
1781 | return 0; | 1753 | return 0; |
1782 | } | 1754 | } |
1783 | 1755 | ||
1784 | static void nilfs_btree_commit_update_v(struct nilfs_btree *btree, | 1756 | static void nilfs_btree_commit_update_v(struct nilfs_bmap *btree, |
1785 | struct nilfs_btree_path *path, | 1757 | struct nilfs_btree_path *path, |
1786 | int level, struct inode *dat) | 1758 | int level, struct inode *dat) |
1787 | { | 1759 | { |
@@ -1789,11 +1761,11 @@ static void nilfs_btree_commit_update_v(struct nilfs_btree *btree, | |||
1789 | 1761 | ||
1790 | nilfs_dat_commit_update(dat, &path[level].bp_oldreq.bpr_req, | 1762 | nilfs_dat_commit_update(dat, &path[level].bp_oldreq.bpr_req, |
1791 | &path[level].bp_newreq.bpr_req, | 1763 | &path[level].bp_newreq.bpr_req, |
1792 | btree->bt_bmap.b_ptr_type == NILFS_BMAP_PTR_VS); | 1764 | btree->b_ptr_type == NILFS_BMAP_PTR_VS); |
1793 | 1765 | ||
1794 | if (buffer_nilfs_node(path[level].bp_bh)) { | 1766 | if (buffer_nilfs_node(path[level].bp_bh)) { |
1795 | nilfs_btnode_commit_change_key( | 1767 | nilfs_btnode_commit_change_key( |
1796 | &NILFS_BMAP_I(&btree->bt_bmap)->i_btnode_cache, | 1768 | &NILFS_BMAP_I(btree)->i_btnode_cache, |
1797 | &path[level].bp_ctxt); | 1769 | &path[level].bp_ctxt); |
1798 | path[level].bp_bh = path[level].bp_ctxt.bh; | 1770 | path[level].bp_bh = path[level].bp_ctxt.bh; |
1799 | } | 1771 | } |
@@ -1804,7 +1776,7 @@ static void nilfs_btree_commit_update_v(struct nilfs_btree *btree, | |||
1804 | path[level].bp_newreq.bpr_ptr); | 1776 | path[level].bp_newreq.bpr_ptr); |
1805 | } | 1777 | } |
1806 | 1778 | ||
1807 | static void nilfs_btree_abort_update_v(struct nilfs_btree *btree, | 1779 | static void nilfs_btree_abort_update_v(struct nilfs_bmap *btree, |
1808 | struct nilfs_btree_path *path, | 1780 | struct nilfs_btree_path *path, |
1809 | int level, struct inode *dat) | 1781 | int level, struct inode *dat) |
1810 | { | 1782 | { |
@@ -1812,11 +1784,11 @@ static void nilfs_btree_abort_update_v(struct nilfs_btree *btree, | |||
1812 | &path[level].bp_newreq.bpr_req); | 1784 | &path[level].bp_newreq.bpr_req); |
1813 | if (buffer_nilfs_node(path[level].bp_bh)) | 1785 | if (buffer_nilfs_node(path[level].bp_bh)) |
1814 | nilfs_btnode_abort_change_key( | 1786 | nilfs_btnode_abort_change_key( |
1815 | &NILFS_BMAP_I(&btree->bt_bmap)->i_btnode_cache, | 1787 | &NILFS_BMAP_I(btree)->i_btnode_cache, |
1816 | &path[level].bp_ctxt); | 1788 | &path[level].bp_ctxt); |
1817 | } | 1789 | } |
1818 | 1790 | ||
1819 | static int nilfs_btree_prepare_propagate_v(struct nilfs_btree *btree, | 1791 | static int nilfs_btree_prepare_propagate_v(struct nilfs_bmap *btree, |
1820 | struct nilfs_btree_path *path, | 1792 | struct nilfs_btree_path *path, |
1821 | int minlevel, int *maxlevelp, | 1793 | int minlevel, int *maxlevelp, |
1822 | struct inode *dat) | 1794 | struct inode *dat) |
@@ -1851,7 +1823,7 @@ static int nilfs_btree_prepare_propagate_v(struct nilfs_btree *btree, | |||
1851 | return ret; | 1823 | return ret; |
1852 | } | 1824 | } |
1853 | 1825 | ||
1854 | static void nilfs_btree_commit_propagate_v(struct nilfs_btree *btree, | 1826 | static void nilfs_btree_commit_propagate_v(struct nilfs_bmap *btree, |
1855 | struct nilfs_btree_path *path, | 1827 | struct nilfs_btree_path *path, |
1856 | int minlevel, int maxlevel, | 1828 | int minlevel, int maxlevel, |
1857 | struct buffer_head *bh, | 1829 | struct buffer_head *bh, |
@@ -1866,13 +1838,13 @@ static void nilfs_btree_commit_propagate_v(struct nilfs_btree *btree, | |||
1866 | nilfs_btree_commit_update_v(btree, path, level, dat); | 1838 | nilfs_btree_commit_update_v(btree, path, level, dat); |
1867 | } | 1839 | } |
1868 | 1840 | ||
1869 | static int nilfs_btree_propagate_v(struct nilfs_btree *btree, | 1841 | static int nilfs_btree_propagate_v(struct nilfs_bmap *btree, |
1870 | struct nilfs_btree_path *path, | 1842 | struct nilfs_btree_path *path, |
1871 | int level, struct buffer_head *bh) | 1843 | int level, struct buffer_head *bh) |
1872 | { | 1844 | { |
1873 | int maxlevel = 0, ret; | 1845 | int maxlevel = 0, ret; |
1874 | struct nilfs_btree_node *parent; | 1846 | struct nilfs_btree_node *parent; |
1875 | struct inode *dat = nilfs_bmap_get_dat(&btree->bt_bmap); | 1847 | struct inode *dat = nilfs_bmap_get_dat(btree); |
1876 | __u64 ptr; | 1848 | __u64 ptr; |
1877 | 1849 | ||
1878 | get_bh(bh); | 1850 | get_bh(bh); |
@@ -1899,10 +1871,9 @@ static int nilfs_btree_propagate_v(struct nilfs_btree *btree, | |||
1899 | return ret; | 1871 | return ret; |
1900 | } | 1872 | } |
1901 | 1873 | ||
1902 | static int nilfs_btree_propagate(struct nilfs_bmap *bmap, | 1874 | static int nilfs_btree_propagate(struct nilfs_bmap *btree, |
1903 | struct buffer_head *bh) | 1875 | struct buffer_head *bh) |
1904 | { | 1876 | { |
1905 | struct nilfs_btree *btree; | ||
1906 | struct nilfs_btree_path *path; | 1877 | struct nilfs_btree_path *path; |
1907 | struct nilfs_btree_node *node; | 1878 | struct nilfs_btree_node *node; |
1908 | __u64 key; | 1879 | __u64 key; |
@@ -1910,7 +1881,6 @@ static int nilfs_btree_propagate(struct nilfs_bmap *bmap, | |||
1910 | 1881 | ||
1911 | WARN_ON(!buffer_dirty(bh)); | 1882 | WARN_ON(!buffer_dirty(bh)); |
1912 | 1883 | ||
1913 | btree = (struct nilfs_btree *)bmap; | ||
1914 | path = nilfs_btree_alloc_path(); | 1884 | path = nilfs_btree_alloc_path(); |
1915 | if (path == NULL) | 1885 | if (path == NULL) |
1916 | return -ENOMEM; | 1886 | return -ENOMEM; |
@@ -1920,7 +1890,7 @@ static int nilfs_btree_propagate(struct nilfs_bmap *bmap, | |||
1920 | key = nilfs_btree_node_get_key(node, 0); | 1890 | key = nilfs_btree_node_get_key(node, 0); |
1921 | level = nilfs_btree_node_get_level(node); | 1891 | level = nilfs_btree_node_get_level(node); |
1922 | } else { | 1892 | } else { |
1923 | key = nilfs_bmap_data_get_key(bmap, bh); | 1893 | key = nilfs_bmap_data_get_key(btree, bh); |
1924 | level = NILFS_BTREE_LEVEL_DATA; | 1894 | level = NILFS_BTREE_LEVEL_DATA; |
1925 | } | 1895 | } |
1926 | 1896 | ||
@@ -1932,7 +1902,7 @@ static int nilfs_btree_propagate(struct nilfs_bmap *bmap, | |||
1932 | goto out; | 1902 | goto out; |
1933 | } | 1903 | } |
1934 | 1904 | ||
1935 | ret = NILFS_BMAP_USE_VBN(bmap) ? | 1905 | ret = NILFS_BMAP_USE_VBN(btree) ? |
1936 | nilfs_btree_propagate_v(btree, path, level, bh) : | 1906 | nilfs_btree_propagate_v(btree, path, level, bh) : |
1937 | nilfs_btree_propagate_p(btree, path, level, bh); | 1907 | nilfs_btree_propagate_p(btree, path, level, bh); |
1938 | 1908 | ||
@@ -1942,13 +1912,13 @@ static int nilfs_btree_propagate(struct nilfs_bmap *bmap, | |||
1942 | return ret; | 1912 | return ret; |
1943 | } | 1913 | } |
1944 | 1914 | ||
1945 | static int nilfs_btree_propagate_gc(struct nilfs_bmap *bmap, | 1915 | static int nilfs_btree_propagate_gc(struct nilfs_bmap *btree, |
1946 | struct buffer_head *bh) | 1916 | struct buffer_head *bh) |
1947 | { | 1917 | { |
1948 | return nilfs_dat_mark_dirty(nilfs_bmap_get_dat(bmap), bh->b_blocknr); | 1918 | return nilfs_dat_mark_dirty(nilfs_bmap_get_dat(btree), bh->b_blocknr); |
1949 | } | 1919 | } |
1950 | 1920 | ||
1951 | static void nilfs_btree_add_dirty_buffer(struct nilfs_btree *btree, | 1921 | static void nilfs_btree_add_dirty_buffer(struct nilfs_bmap *btree, |
1952 | struct list_head *lists, | 1922 | struct list_head *lists, |
1953 | struct buffer_head *bh) | 1923 | struct buffer_head *bh) |
1954 | { | 1924 | { |
@@ -1969,7 +1939,7 @@ static void nilfs_btree_add_dirty_buffer(struct nilfs_btree *btree, | |||
1969 | "%s: invalid btree level: %d (key=%llu, ino=%lu, " | 1939 | "%s: invalid btree level: %d (key=%llu, ino=%lu, " |
1970 | "blocknr=%llu)\n", | 1940 | "blocknr=%llu)\n", |
1971 | __func__, level, (unsigned long long)key, | 1941 | __func__, level, (unsigned long long)key, |
1972 | NILFS_BMAP_I(&btree->bt_bmap)->vfs_inode.i_ino, | 1942 | NILFS_BMAP_I(btree)->vfs_inode.i_ino, |
1973 | (unsigned long long)bh->b_blocknr); | 1943 | (unsigned long long)bh->b_blocknr); |
1974 | return; | 1944 | return; |
1975 | } | 1945 | } |
@@ -1984,11 +1954,10 @@ static void nilfs_btree_add_dirty_buffer(struct nilfs_btree *btree, | |||
1984 | list_add_tail(&bh->b_assoc_buffers, head); | 1954 | list_add_tail(&bh->b_assoc_buffers, head); |
1985 | } | 1955 | } |
1986 | 1956 | ||
1987 | static void nilfs_btree_lookup_dirty_buffers(struct nilfs_bmap *bmap, | 1957 | static void nilfs_btree_lookup_dirty_buffers(struct nilfs_bmap *btree, |
1988 | struct list_head *listp) | 1958 | struct list_head *listp) |
1989 | { | 1959 | { |
1990 | struct nilfs_btree *btree = (struct nilfs_btree *)bmap; | 1960 | struct address_space *btcache = &NILFS_BMAP_I(btree)->i_btnode_cache; |
1991 | struct address_space *btcache = &NILFS_BMAP_I(bmap)->i_btnode_cache; | ||
1992 | struct list_head lists[NILFS_BTREE_LEVEL_MAX]; | 1961 | struct list_head lists[NILFS_BTREE_LEVEL_MAX]; |
1993 | struct pagevec pvec; | 1962 | struct pagevec pvec; |
1994 | struct buffer_head *bh, *head; | 1963 | struct buffer_head *bh, *head; |
@@ -2022,7 +1991,7 @@ static void nilfs_btree_lookup_dirty_buffers(struct nilfs_bmap *bmap, | |||
2022 | list_splice_tail(&lists[level], listp); | 1991 | list_splice_tail(&lists[level], listp); |
2023 | } | 1992 | } |
2024 | 1993 | ||
2025 | static int nilfs_btree_assign_p(struct nilfs_btree *btree, | 1994 | static int nilfs_btree_assign_p(struct nilfs_bmap *btree, |
2026 | struct nilfs_btree_path *path, | 1995 | struct nilfs_btree_path *path, |
2027 | int level, | 1996 | int level, |
2028 | struct buffer_head **bh, | 1997 | struct buffer_head **bh, |
@@ -2042,12 +2011,12 @@ static int nilfs_btree_assign_p(struct nilfs_btree *btree, | |||
2042 | path[level].bp_ctxt.newkey = blocknr; | 2011 | path[level].bp_ctxt.newkey = blocknr; |
2043 | path[level].bp_ctxt.bh = *bh; | 2012 | path[level].bp_ctxt.bh = *bh; |
2044 | ret = nilfs_btnode_prepare_change_key( | 2013 | ret = nilfs_btnode_prepare_change_key( |
2045 | &NILFS_BMAP_I(&btree->bt_bmap)->i_btnode_cache, | 2014 | &NILFS_BMAP_I(btree)->i_btnode_cache, |
2046 | &path[level].bp_ctxt); | 2015 | &path[level].bp_ctxt); |
2047 | if (ret < 0) | 2016 | if (ret < 0) |
2048 | return ret; | 2017 | return ret; |
2049 | nilfs_btnode_commit_change_key( | 2018 | nilfs_btnode_commit_change_key( |
2050 | &NILFS_BMAP_I(&btree->bt_bmap)->i_btnode_cache, | 2019 | &NILFS_BMAP_I(btree)->i_btnode_cache, |
2051 | &path[level].bp_ctxt); | 2020 | &path[level].bp_ctxt); |
2052 | *bh = path[level].bp_ctxt.bh; | 2021 | *bh = path[level].bp_ctxt.bh; |
2053 | } | 2022 | } |
@@ -2063,7 +2032,7 @@ static int nilfs_btree_assign_p(struct nilfs_btree *btree, | |||
2063 | return 0; | 2032 | return 0; |
2064 | } | 2033 | } |
2065 | 2034 | ||
2066 | static int nilfs_btree_assign_v(struct nilfs_btree *btree, | 2035 | static int nilfs_btree_assign_v(struct nilfs_bmap *btree, |
2067 | struct nilfs_btree_path *path, | 2036 | struct nilfs_btree_path *path, |
2068 | int level, | 2037 | int level, |
2069 | struct buffer_head **bh, | 2038 | struct buffer_head **bh, |
@@ -2071,15 +2040,14 @@ static int nilfs_btree_assign_v(struct nilfs_btree *btree, | |||
2071 | union nilfs_binfo *binfo) | 2040 | union nilfs_binfo *binfo) |
2072 | { | 2041 | { |
2073 | struct nilfs_btree_node *parent; | 2042 | struct nilfs_btree_node *parent; |
2074 | struct inode *dat = nilfs_bmap_get_dat(&btree->bt_bmap); | 2043 | struct inode *dat = nilfs_bmap_get_dat(btree); |
2075 | __u64 key; | 2044 | __u64 key; |
2076 | __u64 ptr; | 2045 | __u64 ptr; |
2077 | union nilfs_bmap_ptr_req req; | 2046 | union nilfs_bmap_ptr_req req; |
2078 | int ret; | 2047 | int ret; |
2079 | 2048 | ||
2080 | parent = nilfs_btree_get_node(btree, path, level + 1); | 2049 | parent = nilfs_btree_get_node(btree, path, level + 1); |
2081 | ptr = nilfs_btree_node_get_ptr(btree, parent, | 2050 | ptr = nilfs_btree_node_get_ptr(btree, parent, path[level + 1].bp_index); |
2082 | path[level + 1].bp_index); | ||
2083 | req.bpr_ptr = ptr; | 2051 | req.bpr_ptr = ptr; |
2084 | ret = nilfs_dat_prepare_start(dat, &req.bpr_req); | 2052 | ret = nilfs_dat_prepare_start(dat, &req.bpr_req); |
2085 | if (ret < 0) | 2053 | if (ret < 0) |
@@ -2094,18 +2062,16 @@ static int nilfs_btree_assign_v(struct nilfs_btree *btree, | |||
2094 | return 0; | 2062 | return 0; |
2095 | } | 2063 | } |
2096 | 2064 | ||
2097 | static int nilfs_btree_assign(struct nilfs_bmap *bmap, | 2065 | static int nilfs_btree_assign(struct nilfs_bmap *btree, |
2098 | struct buffer_head **bh, | 2066 | struct buffer_head **bh, |
2099 | sector_t blocknr, | 2067 | sector_t blocknr, |
2100 | union nilfs_binfo *binfo) | 2068 | union nilfs_binfo *binfo) |
2101 | { | 2069 | { |
2102 | struct nilfs_btree *btree; | ||
2103 | struct nilfs_btree_path *path; | 2070 | struct nilfs_btree_path *path; |
2104 | struct nilfs_btree_node *node; | 2071 | struct nilfs_btree_node *node; |
2105 | __u64 key; | 2072 | __u64 key; |
2106 | int level, ret; | 2073 | int level, ret; |
2107 | 2074 | ||
2108 | btree = (struct nilfs_btree *)bmap; | ||
2109 | path = nilfs_btree_alloc_path(); | 2075 | path = nilfs_btree_alloc_path(); |
2110 | if (path == NULL) | 2076 | if (path == NULL) |
2111 | return -ENOMEM; | 2077 | return -ENOMEM; |
@@ -2115,7 +2081,7 @@ static int nilfs_btree_assign(struct nilfs_bmap *bmap, | |||
2115 | key = nilfs_btree_node_get_key(node, 0); | 2081 | key = nilfs_btree_node_get_key(node, 0); |
2116 | level = nilfs_btree_node_get_level(node); | 2082 | level = nilfs_btree_node_get_level(node); |
2117 | } else { | 2083 | } else { |
2118 | key = nilfs_bmap_data_get_key(bmap, *bh); | 2084 | key = nilfs_bmap_data_get_key(btree, *bh); |
2119 | level = NILFS_BTREE_LEVEL_DATA; | 2085 | level = NILFS_BTREE_LEVEL_DATA; |
2120 | } | 2086 | } |
2121 | 2087 | ||
@@ -2125,7 +2091,7 @@ static int nilfs_btree_assign(struct nilfs_bmap *bmap, | |||
2125 | goto out; | 2091 | goto out; |
2126 | } | 2092 | } |
2127 | 2093 | ||
2128 | ret = NILFS_BMAP_USE_VBN(bmap) ? | 2094 | ret = NILFS_BMAP_USE_VBN(btree) ? |
2129 | nilfs_btree_assign_v(btree, path, level, bh, blocknr, binfo) : | 2095 | nilfs_btree_assign_v(btree, path, level, bh, blocknr, binfo) : |
2130 | nilfs_btree_assign_p(btree, path, level, bh, blocknr, binfo); | 2096 | nilfs_btree_assign_p(btree, path, level, bh, blocknr, binfo); |
2131 | 2097 | ||
@@ -2135,7 +2101,7 @@ static int nilfs_btree_assign(struct nilfs_bmap *bmap, | |||
2135 | return ret; | 2101 | return ret; |
2136 | } | 2102 | } |
2137 | 2103 | ||
2138 | static int nilfs_btree_assign_gc(struct nilfs_bmap *bmap, | 2104 | static int nilfs_btree_assign_gc(struct nilfs_bmap *btree, |
2139 | struct buffer_head **bh, | 2105 | struct buffer_head **bh, |
2140 | sector_t blocknr, | 2106 | sector_t blocknr, |
2141 | union nilfs_binfo *binfo) | 2107 | union nilfs_binfo *binfo) |
@@ -2144,7 +2110,7 @@ static int nilfs_btree_assign_gc(struct nilfs_bmap *bmap, | |||
2144 | __u64 key; | 2110 | __u64 key; |
2145 | int ret; | 2111 | int ret; |
2146 | 2112 | ||
2147 | ret = nilfs_dat_move(nilfs_bmap_get_dat(bmap), (*bh)->b_blocknr, | 2113 | ret = nilfs_dat_move(nilfs_bmap_get_dat(btree), (*bh)->b_blocknr, |
2148 | blocknr); | 2114 | blocknr); |
2149 | if (ret < 0) | 2115 | if (ret < 0) |
2150 | return ret; | 2116 | return ret; |
@@ -2153,7 +2119,7 @@ static int nilfs_btree_assign_gc(struct nilfs_bmap *bmap, | |||
2153 | node = (struct nilfs_btree_node *)(*bh)->b_data; | 2119 | node = (struct nilfs_btree_node *)(*bh)->b_data; |
2154 | key = nilfs_btree_node_get_key(node, 0); | 2120 | key = nilfs_btree_node_get_key(node, 0); |
2155 | } else | 2121 | } else |
2156 | key = nilfs_bmap_data_get_key(bmap, *bh); | 2122 | key = nilfs_bmap_data_get_key(btree, *bh); |
2157 | 2123 | ||
2158 | /* on-disk format */ | 2124 | /* on-disk format */ |
2159 | binfo->bi_v.bi_vblocknr = cpu_to_le64((*bh)->b_blocknr); | 2125 | binfo->bi_v.bi_vblocknr = cpu_to_le64((*bh)->b_blocknr); |
@@ -2162,15 +2128,13 @@ static int nilfs_btree_assign_gc(struct nilfs_bmap *bmap, | |||
2162 | return 0; | 2128 | return 0; |
2163 | } | 2129 | } |
2164 | 2130 | ||
2165 | static int nilfs_btree_mark(struct nilfs_bmap *bmap, __u64 key, int level) | 2131 | static int nilfs_btree_mark(struct nilfs_bmap *btree, __u64 key, int level) |
2166 | { | 2132 | { |
2167 | struct buffer_head *bh; | 2133 | struct buffer_head *bh; |
2168 | struct nilfs_btree *btree; | ||
2169 | struct nilfs_btree_path *path; | 2134 | struct nilfs_btree_path *path; |
2170 | __u64 ptr; | 2135 | __u64 ptr; |
2171 | int ret; | 2136 | int ret; |
2172 | 2137 | ||
2173 | btree = (struct nilfs_btree *)bmap; | ||
2174 | path = nilfs_btree_alloc_path(); | 2138 | path = nilfs_btree_alloc_path(); |
2175 | if (path == NULL) | 2139 | if (path == NULL) |
2176 | return -ENOMEM; | 2140 | return -ENOMEM; |
@@ -2189,8 +2153,8 @@ static int nilfs_btree_mark(struct nilfs_bmap *bmap, __u64 key, int level) | |||
2189 | if (!buffer_dirty(bh)) | 2153 | if (!buffer_dirty(bh)) |
2190 | nilfs_btnode_mark_dirty(bh); | 2154 | nilfs_btnode_mark_dirty(bh); |
2191 | brelse(bh); | 2155 | brelse(bh); |
2192 | if (!nilfs_bmap_dirty(&btree->bt_bmap)) | 2156 | if (!nilfs_bmap_dirty(btree)) |
2193 | nilfs_bmap_set_dirty(&btree->bt_bmap); | 2157 | nilfs_bmap_set_dirty(btree); |
2194 | 2158 | ||
2195 | out: | 2159 | out: |
2196 | nilfs_btree_free_path(path); | 2160 | nilfs_btree_free_path(path); |