diff options
author | Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> | 2009-04-06 22:01:55 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-04-07 11:31:19 -0400 |
commit | 1f5abe7e7dbcd83e73212c6cb135a6106cea6a0b (patch) | |
tree | f80e97297d5badebd31bbb17003d76a4ea30453a /fs/nilfs2/segment.c | |
parent | 2c2e52fc4fca251e68f90821c9ff5cb18be4df58 (diff) |
nilfs2: replace BUG_ON and BUG calls triggerable from ioctl
Pekka Enberg advised me:
> It would be nice if BUG(), BUG_ON(), and panic() calls would be
> converted to proper error handling using WARN_ON() calls. The BUG()
> call in nilfs_cpfile_delete_checkpoints(), for example, looks to be
> triggerable from user-space via the ioctl() system call.
This will follow the comment and keep them to a minimum.
Acked-by: Pekka Enberg <penberg@cs.helsinki.fi>
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/nilfs2/segment.c')
-rw-r--r-- | fs/nilfs2/segment.c | 78 |
1 files changed, 23 insertions, 55 deletions
diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c index 24d0fbd4271c..9a87410985b9 100644 --- a/fs/nilfs2/segment.c +++ b/fs/nilfs2/segment.c | |||
@@ -334,8 +334,7 @@ static void nilfs_transaction_lock(struct nilfs_sb_info *sbi, | |||
334 | { | 334 | { |
335 | struct nilfs_transaction_info *cur_ti = current->journal_info; | 335 | struct nilfs_transaction_info *cur_ti = current->journal_info; |
336 | 336 | ||
337 | BUG_ON(cur_ti); | 337 | WARN_ON(cur_ti); |
338 | BUG_ON(!ti); | ||
339 | ti->ti_flags = NILFS_TI_WRITER; | 338 | ti->ti_flags = NILFS_TI_WRITER; |
340 | ti->ti_count = 0; | 339 | ti->ti_count = 0; |
341 | ti->ti_save = cur_ti; | 340 | ti->ti_save = cur_ti; |
@@ -546,8 +545,6 @@ static int nilfs_collect_file_data(struct nilfs_sc_info *sci, | |||
546 | { | 545 | { |
547 | int err; | 546 | int err; |
548 | 547 | ||
549 | /* BUG_ON(!buffer_dirty(bh)); */ | ||
550 | /* excluded by scan_dirty_data_buffers() */ | ||
551 | err = nilfs_bmap_propagate(NILFS_I(inode)->i_bmap, bh); | 548 | err = nilfs_bmap_propagate(NILFS_I(inode)->i_bmap, bh); |
552 | if (unlikely(err < 0)) | 549 | if (unlikely(err < 0)) |
553 | return nilfs_handle_bmap_error(err, __func__, inode, | 550 | return nilfs_handle_bmap_error(err, __func__, inode, |
@@ -566,8 +563,6 @@ static int nilfs_collect_file_node(struct nilfs_sc_info *sci, | |||
566 | { | 563 | { |
567 | int err; | 564 | int err; |
568 | 565 | ||
569 | /* BUG_ON(!buffer_dirty(bh)); */ | ||
570 | /* excluded by scan_dirty_node_buffers() */ | ||
571 | err = nilfs_bmap_propagate(NILFS_I(inode)->i_bmap, bh); | 566 | err = nilfs_bmap_propagate(NILFS_I(inode)->i_bmap, bh); |
572 | if (unlikely(err < 0)) | 567 | if (unlikely(err < 0)) |
573 | return nilfs_handle_bmap_error(err, __func__, inode, | 568 | return nilfs_handle_bmap_error(err, __func__, inode, |
@@ -579,7 +574,7 @@ static int nilfs_collect_file_bmap(struct nilfs_sc_info *sci, | |||
579 | struct buffer_head *bh, | 574 | struct buffer_head *bh, |
580 | struct inode *inode) | 575 | struct inode *inode) |
581 | { | 576 | { |
582 | BUG_ON(!buffer_dirty(bh)); | 577 | WARN_ON(!buffer_dirty(bh)); |
583 | return nilfs_segctor_add_file_block(sci, bh, inode, sizeof(__le64)); | 578 | return nilfs_segctor_add_file_block(sci, bh, inode, sizeof(__le64)); |
584 | } | 579 | } |
585 | 580 | ||
@@ -628,7 +623,7 @@ static int nilfs_collect_dat_data(struct nilfs_sc_info *sci, | |||
628 | static int nilfs_collect_dat_bmap(struct nilfs_sc_info *sci, | 623 | static int nilfs_collect_dat_bmap(struct nilfs_sc_info *sci, |
629 | struct buffer_head *bh, struct inode *inode) | 624 | struct buffer_head *bh, struct inode *inode) |
630 | { | 625 | { |
631 | BUG_ON(!buffer_dirty(bh)); | 626 | WARN_ON(!buffer_dirty(bh)); |
632 | return nilfs_segctor_add_file_block(sci, bh, inode, | 627 | return nilfs_segctor_add_file_block(sci, bh, inode, |
633 | sizeof(struct nilfs_binfo_dat)); | 628 | sizeof(struct nilfs_binfo_dat)); |
634 | } | 629 | } |
@@ -862,9 +857,9 @@ static int nilfs_segctor_create_checkpoint(struct nilfs_sc_info *sci) | |||
862 | nilfs_mdt_mark_dirty(nilfs->ns_cpfile); | 857 | nilfs_mdt_mark_dirty(nilfs->ns_cpfile); |
863 | nilfs_cpfile_put_checkpoint( | 858 | nilfs_cpfile_put_checkpoint( |
864 | nilfs->ns_cpfile, nilfs->ns_cno, bh_cp); | 859 | nilfs->ns_cpfile, nilfs->ns_cno, bh_cp); |
865 | } else { | 860 | } else |
866 | BUG_ON(err == -EINVAL || err == -ENOENT); | 861 | WARN_ON(err == -EINVAL || err == -ENOENT); |
867 | } | 862 | |
868 | return err; | 863 | return err; |
869 | } | 864 | } |
870 | 865 | ||
@@ -879,7 +874,7 @@ static int nilfs_segctor_fill_in_checkpoint(struct nilfs_sc_info *sci) | |||
879 | err = nilfs_cpfile_get_checkpoint(nilfs->ns_cpfile, nilfs->ns_cno, 0, | 874 | err = nilfs_cpfile_get_checkpoint(nilfs->ns_cpfile, nilfs->ns_cno, 0, |
880 | &raw_cp, &bh_cp); | 875 | &raw_cp, &bh_cp); |
881 | if (unlikely(err)) { | 876 | if (unlikely(err)) { |
882 | BUG_ON(err == -EINVAL || err == -ENOENT); | 877 | WARN_ON(err == -EINVAL || err == -ENOENT); |
883 | goto failed_ibh; | 878 | goto failed_ibh; |
884 | } | 879 | } |
885 | raw_cp->cp_snapshot_list.ssl_next = 0; | 880 | raw_cp->cp_snapshot_list.ssl_next = 0; |
@@ -944,7 +939,6 @@ static void nilfs_fill_in_super_root_crc(struct buffer_head *bh_sr, u32 seed) | |||
944 | (struct nilfs_super_root *)bh_sr->b_data; | 939 | (struct nilfs_super_root *)bh_sr->b_data; |
945 | u32 crc; | 940 | u32 crc; |
946 | 941 | ||
947 | BUG_ON(NILFS_SR_BYTES > bh_sr->b_size); | ||
948 | crc = crc32_le(seed, | 942 | crc = crc32_le(seed, |
949 | (unsigned char *)raw_sr + sizeof(raw_sr->sr_sum), | 943 | (unsigned char *)raw_sr + sizeof(raw_sr->sr_sum), |
950 | NILFS_SR_BYTES - sizeof(raw_sr->sr_sum)); | 944 | NILFS_SR_BYTES - sizeof(raw_sr->sr_sum)); |
@@ -1022,8 +1016,7 @@ static void nilfs_segctor_cancel_free_segments(struct nilfs_sc_info *sci, | |||
1022 | if (!(ent->flags & NILFS_SLH_FREED)) | 1016 | if (!(ent->flags & NILFS_SLH_FREED)) |
1023 | break; | 1017 | break; |
1024 | err = nilfs_sufile_cancel_free(sufile, ent->segnum); | 1018 | err = nilfs_sufile_cancel_free(sufile, ent->segnum); |
1025 | BUG_ON(err); | 1019 | WARN_ON(err); /* do not happen */ |
1026 | |||
1027 | ent->flags &= ~NILFS_SLH_FREED; | 1020 | ent->flags &= ~NILFS_SLH_FREED; |
1028 | } | 1021 | } |
1029 | } | 1022 | } |
@@ -1472,7 +1465,7 @@ static int nilfs_segctor_extend_segments(struct nilfs_sc_info *sci, | |||
1472 | failed: | 1465 | failed: |
1473 | list_for_each_entry_safe(segbuf, n, &list, sb_list) { | 1466 | list_for_each_entry_safe(segbuf, n, &list, sb_list) { |
1474 | ret = nilfs_sufile_free(sufile, segbuf->sb_nextnum); | 1467 | ret = nilfs_sufile_free(sufile, segbuf->sb_nextnum); |
1475 | BUG_ON(ret); | 1468 | WARN_ON(ret); /* never fails */ |
1476 | list_del_init(&segbuf->sb_list); | 1469 | list_del_init(&segbuf->sb_list); |
1477 | nilfs_segbuf_free(segbuf); | 1470 | nilfs_segbuf_free(segbuf); |
1478 | } | 1471 | } |
@@ -1488,7 +1481,7 @@ static void nilfs_segctor_free_incomplete_segments(struct nilfs_sc_info *sci, | |||
1488 | segbuf = NILFS_FIRST_SEGBUF(&sci->sc_segbufs); | 1481 | segbuf = NILFS_FIRST_SEGBUF(&sci->sc_segbufs); |
1489 | if (nilfs->ns_nextnum != segbuf->sb_nextnum) { | 1482 | if (nilfs->ns_nextnum != segbuf->sb_nextnum) { |
1490 | ret = nilfs_sufile_free(nilfs->ns_sufile, segbuf->sb_nextnum); | 1483 | ret = nilfs_sufile_free(nilfs->ns_sufile, segbuf->sb_nextnum); |
1491 | BUG_ON(ret); | 1484 | WARN_ON(ret); /* never fails */ |
1492 | } | 1485 | } |
1493 | if (segbuf->sb_io_error) { | 1486 | if (segbuf->sb_io_error) { |
1494 | /* Case 1: The first segment failed */ | 1487 | /* Case 1: The first segment failed */ |
@@ -1504,7 +1497,7 @@ static void nilfs_segctor_free_incomplete_segments(struct nilfs_sc_info *sci, | |||
1504 | 1497 | ||
1505 | list_for_each_entry_continue(segbuf, &sci->sc_segbufs, sb_list) { | 1498 | list_for_each_entry_continue(segbuf, &sci->sc_segbufs, sb_list) { |
1506 | ret = nilfs_sufile_free(nilfs->ns_sufile, segbuf->sb_nextnum); | 1499 | ret = nilfs_sufile_free(nilfs->ns_sufile, segbuf->sb_nextnum); |
1507 | BUG_ON(ret); | 1500 | WARN_ON(ret); /* never fails */ |
1508 | if (!done && segbuf->sb_io_error) { | 1501 | if (!done && segbuf->sb_io_error) { |
1509 | if (segbuf->sb_segnum != nilfs->ns_nextnum) | 1502 | if (segbuf->sb_segnum != nilfs->ns_nextnum) |
1510 | /* Case 2: extended segment (!= next) failed */ | 1503 | /* Case 2: extended segment (!= next) failed */ |
@@ -1558,7 +1551,7 @@ static void nilfs_segctor_update_segusage(struct nilfs_sc_info *sci, | |||
1558 | list_for_each_entry(segbuf, &sci->sc_segbufs, sb_list) { | 1551 | list_for_each_entry(segbuf, &sci->sc_segbufs, sb_list) { |
1559 | ret = nilfs_sufile_get_segment_usage(sufile, segbuf->sb_segnum, | 1552 | ret = nilfs_sufile_get_segment_usage(sufile, segbuf->sb_segnum, |
1560 | &raw_su, &bh_su); | 1553 | &raw_su, &bh_su); |
1561 | BUG_ON(ret); /* always succeed because bh_su is dirty */ | 1554 | WARN_ON(ret); /* always succeed because bh_su is dirty */ |
1562 | live_blocks = segbuf->sb_sum.nblocks + | 1555 | live_blocks = segbuf->sb_sum.nblocks + |
1563 | (segbuf->sb_pseg_start - segbuf->sb_fseg_start); | 1556 | (segbuf->sb_pseg_start - segbuf->sb_fseg_start); |
1564 | raw_su->su_lastmod = cpu_to_le64(sci->sc_seg_ctime); | 1557 | raw_su->su_lastmod = cpu_to_le64(sci->sc_seg_ctime); |
@@ -1579,7 +1572,7 @@ static void nilfs_segctor_cancel_segusage(struct nilfs_sc_info *sci, | |||
1579 | segbuf = NILFS_FIRST_SEGBUF(&sci->sc_segbufs); | 1572 | segbuf = NILFS_FIRST_SEGBUF(&sci->sc_segbufs); |
1580 | ret = nilfs_sufile_get_segment_usage(sufile, segbuf->sb_segnum, | 1573 | ret = nilfs_sufile_get_segment_usage(sufile, segbuf->sb_segnum, |
1581 | &raw_su, &bh_su); | 1574 | &raw_su, &bh_su); |
1582 | BUG_ON(ret); /* always succeed because bh_su is dirty */ | 1575 | WARN_ON(ret); /* always succeed because bh_su is dirty */ |
1583 | raw_su->su_nblocks = cpu_to_le32(segbuf->sb_pseg_start - | 1576 | raw_su->su_nblocks = cpu_to_le32(segbuf->sb_pseg_start - |
1584 | segbuf->sb_fseg_start); | 1577 | segbuf->sb_fseg_start); |
1585 | nilfs_sufile_put_segment_usage(sufile, segbuf->sb_segnum, bh_su); | 1578 | nilfs_sufile_put_segment_usage(sufile, segbuf->sb_segnum, bh_su); |
@@ -1587,7 +1580,7 @@ static void nilfs_segctor_cancel_segusage(struct nilfs_sc_info *sci, | |||
1587 | list_for_each_entry_continue(segbuf, &sci->sc_segbufs, sb_list) { | 1580 | list_for_each_entry_continue(segbuf, &sci->sc_segbufs, sb_list) { |
1588 | ret = nilfs_sufile_get_segment_usage(sufile, segbuf->sb_segnum, | 1581 | ret = nilfs_sufile_get_segment_usage(sufile, segbuf->sb_segnum, |
1589 | &raw_su, &bh_su); | 1582 | &raw_su, &bh_su); |
1590 | BUG_ON(ret); /* always succeed */ | 1583 | WARN_ON(ret); /* always succeed */ |
1591 | raw_su->su_nblocks = 0; | 1584 | raw_su->su_nblocks = 0; |
1592 | nilfs_sufile_put_segment_usage(sufile, segbuf->sb_segnum, | 1585 | nilfs_sufile_put_segment_usage(sufile, segbuf->sb_segnum, |
1593 | bh_su); | 1586 | bh_su); |
@@ -1606,7 +1599,7 @@ static void nilfs_segctor_truncate_segments(struct nilfs_sc_info *sci, | |||
1606 | list_del_init(&segbuf->sb_list); | 1599 | list_del_init(&segbuf->sb_list); |
1607 | sci->sc_segbuf_nblocks -= segbuf->sb_rest_blocks; | 1600 | sci->sc_segbuf_nblocks -= segbuf->sb_rest_blocks; |
1608 | ret = nilfs_sufile_free(sufile, segbuf->sb_nextnum); | 1601 | ret = nilfs_sufile_free(sufile, segbuf->sb_nextnum); |
1609 | BUG_ON(ret); | 1602 | WARN_ON(ret); |
1610 | nilfs_segbuf_free(segbuf); | 1603 | nilfs_segbuf_free(segbuf); |
1611 | } | 1604 | } |
1612 | } | 1605 | } |
@@ -1923,7 +1916,6 @@ static int nilfs_page_has_uncleared_buffer(struct page *page) | |||
1923 | 1916 | ||
1924 | static void __nilfs_end_page_io(struct page *page, int err) | 1917 | static void __nilfs_end_page_io(struct page *page, int err) |
1925 | { | 1918 | { |
1926 | /* BUG_ON(err > 0); */ | ||
1927 | if (!err) { | 1919 | if (!err) { |
1928 | if (!nilfs_page_buffers_clean(page)) | 1920 | if (!nilfs_page_buffers_clean(page)) |
1929 | __set_page_dirty_nobuffers(page); | 1921 | __set_page_dirty_nobuffers(page); |
@@ -2262,7 +2254,7 @@ static int nilfs_segctor_deactivate_segments(struct nilfs_sc_info *sci, | |||
2262 | if (unlikely(err)) | 2254 | if (unlikely(err)) |
2263 | goto failed; | 2255 | goto failed; |
2264 | nilfs_segment_usage_clear_active(ent->raw_su); | 2256 | nilfs_segment_usage_clear_active(ent->raw_su); |
2265 | BUG_ON(!buffer_dirty(ent->bh_su)); | 2257 | WARN_ON(!buffer_dirty(ent->bh_su)); |
2266 | } | 2258 | } |
2267 | return 0; | 2259 | return 0; |
2268 | 2260 | ||
@@ -2340,7 +2332,6 @@ static int nilfs_segctor_do_construct(struct nilfs_sc_info *sci, int mode) | |||
2340 | /* Avoid empty segment */ | 2332 | /* Avoid empty segment */ |
2341 | if (sci->sc_stage.scnt == NILFS_ST_DONE && | 2333 | if (sci->sc_stage.scnt == NILFS_ST_DONE && |
2342 | NILFS_SEG_EMPTY(&sci->sc_curseg->sb_sum)) { | 2334 | NILFS_SEG_EMPTY(&sci->sc_curseg->sb_sum)) { |
2343 | BUG_ON(mode == SC_LSEG_SR); | ||
2344 | nilfs_segctor_end_construction(sci, nilfs, 1); | 2335 | nilfs_segctor_end_construction(sci, nilfs, 1); |
2345 | goto out; | 2336 | goto out; |
2346 | } | 2337 | } |
@@ -2479,9 +2470,8 @@ int nilfs_segctor_add_segments_to_be_freed(struct nilfs_sc_info *sci, | |||
2479 | struct inode *sufile = nilfs->ns_sufile; | 2470 | struct inode *sufile = nilfs->ns_sufile; |
2480 | LIST_HEAD(list); | 2471 | LIST_HEAD(list); |
2481 | __u64 *pnum; | 2472 | __u64 *pnum; |
2482 | const char *flag_name; | ||
2483 | size_t i; | 2473 | size_t i; |
2484 | int err, err2 = 0; | 2474 | int err; |
2485 | 2475 | ||
2486 | for (pnum = segnum, i = 0; i < nsegs; pnum++, i++) { | 2476 | for (pnum = segnum, i = 0; i < nsegs; pnum++, i++) { |
2487 | ent = nilfs_alloc_segment_entry(*pnum); | 2477 | ent = nilfs_alloc_segment_entry(*pnum); |
@@ -2495,32 +2485,12 @@ int nilfs_segctor_add_segments_to_be_freed(struct nilfs_sc_info *sci, | |||
2495 | if (unlikely(err)) | 2485 | if (unlikely(err)) |
2496 | goto failed; | 2486 | goto failed; |
2497 | 2487 | ||
2498 | if (unlikely(le32_to_cpu(ent->raw_su->su_flags) != | 2488 | if (unlikely(!nilfs_segment_usage_dirty(ent->raw_su))) |
2499 | (1UL << NILFS_SEGMENT_USAGE_DIRTY))) { | 2489 | printk(KERN_WARNING "NILFS: unused segment is " |
2500 | if (nilfs_segment_usage_clean(ent->raw_su)) | 2490 | "requested to be cleaned (segnum=%llu)\n", |
2501 | flag_name = "clean"; | 2491 | (unsigned long long)ent->segnum); |
2502 | else if (nilfs_segment_usage_active(ent->raw_su)) | ||
2503 | flag_name = "active"; | ||
2504 | else if (nilfs_segment_usage_volatile_active( | ||
2505 | ent->raw_su)) | ||
2506 | flag_name = "volatile active"; | ||
2507 | else if (!nilfs_segment_usage_dirty(ent->raw_su)) | ||
2508 | flag_name = "non-dirty"; | ||
2509 | else | ||
2510 | flag_name = "erroneous"; | ||
2511 | |||
2512 | printk(KERN_ERR | ||
2513 | "NILFS: %s segment is requested to be cleaned " | ||
2514 | "(segnum=%llu)\n", | ||
2515 | flag_name, (unsigned long long)ent->segnum); | ||
2516 | err2 = -EINVAL; | ||
2517 | } | ||
2518 | nilfs_close_segment_entry(ent, sufile); | 2492 | nilfs_close_segment_entry(ent, sufile); |
2519 | } | 2493 | } |
2520 | if (unlikely(err2)) { | ||
2521 | err = err2; | ||
2522 | goto failed; | ||
2523 | } | ||
2524 | list_splice(&list, sci->sc_cleaning_segments.prev); | 2494 | list_splice(&list, sci->sc_cleaning_segments.prev); |
2525 | return 0; | 2495 | return 0; |
2526 | 2496 | ||
@@ -2705,8 +2675,6 @@ struct nilfs_segctor_req { | |||
2705 | static void nilfs_segctor_accept(struct nilfs_sc_info *sci, | 2675 | static void nilfs_segctor_accept(struct nilfs_sc_info *sci, |
2706 | struct nilfs_segctor_req *req) | 2676 | struct nilfs_segctor_req *req) |
2707 | { | 2677 | { |
2708 | BUG_ON(!sci); | ||
2709 | |||
2710 | req->sc_err = req->sb_err = 0; | 2678 | req->sc_err = req->sb_err = 0; |
2711 | spin_lock(&sci->sc_state_lock); | 2679 | spin_lock(&sci->sc_state_lock); |
2712 | req->seq_accepted = sci->sc_seq_request; | 2680 | req->seq_accepted = sci->sc_seq_request; |
@@ -3107,7 +3075,7 @@ static void nilfs_segctor_destroy(struct nilfs_sc_info *sci) | |||
3107 | if (flag || nilfs_segctor_confirm(sci)) | 3075 | if (flag || nilfs_segctor_confirm(sci)) |
3108 | nilfs_segctor_write_out(sci); | 3076 | nilfs_segctor_write_out(sci); |
3109 | 3077 | ||
3110 | BUG_ON(!list_empty(&sci->sc_copied_buffers)); | 3078 | WARN_ON(!list_empty(&sci->sc_copied_buffers)); |
3111 | 3079 | ||
3112 | if (!list_empty(&sci->sc_dirty_files)) { | 3080 | if (!list_empty(&sci->sc_dirty_files)) { |
3113 | nilfs_warning(sbi->s_super, __func__, | 3081 | nilfs_warning(sbi->s_super, __func__, |
@@ -3120,7 +3088,7 @@ static void nilfs_segctor_destroy(struct nilfs_sc_info *sci) | |||
3120 | if (!list_empty(&sci->sc_cleaning_segments)) | 3088 | if (!list_empty(&sci->sc_cleaning_segments)) |
3121 | nilfs_dispose_segment_list(&sci->sc_cleaning_segments); | 3089 | nilfs_dispose_segment_list(&sci->sc_cleaning_segments); |
3122 | 3090 | ||
3123 | BUG_ON(!list_empty(&sci->sc_segbufs)); | 3091 | WARN_ON(!list_empty(&sci->sc_segbufs)); |
3124 | 3092 | ||
3125 | if (sci->sc_sketch_inode) { | 3093 | if (sci->sc_sketch_inode) { |
3126 | iput(sci->sc_sketch_inode); | 3094 | iput(sci->sc_sketch_inode); |