diff options
author | Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> | 2009-10-10 09:58:10 -0400 |
---|---|---|
committer | Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> | 2009-11-19 20:05:46 -0500 |
commit | 9b945d537db86557e5b5820b4b52df94c35b3829 (patch) | |
tree | 84f041ec97f26d79709e93623f75371f6449d7ef /fs/nilfs2/btree.c | |
parent | 648f4e3e50c4793d9dbf9a09afa193631f76fa26 (diff) |
nilfs2: get rid of BUG_ON use in btree lookup routines
The current btree lookup routines make a kernel oops when detected
inconsistency in btree blocks. These routines should instead return a
proper error code because the inconsistency usually comes from
corruption of on-disk metadata.
This fixes the issue by converting BUG_ON calls to proper error
handlings.
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 | 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; |