aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ext4')
-rw-r--r--fs/ext4/inode.c5
-rw-r--r--fs/ext4/namei.c5
-rw-r--r--fs/ext4/resize.c28
-rw-r--r--fs/ext4/super.c17
-rw-r--r--fs/ext4/xattr.c27
5 files changed, 51 insertions, 31 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 05f01fbd9c7f..22a9d8159720 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -5835,9 +5835,10 @@ int ext4_mark_iloc_dirty(handle_t *handle,
5835{ 5835{
5836 int err = 0; 5836 int err = 0;
5837 5837
5838 if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb)))) 5838 if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb)))) {
5839 put_bh(iloc->bh);
5839 return -EIO; 5840 return -EIO;
5840 5841 }
5841 if (IS_I_VERSION(inode)) 5842 if (IS_I_VERSION(inode))
5842 inode_inc_iversion(inode); 5843 inode_inc_iversion(inode);
5843 5844
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 17adcb16a9c8..437f71fe83ae 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -126,6 +126,7 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode,
126 if (!is_dx_block && type == INDEX) { 126 if (!is_dx_block && type == INDEX) {
127 ext4_error_inode(inode, func, line, block, 127 ext4_error_inode(inode, func, line, block,
128 "directory leaf block found instead of index block"); 128 "directory leaf block found instead of index block");
129 brelse(bh);
129 return ERR_PTR(-EFSCORRUPTED); 130 return ERR_PTR(-EFSCORRUPTED);
130 } 131 }
131 if (!ext4_has_metadata_csum(inode->i_sb) || 132 if (!ext4_has_metadata_csum(inode->i_sb) ||
@@ -2811,7 +2812,9 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode)
2811 list_del_init(&EXT4_I(inode)->i_orphan); 2812 list_del_init(&EXT4_I(inode)->i_orphan);
2812 mutex_unlock(&sbi->s_orphan_lock); 2813 mutex_unlock(&sbi->s_orphan_lock);
2813 } 2814 }
2814 } 2815 } else
2816 brelse(iloc.bh);
2817
2815 jbd_debug(4, "superblock will point to %lu\n", inode->i_ino); 2818 jbd_debug(4, "superblock will point to %lu\n", inode->i_ino);
2816 jbd_debug(4, "orphan inode %lu will point to %d\n", 2819 jbd_debug(4, "orphan inode %lu will point to %d\n",
2817 inode->i_ino, NEXT_ORPHAN(inode)); 2820 inode->i_ino, NEXT_ORPHAN(inode));
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index ebbc663d0798..a5efee34415f 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -459,16 +459,18 @@ static int set_flexbg_block_bitmap(struct super_block *sb, handle_t *handle,
459 459
460 BUFFER_TRACE(bh, "get_write_access"); 460 BUFFER_TRACE(bh, "get_write_access");
461 err = ext4_journal_get_write_access(handle, bh); 461 err = ext4_journal_get_write_access(handle, bh);
462 if (err) 462 if (err) {
463 brelse(bh);
463 return err; 464 return err;
465 }
464 ext4_debug("mark block bitmap %#04llx (+%llu/%u)\n", 466 ext4_debug("mark block bitmap %#04llx (+%llu/%u)\n",
465 first_cluster, first_cluster - start, count2); 467 first_cluster, first_cluster - start, count2);
466 ext4_set_bits(bh->b_data, first_cluster - start, count2); 468 ext4_set_bits(bh->b_data, first_cluster - start, count2);
467 469
468 err = ext4_handle_dirty_metadata(handle, NULL, bh); 470 err = ext4_handle_dirty_metadata(handle, NULL, bh);
471 brelse(bh);
469 if (unlikely(err)) 472 if (unlikely(err))
470 return err; 473 return err;
471 brelse(bh);
472 } 474 }
473 475
474 return 0; 476 return 0;
@@ -605,7 +607,6 @@ handle_bb:
605 bh = bclean(handle, sb, block); 607 bh = bclean(handle, sb, block);
606 if (IS_ERR(bh)) { 608 if (IS_ERR(bh)) {
607 err = PTR_ERR(bh); 609 err = PTR_ERR(bh);
608 bh = NULL;
609 goto out; 610 goto out;
610 } 611 }
611 overhead = ext4_group_overhead_blocks(sb, group); 612 overhead = ext4_group_overhead_blocks(sb, group);
@@ -618,9 +619,9 @@ handle_bb:
618 ext4_mark_bitmap_end(EXT4_B2C(sbi, group_data[i].blocks_count), 619 ext4_mark_bitmap_end(EXT4_B2C(sbi, group_data[i].blocks_count),
619 sb->s_blocksize * 8, bh->b_data); 620 sb->s_blocksize * 8, bh->b_data);
620 err = ext4_handle_dirty_metadata(handle, NULL, bh); 621 err = ext4_handle_dirty_metadata(handle, NULL, bh);
622 brelse(bh);
621 if (err) 623 if (err)
622 goto out; 624 goto out;
623 brelse(bh);
624 625
625handle_ib: 626handle_ib:
626 if (bg_flags[i] & EXT4_BG_INODE_UNINIT) 627 if (bg_flags[i] & EXT4_BG_INODE_UNINIT)
@@ -635,18 +636,16 @@ handle_ib:
635 bh = bclean(handle, sb, block); 636 bh = bclean(handle, sb, block);
636 if (IS_ERR(bh)) { 637 if (IS_ERR(bh)) {
637 err = PTR_ERR(bh); 638 err = PTR_ERR(bh);
638 bh = NULL;
639 goto out; 639 goto out;
640 } 640 }
641 641
642 ext4_mark_bitmap_end(EXT4_INODES_PER_GROUP(sb), 642 ext4_mark_bitmap_end(EXT4_INODES_PER_GROUP(sb),
643 sb->s_blocksize * 8, bh->b_data); 643 sb->s_blocksize * 8, bh->b_data);
644 err = ext4_handle_dirty_metadata(handle, NULL, bh); 644 err = ext4_handle_dirty_metadata(handle, NULL, bh);
645 brelse(bh);
645 if (err) 646 if (err)
646 goto out; 647 goto out;
647 brelse(bh);
648 } 648 }
649 bh = NULL;
650 649
651 /* Mark group tables in block bitmap */ 650 /* Mark group tables in block bitmap */
652 for (j = 0; j < GROUP_TABLE_COUNT; j++) { 651 for (j = 0; j < GROUP_TABLE_COUNT; j++) {
@@ -685,7 +684,6 @@ handle_ib:
685 } 684 }
686 685
687out: 686out:
688 brelse(bh);
689 err2 = ext4_journal_stop(handle); 687 err2 = ext4_journal_stop(handle);
690 if (err2 && !err) 688 if (err2 && !err)
691 err = err2; 689 err = err2;
@@ -873,6 +871,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
873 err = ext4_handle_dirty_metadata(handle, NULL, gdb_bh); 871 err = ext4_handle_dirty_metadata(handle, NULL, gdb_bh);
874 if (unlikely(err)) { 872 if (unlikely(err)) {
875 ext4_std_error(sb, err); 873 ext4_std_error(sb, err);
874 iloc.bh = NULL;
876 goto exit_inode; 875 goto exit_inode;
877 } 876 }
878 brelse(dind); 877 brelse(dind);
@@ -924,6 +923,7 @@ static int add_new_gdb_meta_bg(struct super_block *sb,
924 sizeof(struct buffer_head *), 923 sizeof(struct buffer_head *),
925 GFP_NOFS); 924 GFP_NOFS);
926 if (!n_group_desc) { 925 if (!n_group_desc) {
926 brelse(gdb_bh);
927 err = -ENOMEM; 927 err = -ENOMEM;
928 ext4_warning(sb, "not enough memory for %lu groups", 928 ext4_warning(sb, "not enough memory for %lu groups",
929 gdb_num + 1); 929 gdb_num + 1);
@@ -939,8 +939,6 @@ static int add_new_gdb_meta_bg(struct super_block *sb,
939 kvfree(o_group_desc); 939 kvfree(o_group_desc);
940 BUFFER_TRACE(gdb_bh, "get_write_access"); 940 BUFFER_TRACE(gdb_bh, "get_write_access");
941 err = ext4_journal_get_write_access(handle, gdb_bh); 941 err = ext4_journal_get_write_access(handle, gdb_bh);
942 if (unlikely(err))
943 brelse(gdb_bh);
944 return err; 942 return err;
945} 943}
946 944
@@ -1124,8 +1122,10 @@ static void update_backups(struct super_block *sb, sector_t blk_off, char *data,
1124 backup_block, backup_block - 1122 backup_block, backup_block -
1125 ext4_group_first_block_no(sb, group)); 1123 ext4_group_first_block_no(sb, group));
1126 BUFFER_TRACE(bh, "get_write_access"); 1124 BUFFER_TRACE(bh, "get_write_access");
1127 if ((err = ext4_journal_get_write_access(handle, bh))) 1125 if ((err = ext4_journal_get_write_access(handle, bh))) {
1126 brelse(bh);
1128 break; 1127 break;
1128 }
1129 lock_buffer(bh); 1129 lock_buffer(bh);
1130 memcpy(bh->b_data, data, size); 1130 memcpy(bh->b_data, data, size);
1131 if (rest) 1131 if (rest)
@@ -2023,7 +2023,7 @@ retry:
2023 2023
2024 err = ext4_alloc_flex_bg_array(sb, n_group + 1); 2024 err = ext4_alloc_flex_bg_array(sb, n_group + 1);
2025 if (err) 2025 if (err)
2026 return err; 2026 goto out;
2027 2027
2028 err = ext4_mb_alloc_groupinfo(sb, n_group + 1); 2028 err = ext4_mb_alloc_groupinfo(sb, n_group + 1);
2029 if (err) 2029 if (err)
@@ -2059,6 +2059,10 @@ retry:
2059 n_blocks_count_retry = 0; 2059 n_blocks_count_retry = 0;
2060 free_flex_gd(flex_gd); 2060 free_flex_gd(flex_gd);
2061 flex_gd = NULL; 2061 flex_gd = NULL;
2062 if (resize_inode) {
2063 iput(resize_inode);
2064 resize_inode = NULL;
2065 }
2062 goto retry; 2066 goto retry;
2063 } 2067 }
2064 2068
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index a221f1cdf704..53ff6c2a26ed 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -4075,6 +4075,14 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
4075 sbi->s_groups_count = blocks_count; 4075 sbi->s_groups_count = blocks_count;
4076 sbi->s_blockfile_groups = min_t(ext4_group_t, sbi->s_groups_count, 4076 sbi->s_blockfile_groups = min_t(ext4_group_t, sbi->s_groups_count,
4077 (EXT4_MAX_BLOCK_FILE_PHYS / EXT4_BLOCKS_PER_GROUP(sb))); 4077 (EXT4_MAX_BLOCK_FILE_PHYS / EXT4_BLOCKS_PER_GROUP(sb)));
4078 if (((u64)sbi->s_groups_count * sbi->s_inodes_per_group) !=
4079 le32_to_cpu(es->s_inodes_count)) {
4080 ext4_msg(sb, KERN_ERR, "inodes count not valid: %u vs %llu",
4081 le32_to_cpu(es->s_inodes_count),
4082 ((u64)sbi->s_groups_count * sbi->s_inodes_per_group));
4083 ret = -EINVAL;
4084 goto failed_mount;
4085 }
4078 db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) / 4086 db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) /
4079 EXT4_DESC_PER_BLOCK(sb); 4087 EXT4_DESC_PER_BLOCK(sb);
4080 if (ext4_has_feature_meta_bg(sb)) { 4088 if (ext4_has_feature_meta_bg(sb)) {
@@ -4094,14 +4102,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
4094 ret = -ENOMEM; 4102 ret = -ENOMEM;
4095 goto failed_mount; 4103 goto failed_mount;
4096 } 4104 }
4097 if (((u64)sbi->s_groups_count * sbi->s_inodes_per_group) !=
4098 le32_to_cpu(es->s_inodes_count)) {
4099 ext4_msg(sb, KERN_ERR, "inodes count not valid: %u vs %llu",
4100 le32_to_cpu(es->s_inodes_count),
4101 ((u64)sbi->s_groups_count * sbi->s_inodes_per_group));
4102 ret = -EINVAL;
4103 goto failed_mount;
4104 }
4105 4105
4106 bgl_lock_init(sbi->s_blockgroup_lock); 4106 bgl_lock_init(sbi->s_blockgroup_lock);
4107 4107
@@ -4510,6 +4510,7 @@ failed_mount6:
4510 percpu_counter_destroy(&sbi->s_freeinodes_counter); 4510 percpu_counter_destroy(&sbi->s_freeinodes_counter);
4511 percpu_counter_destroy(&sbi->s_dirs_counter); 4511 percpu_counter_destroy(&sbi->s_dirs_counter);
4512 percpu_counter_destroy(&sbi->s_dirtyclusters_counter); 4512 percpu_counter_destroy(&sbi->s_dirtyclusters_counter);
4513 percpu_free_rwsem(&sbi->s_journal_flag_rwsem);
4513failed_mount5: 4514failed_mount5:
4514 ext4_ext_release(sb); 4515 ext4_ext_release(sb);
4515 ext4_release_system_zone(sb); 4516 ext4_release_system_zone(sb);
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index f36fc5d5b257..7643d52c776c 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -1031,10 +1031,8 @@ static int ext4_xattr_inode_update_ref(handle_t *handle, struct inode *ea_inode,
1031 inode_lock(ea_inode); 1031 inode_lock(ea_inode);
1032 1032
1033 ret = ext4_reserve_inode_write(handle, ea_inode, &iloc); 1033 ret = ext4_reserve_inode_write(handle, ea_inode, &iloc);
1034 if (ret) { 1034 if (ret)
1035 iloc.bh = NULL;
1036 goto out; 1035 goto out;
1037 }
1038 1036
1039 ref_count = ext4_xattr_inode_get_ref(ea_inode); 1037 ref_count = ext4_xattr_inode_get_ref(ea_inode);
1040 ref_count += ref_change; 1038 ref_count += ref_change;
@@ -1080,12 +1078,10 @@ static int ext4_xattr_inode_update_ref(handle_t *handle, struct inode *ea_inode,
1080 } 1078 }
1081 1079
1082 ret = ext4_mark_iloc_dirty(handle, ea_inode, &iloc); 1080 ret = ext4_mark_iloc_dirty(handle, ea_inode, &iloc);
1083 iloc.bh = NULL;
1084 if (ret) 1081 if (ret)
1085 ext4_warning_inode(ea_inode, 1082 ext4_warning_inode(ea_inode,
1086 "ext4_mark_iloc_dirty() failed ret=%d", ret); 1083 "ext4_mark_iloc_dirty() failed ret=%d", ret);
1087out: 1084out:
1088 brelse(iloc.bh);
1089 inode_unlock(ea_inode); 1085 inode_unlock(ea_inode);
1090 return ret; 1086 return ret;
1091} 1087}
@@ -1388,6 +1384,12 @@ retry:
1388 bh = ext4_getblk(handle, ea_inode, block, 0); 1384 bh = ext4_getblk(handle, ea_inode, block, 0);
1389 if (IS_ERR(bh)) 1385 if (IS_ERR(bh))
1390 return PTR_ERR(bh); 1386 return PTR_ERR(bh);
1387 if (!bh) {
1388 WARN_ON_ONCE(1);
1389 EXT4_ERROR_INODE(ea_inode,
1390 "ext4_getblk() return bh = NULL");
1391 return -EFSCORRUPTED;
1392 }
1391 ret = ext4_journal_get_write_access(handle, bh); 1393 ret = ext4_journal_get_write_access(handle, bh);
1392 if (ret) 1394 if (ret)
1393 goto out; 1395 goto out;
@@ -2276,8 +2278,10 @@ static struct buffer_head *ext4_xattr_get_block(struct inode *inode)
2276 if (!bh) 2278 if (!bh)
2277 return ERR_PTR(-EIO); 2279 return ERR_PTR(-EIO);
2278 error = ext4_xattr_check_block(inode, bh); 2280 error = ext4_xattr_check_block(inode, bh);
2279 if (error) 2281 if (error) {
2282 brelse(bh);
2280 return ERR_PTR(error); 2283 return ERR_PTR(error);
2284 }
2281 return bh; 2285 return bh;
2282} 2286}
2283 2287
@@ -2397,6 +2401,8 @@ retry_inode:
2397 error = ext4_xattr_block_set(handle, inode, &i, &bs); 2401 error = ext4_xattr_block_set(handle, inode, &i, &bs);
2398 } else if (error == -ENOSPC) { 2402 } else if (error == -ENOSPC) {
2399 if (EXT4_I(inode)->i_file_acl && !bs.s.base) { 2403 if (EXT4_I(inode)->i_file_acl && !bs.s.base) {
2404 brelse(bs.bh);
2405 bs.bh = NULL;
2400 error = ext4_xattr_block_find(inode, &i, &bs); 2406 error = ext4_xattr_block_find(inode, &i, &bs);
2401 if (error) 2407 if (error)
2402 goto cleanup; 2408 goto cleanup;
@@ -2617,6 +2623,8 @@ out:
2617 kfree(buffer); 2623 kfree(buffer);
2618 if (is) 2624 if (is)
2619 brelse(is->iloc.bh); 2625 brelse(is->iloc.bh);
2626 if (bs)
2627 brelse(bs->bh);
2620 kfree(is); 2628 kfree(is);
2621 kfree(bs); 2629 kfree(bs);
2622 2630
@@ -2696,7 +2704,6 @@ int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
2696 struct ext4_inode *raw_inode, handle_t *handle) 2704 struct ext4_inode *raw_inode, handle_t *handle)
2697{ 2705{
2698 struct ext4_xattr_ibody_header *header; 2706 struct ext4_xattr_ibody_header *header;
2699 struct buffer_head *bh;
2700 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 2707 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
2701 static unsigned int mnt_count; 2708 static unsigned int mnt_count;
2702 size_t min_offs; 2709 size_t min_offs;
@@ -2737,13 +2744,17 @@ retry:
2737 * EA block can hold new_extra_isize bytes. 2744 * EA block can hold new_extra_isize bytes.
2738 */ 2745 */
2739 if (EXT4_I(inode)->i_file_acl) { 2746 if (EXT4_I(inode)->i_file_acl) {
2747 struct buffer_head *bh;
2748
2740 bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl); 2749 bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
2741 error = -EIO; 2750 error = -EIO;
2742 if (!bh) 2751 if (!bh)
2743 goto cleanup; 2752 goto cleanup;
2744 error = ext4_xattr_check_block(inode, bh); 2753 error = ext4_xattr_check_block(inode, bh);
2745 if (error) 2754 if (error) {
2755 brelse(bh);
2746 goto cleanup; 2756 goto cleanup;
2757 }
2747 base = BHDR(bh); 2758 base = BHDR(bh);
2748 end = bh->b_data + bh->b_size; 2759 end = bh->b_data + bh->b_size;
2749 min_offs = end - base; 2760 min_offs = end - base;