diff mbox

ext4: trigger the lazy inode table initialization after resize

Message ID 1358084571-3042-1-git-send-email-tytso@mit.edu
State Accepted, archived
Headers show

Commit Message

Theodore Ts'o Jan. 13, 2013, 1:42 p.m. UTC
After we have finished extending the file system, we need to trigger a
the lazy inode table thread to zero out the inode tables.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
---
 fs/ext4/ext4.h   |  2 ++
 fs/ext4/ioctl.c  |  9 +++++++++
 fs/ext4/resize.c |  8 +++++---
 fs/ext4/super.c  | 21 +++++++++++----------
 4 files changed, 27 insertions(+), 13 deletions(-)

Comments

Carlos Maiolino Jan. 14, 2013, 1:04 p.m. UTC | #1
Hi,

> @@ -358,6 +361,7 @@ group_add_out:
>  		ext4_fsblk_t n_blocks_count;
>  		struct super_block *sb = inode->i_sb;
>  		int err = 0, err2 = 0;
> +		ext4_group_t o_group = EXT4_SB(sb)->s_groups_count;
>  
>  		if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
>  			       EXT4_FEATURE_RO_COMPAT_BIGALLOC)) {
> @@ -388,6 +392,11 @@ group_add_out:
>  		if (err == 0)
>  			err = err2;
>  		mnt_drop_write_file(filp);
> +		if (!err && (o_group > EXT4_SB(sb)->s_groups_count) &&

Maybe a n00b question Ted, but can o_group here be bigger than ->s_groups_count
in any chance? 


The patch looks good,

Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Theodore Ts'o Jan. 14, 2013, 2:33 p.m. UTC | #2
On Mon, Jan 14, 2013 at 11:04:15AM -0200, Carlos Maiolino wrote:
> > @@ -388,6 +392,11 @@ group_add_out:
> >  		if (err == 0)
> >  			err = err2;
> >  		mnt_drop_write_file(filp);
> > +		if (!err && (o_group > EXT4_SB(sb)->s_groups_count) &&
> 
> Maybe a n00b question Ted, but can o_group here be bigger than ->s_groups_count
> in any chance? 

o_group can never be smaller than s_groups_count (since we don't
support online shrink).  o_group can be larger than s_groups_count if
ext4_resize_fs() has added one or more block groups to the file system
--- which is when we might need to kick off the lazy init thread.

Cheers,

						- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Carlos Maiolino Jan. 14, 2013, 2:42 p.m. UTC | #3
On Mon, Jan 14, 2013 at 09:33:17AM -0500, Theodore Ts'o wrote:
> On Mon, Jan 14, 2013 at 11:04:15AM -0200, Carlos Maiolino wrote:
> > > @@ -388,6 +392,11 @@ group_add_out:
> > >  		if (err == 0)
> > >  			err = err2;
> > >  		mnt_drop_write_file(filp);
> > > +		if (!err && (o_group > EXT4_SB(sb)->s_groups_count) &&
> > 
> > Maybe a n00b question Ted, but can o_group here be bigger than ->s_groups_count
> > in any chance? 
> 
> o_group can never be smaller than s_groups_count (since we don't
> support online shrink).  o_group can be larger than s_groups_count if
> ext4_resize_fs() has added one or more block groups to the file system
> --- which is when we might need to kick off the lazy init thread.
> 
Thanks to catch the right question :)

> Cheers,
> 
> 						- Ted
Carlos Maiolino Jan. 14, 2013, 2:45 p.m. UTC | #4
On Mon, Jan 14, 2013 at 09:33:17AM -0500, Theodore Ts'o wrote:
> On Mon, Jan 14, 2013 at 11:04:15AM -0200, Carlos Maiolino wrote:
> > > @@ -388,6 +392,11 @@ group_add_out:
> > >  		if (err == 0)
> > >  			err = err2;
> > >  		mnt_drop_write_file(filp);
> > > +		if (!err && (o_group > EXT4_SB(sb)->s_groups_count) &&
> > 
> > Maybe a n00b question Ted, but can o_group here be bigger than ->s_groups_count
> > in any chance? 
> 
> o_group can never be smaller than s_groups_count (since we don't
> support online shrink).  o_group can be larger than s_groups_count if
> ext4_resize_fs() has added one or more block groups to the file system
> --- which is when we might need to kick off the lazy init thread.
> 
> Cheers,
> 
s/bigger/smaller

Thanks to catch the right question.
diff mbox

Patch

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 8462eb3..8024623 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2227,6 +2227,8 @@  extern int ext4_group_desc_csum_verify(struct super_block *sb, __u32 group,
 				       struct ext4_group_desc *gdp);
 extern void ext4_group_desc_csum_set(struct super_block *sb, __u32 group,
 				     struct ext4_group_desc *gdp);
+extern int ext4_register_li_request(struct super_block *sb,
+				    ext4_group_t first_not_zeroed);
 
 static inline int ext4_has_group_desc_csum(struct super_block *sb)
 {
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 5747f52..4784ac2 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -313,6 +313,9 @@  mext_out:
 		if (err == 0)
 			err = err2;
 		mnt_drop_write_file(filp);
+		if (!err && ext4_has_group_desc_csum(sb) &&
+		    test_opt(sb, INIT_INODE_TABLE))
+			err = ext4_register_li_request(sb, input.group);
 group_add_out:
 		ext4_resize_end(sb);
 		return err;
@@ -358,6 +361,7 @@  group_add_out:
 		ext4_fsblk_t n_blocks_count;
 		struct super_block *sb = inode->i_sb;
 		int err = 0, err2 = 0;
+		ext4_group_t o_group = EXT4_SB(sb)->s_groups_count;
 
 		if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
 			       EXT4_FEATURE_RO_COMPAT_BIGALLOC)) {
@@ -388,6 +392,11 @@  group_add_out:
 		if (err == 0)
 			err = err2;
 		mnt_drop_write_file(filp);
+		if (!err && (o_group > EXT4_SB(sb)->s_groups_count) &&
+		    ext4_has_group_desc_csum(sb) &&
+		    test_opt(sb, INIT_INODE_TABLE))
+			err = ext4_register_li_request(sb, o_group);
+
 resizefs_out:
 		ext4_resize_end(sb);
 		return err;
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index 05f8d45..8eefb63 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -1506,10 +1506,12 @@  static int ext4_setup_next_flex_gd(struct super_block *sb,
 		group_data[i].blocks_count = blocks_per_group;
 		overhead = ext4_group_overhead_blocks(sb, group + i);
 		group_data[i].free_blocks_count = blocks_per_group - overhead;
-		if (ext4_has_group_desc_csum(sb))
+		if (ext4_has_group_desc_csum(sb)) {
 			flex_gd->bg_flags[i] = EXT4_BG_BLOCK_UNINIT |
 					       EXT4_BG_INODE_UNINIT;
-		else
+			if (!test_opt(sb, INIT_INODE_TABLE))
+				flex_gd->bg_flags[i] |= EXT4_BG_INODE_ZEROED;
+		} else
 			flex_gd->bg_flags[i] = EXT4_BG_INODE_ZEROED;
 	}
 
@@ -1594,7 +1596,7 @@  int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
 
 	err = ext4_alloc_flex_bg_array(sb, input->group + 1);
 	if (err)
-		return err;
+		goto out;
 
 	err = ext4_mb_alloc_groupinfo(sb, input->group + 1);
 	if (err)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 3d4fb81..c014edd 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -2776,7 +2776,7 @@  static int ext4_run_li_request(struct ext4_li_request *elr)
 			break;
 	}
 
-	if (group == ngroups)
+	if (group >= ngroups)
 		ret = 1;
 
 	if (!ret) {
@@ -3016,33 +3016,34 @@  static struct ext4_li_request *ext4_li_request_new(struct super_block *sb,
 	return elr;
 }
 
-static int ext4_register_li_request(struct super_block *sb,
-				    ext4_group_t first_not_zeroed)
+int ext4_register_li_request(struct super_block *sb,
+			     ext4_group_t first_not_zeroed)
 {
 	struct ext4_sb_info *sbi = EXT4_SB(sb);
-	struct ext4_li_request *elr;
+	struct ext4_li_request *elr = NULL;
 	ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count;
 	int ret = 0;
 
+	mutex_lock(&ext4_li_mtx);
 	if (sbi->s_li_request != NULL) {
 		/*
 		 * Reset timeout so it can be computed again, because
 		 * s_li_wait_mult might have changed.
 		 */
 		sbi->s_li_request->lr_timeout = 0;
-		return 0;
+		goto out;
 	}
 
 	if (first_not_zeroed == ngroups ||
 	    (sb->s_flags & MS_RDONLY) ||
 	    !test_opt(sb, INIT_INODE_TABLE))
-		return 0;
+		goto out;
 
 	elr = ext4_li_request_new(sb, first_not_zeroed);
-	if (!elr)
-		return -ENOMEM;
-
-	mutex_lock(&ext4_li_mtx);
+	if (!elr) {
+		ret = -ENOMEM;
+		goto out;
+	}
 
 	if (NULL == ext4_li_info) {
 		ret = ext4_li_info_new();