Skip to content

Commit cc7365d

Browse files
xiaoqiangnktytso
authored andcommitted
ext4: let ext4_group_add_blocks() return an error code
This patch lets ext4_group_add_blocks() return an error code if it fails, so that upper functions can handle error correctly. Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent 0529155 commit cc7365d

3 files changed

Lines changed: 23 additions & 9 deletions

File tree

‎fs/ext4/ext4.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1799,7 +1799,7 @@ extern void ext4_free_blocks(handle_t *handle, struct inode *inode,
17991799
unsigned long count, int flags);
18001800
extern int ext4_mb_add_groupinfo(struct super_block *sb,
18011801
ext4_group_t i, struct ext4_group_desc *desc);
1802-
extern void ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
1802+
extern int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
18031803
ext4_fsblk_t block, unsigned long count);
18041804
extern int ext4_trim_fs(struct super_block *, struct fstrim_range *);
18051805

‎fs/ext4/mballoc.c‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4675,7 +4675,7 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode,
46754675
*
46764676
* This marks the blocks as free in the bitmap and buddy.
46774677
*/
4678-
void ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
4678+
int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
46794679
ext4_fsblk_t block, unsigned long count)
46804680
{
46814681
struct buffer_head *bitmap_bh = NULL;
@@ -4696,15 +4696,24 @@ void ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
46964696
* Check to see if we are freeing blocks across a group
46974697
* boundary.
46984698
*/
4699-
if (bit + count > EXT4_BLOCKS_PER_GROUP(sb))
4699+
if (bit + count > EXT4_BLOCKS_PER_GROUP(sb)) {
4700+
ext4_warning(sb, "too much blocks added to group %u\n",
4701+
block_group);
4702+
err = -EINVAL;
47004703
goto error_return;
4704+
}
47014705

47024706
bitmap_bh = ext4_read_block_bitmap(sb, block_group);
4703-
if (!bitmap_bh)
4707+
if (!bitmap_bh) {
4708+
err = -EIO;
47044709
goto error_return;
4710+
}
4711+
47054712
desc = ext4_get_group_desc(sb, block_group, &gd_bh);
4706-
if (!desc)
4713+
if (!desc) {
4714+
err = -EIO;
47074715
goto error_return;
4716+
}
47084717

47094718
if (in_range(ext4_block_bitmap(sb, desc), block, count) ||
47104719
in_range(ext4_inode_bitmap(sb, desc), block, count) ||
@@ -4714,6 +4723,7 @@ void ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
47144723
ext4_error(sb, "Adding blocks in system zones - "
47154724
"Block = %llu, count = %lu",
47164725
block, count);
4726+
err = -EINVAL;
47174727
goto error_return;
47184728
}
47194729

@@ -4782,7 +4792,7 @@ void ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
47824792
error_return:
47834793
brelse(bitmap_bh);
47844794
ext4_std_error(sb, err);
4785-
return;
4795+
return err;
47864796
}
47874797

47884798
/**

‎fs/ext4/resize.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
980980
ext4_grpblk_t add;
981981
struct buffer_head *bh;
982982
handle_t *handle;
983-
int err;
983+
int err, err2;
984984
ext4_group_t group;
985985

986986
o_blocks_count = ext4_blocks_count(es);
@@ -1056,11 +1056,15 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
10561056
ext4_debug("freeing blocks %llu through %llu\n", o_blocks_count,
10571057
o_blocks_count + add);
10581058
/* We add the blocks to the bitmap and set the group need init bit */
1059-
ext4_group_add_blocks(handle, sb, o_blocks_count, add);
1059+
err = ext4_group_add_blocks(handle, sb, o_blocks_count, add);
10601060
ext4_handle_dirty_super(handle, sb);
10611061
ext4_debug("freed blocks %llu through %llu\n", o_blocks_count,
10621062
o_blocks_count + add);
1063-
if ((err = ext4_journal_stop(handle)))
1063+
err2 = ext4_journal_stop(handle);
1064+
if (!err && err2)
1065+
err = err2;
1066+
1067+
if (err)
10641068
goto exit_put;
10651069

10661070
if (test_opt(sb, DEBUG))

0 commit comments

Comments
 (0)