diff options
Diffstat (limited to 'fs/nilfs2/btree.c')
-rw-r--r-- | fs/nilfs2/btree.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/fs/nilfs2/btree.c b/fs/nilfs2/btree.c index e25b507a474f..420c9ecbca15 100644 --- a/fs/nilfs2/btree.c +++ b/fs/nilfs2/btree.c | |||
@@ -444,6 +444,18 @@ nilfs_btree_get_node(const struct nilfs_btree *btree, | |||
444 | nilfs_btree_get_nonroot_node(path, level); | 444 | nilfs_btree_get_nonroot_node(path, level); |
445 | } | 445 | } |
446 | 446 | ||
447 | static inline int | ||
448 | nilfs_btree_bad_node(struct nilfs_btree_node *node, int level) | ||
449 | { | ||
450 | if (unlikely(nilfs_btree_node_get_level(node) != level)) { | ||
451 | dump_stack(); | ||
452 | printk(KERN_CRIT "NILFS: btree level mismatch: %d != %d\n", | ||
453 | nilfs_btree_node_get_level(node), level); | ||
454 | return 1; | ||
455 | } | ||
456 | return 0; | ||
457 | } | ||
458 | |||
447 | static int nilfs_btree_do_lookup(const struct nilfs_btree *btree, | 459 | static int nilfs_btree_do_lookup(const struct nilfs_btree *btree, |
448 | struct nilfs_btree_path *path, | 460 | struct nilfs_btree_path *path, |
449 | __u64 key, __u64 *ptrp, int minlevel) | 461 | __u64 key, __u64 *ptrp, int minlevel) |
@@ -467,7 +479,8 @@ static int nilfs_btree_do_lookup(const struct nilfs_btree *btree, | |||
467 | if (ret < 0) | 479 | if (ret < 0) |
468 | return ret; | 480 | return ret; |
469 | node = nilfs_btree_get_nonroot_node(path, level); | 481 | node = nilfs_btree_get_nonroot_node(path, level); |
470 | BUG_ON(level != nilfs_btree_node_get_level(node)); | 482 | if (nilfs_btree_bad_node(node, level)) |
483 | return -EINVAL; | ||
471 | if (!found) | 484 | if (!found) |
472 | found = nilfs_btree_node_lookup(node, key, &index); | 485 | found = nilfs_btree_node_lookup(node, key, &index); |
473 | else | 486 | else |
@@ -512,7 +525,8 @@ static int nilfs_btree_do_lookup_last(const struct nilfs_btree *btree, | |||
512 | if (ret < 0) | 525 | if (ret < 0) |
513 | return ret; | 526 | return ret; |
514 | node = nilfs_btree_get_nonroot_node(path, level); | 527 | node = nilfs_btree_get_nonroot_node(path, level); |
515 | BUG_ON(level != nilfs_btree_node_get_level(node)); | 528 | if (nilfs_btree_bad_node(node, level)) |
529 | return -EINVAL; | ||
516 | index = nilfs_btree_node_get_nchildren(node) - 1; | 530 | index = nilfs_btree_node_get_nchildren(node) - 1; |
517 | ptr = nilfs_btree_node_get_ptr(btree, node, index); | 531 | ptr = nilfs_btree_node_get_ptr(btree, node, index); |
518 | path[level].bp_index = index; | 532 | path[level].bp_index = index; |