Skip to content

Commit 59e31c1

Browse files
committed
ext4: fix online resizing when the # of block groups is constant
Commit 1c6bd71 introduced a regression where an online resize operation which did not change the number of block groups would fail, i.e: mke2fs -t /dev/vdc 60000 mount /dev/vdc resize2fs /dev/vdc 60001 This was due to a bug in the logic regarding when to try converting the filesystem to use meta_bg. Also fix up a number of other minor issues with the online resizing code: (a) Fix a sparse warning; (b) only check to make sure the device is large enough once, instead of multiple times through the resize loop. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent c9b9253 commit 59e31c1

1 file changed

Lines changed: 14 additions & 22 deletions

File tree

‎fs/ext4/resize.c‎

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,23 +1772,18 @@ static int ext4_convert_meta_bg(struct super_block *sb, struct inode *inode)
17721772
handle_t *handle;
17731773
struct ext4_sb_info *sbi = EXT4_SB(sb);
17741774
struct ext4_super_block *es = sbi->s_es;
1775-
struct ext4_inode_info *ei = 0;
1775+
struct ext4_inode_info *ei = EXT4_I(inode);
17761776
ext4_fsblk_t nr;
17771777
int i, ret, err = 0;
17781778
int credits = 1;
17791779

17801780
ext4_msg(sb, KERN_INFO, "Converting file system to meta_bg");
1781-
if (EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_RESIZE_INODE)) {
1781+
if (inode) {
17821782
if (es->s_reserved_gdt_blocks) {
17831783
ext4_error(sb, "Unexpected non-zero "
17841784
"s_reserved_gdt_blocks");
17851785
return -EPERM;
17861786
}
1787-
if (!inode) {
1788-
ext4_error(sb, "Unexpected NULL resize_inode");
1789-
return -EPERM;
1790-
}
1791-
ei = EXT4_I(inode);
17921787

17931788
/* Do a quick sanity check of the resize inode */
17941789
if (inode->i_blocks != 1 << (inode->i_blkbits - 9))
@@ -1873,12 +1868,19 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count)
18731868
int err = 0, flexbg_size = 1 << sbi->s_log_groups_per_flex;
18741869
int meta_bg;
18751870

1871+
/* See if the device is actually as big as what was requested */
1872+
bh = sb_bread(sb, n_blocks_count - 1);
1873+
if (!bh) {
1874+
ext4_warning(sb, "can't read last block, resize aborted");
1875+
return -ENOSPC;
1876+
}
1877+
brelse(bh);
1878+
18761879
retry:
18771880
o_blocks_count = ext4_blocks_count(es);
18781881

1879-
if (test_opt(sb, DEBUG))
1880-
ext4_msg(sb, KERN_DEBUG, "resizing filesystem from %llu "
1881-
"to %llu blocks", o_blocks_count, n_blocks_count);
1882+
ext4_msg(sb, KERN_INFO, "resizing filesystem from %llu "
1883+
"to %llu blocks", o_blocks_count, n_blocks_count);
18821884

18831885
if (n_blocks_count < o_blocks_count) {
18841886
/* On-line shrinking not supported */
@@ -1922,7 +1924,7 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count)
19221924
}
19231925
}
19241926

1925-
if ((!resize_inode && !meta_bg) || n_group == o_group) {
1927+
if ((!resize_inode && !meta_bg) || n_blocks_count == o_blocks_count) {
19261928
err = ext4_convert_meta_bg(sb, resize_inode);
19271929
if (err)
19281930
goto out;
@@ -1937,14 +1939,6 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count)
19371939
}
19381940
}
19391941

1940-
/* See if the device is actually as big as what was requested */
1941-
bh = sb_bread(sb, n_blocks_count - 1);
1942-
if (!bh) {
1943-
ext4_warning(sb, "can't read last block, resize aborted");
1944-
return -ENOSPC;
1945-
}
1946-
brelse(bh);
1947-
19481942
/* extend the last group */
19491943
if (n_group == o_group)
19501944
add = n_blocks_count - o_blocks_count;
@@ -2005,8 +1999,6 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count)
20051999
free_flex_gd(flex_gd);
20062000
if (resize_inode != NULL)
20072001
iput(resize_inode);
2008-
if (test_opt(sb, DEBUG))
2009-
ext4_msg(sb, KERN_DEBUG, "resized filesystem to %llu",
2010-
n_blocks_count);
2002+
ext4_msg(sb, KERN_INFO, "resized filesystem to %llu", n_blocks_count);
20112003
return err;
20122004
}

0 commit comments

Comments
 (0)