ext4: Protect group inode free counting with group lock.
PATCH 1/1 ext4: Protect group inode free counting with group lock.
From: Tao Ma <[email protected]>
Now when we set the group inode free count, we don't have a proper group lock so that multiple threads may decrease the inode free count at the same time. And e2fsck will complain something like:
Free inodes count wrong for group #1 (1, counted=0). Fix? no
Free inodes count wrong for group #2 (3, counted=0). Fix? no
Directories count wrong for group #2 (780, counted=779). Fix? no
Free inodes count wrong for group #3 (2272, counted=2273). Fix? no
So this patch try to protect it with the ext4_lock_group.
btw, it is found by xfstests test case 269 and I have run it 100 times and the error in e2fsck doesn't show up again.
--- fs/ext4/ialloc.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
fs/ext4/ialloc.c +5 -4
@@ -772,7 +772,9 @@ got:ext4_itable_unused_set (sb, gdp, (EXT4_INODES_PER_GROUP (sb) - ino));up_read (&grp->alloc_sem); - } + }else +ext4_lock_group (sb, group); +ext4_free_inodes_set (sb, gdp,ext4_free_inodes_count (sb, gdp) -1 );if (S_ISDIR (mode)) {ext4_used_dirs_set (sb, gdp,ext4_used_dirs_count (sb, gdp) +1 );
@@ -782,10 +784,9 @@ got:atomic_inc (&sbi->s_flex_groups[f].used_dirs); } } -if (EXT4_HAS_RO_COMPAT_FEATURE (sb,EXT4_FEATURE_RO_COMPAT_GDT_CSUM )) { +if (EXT4_HAS_RO_COMPAT_FEATURE (sb,EXT4_FEATURE_RO_COMPAT_GDT_CSUM )) gdp->bg_checksum =ext4_group_desc_csum (sbi, group, gdp); -ext4_unlock_group (sb, group); - } +ext4_unlock_group (sb, group);BUFFER_TRACE (inode_bitmap_bh,"call ext4_handle_dirty_metadata" ); err =ext4_handle_dirty_metadata (handle,NULL , inode_bitmap_bh);
Signature · 1 line
1.7.1
Quoted 5 lines · Tao Ma
From: Tao Ma <[email protected]>
Now when we set the group inode free count, we don't have a proper group lock so that multiple threads may decrease the inode free count at the same time. And e2fsck will complain something like:
This is only in the ! EXT4_FEATURE_RO_COMPAT_GDT_CSUM case I guess? That would be worth mentioning in the summary & changelog.
I guess you were testing without that for some reason?
-eric
Quoted 51 lines
Free inodes count wrong for group #1 (1, counted=0). Fix? no
Free inodes count wrong for group #2 (3, counted=0). Fix? no
Directories count wrong for group #2 (780, counted=779). Fix? no
Free inodes count wrong for group #3 (2272, counted=2273). Fix? no
So this patch try to protect it with the
ext4_lock_group.btw, it is found by xfstests test case 269 and I have run it 100 times and the error in e2fsck doesn't show up again.
Cc Theodore Ts'o <[email protected]>Signed-off-by Tao Ma <[email protected]>--- fs/ext4/ialloc.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)fs/ext4/ialloc.c +5
-4@@ -772,7 +772,9 @@ got:ext4_itable_unused_set (sb, gdp, (EXT4_INODES_PER_GROUP (sb) - ino));up_read (&grp->alloc_sem); - } + }else +ext4_lock_group (sb, group); +ext4_free_inodes_set (sb, gdp,ext4_free_inodes_count (sb, gdp) -1 );if (S_ISDIR (mode)) {ext4_used_dirs_set (sb, gdp,ext4_used_dirs_count (sb, gdp) +1 );@@ -782,10 +784,9 @@ got:atomic_inc (&sbi->s_flex_groups[f].used_dirs); } } -if (EXT4_HAS_RO_COMPAT_FEATURE (sb,EXT4_FEATURE_RO_COMPAT_GDT_CSUM )) { +if (EXT4_HAS_RO_COMPAT_FEATURE (sb,EXT4_FEATURE_RO_COMPAT_GDT_CSUM )) gdp->bg_checksum =ext4_group_desc_csum (sbi, group, gdp); -ext4_unlock_group (sb, group); - } +ext4_unlock_group (sb, group);BUFFER_TRACE (inode_bitmap_bh,"call ext4_handle_dirty_metadata" ); err =ext4_handle_dirty_metadata (handle,NULL , inode_bitmap_bh);
Quoted 9 lines · Eric Sandeen
Quoted 5 lines · Tao Ma
From: Tao Ma <[email protected]>
Now when we set the group inode free count, we don't have a proper group lock so that multiple threads may decrease the inode free count at the same time. And e2fsck will complain something like:
This is only in the !
EXT4_FEATURE_RO_COMPAT_GDT_CSUMcase I guess? That would be worth mentioning in the summary & changelog.
sure, I will add it in v2.
Quoted 2 lines
I guess you were testing without that for some reason?
See my comments below. I found it when running xfstests 269.
Thanks
Tao
Quoted 59 lines
-eric
Quoted 41 lines
Free inodes count wrong for group #1 (1, counted=0). Fix? no
Free inodes count wrong for group #2 (3, counted=0). Fix? no
Directories count wrong for group #2 (780, counted=779). Fix? no
Free inodes count wrong for group #3 (2272, counted=2273). Fix? no
So this patch try to protect it with the
ext4_lock_group.btw, it is found by xfstests test case 269 and I have run it 100 times and the error in e2fsck doesn't show up again.
Cc Theodore Ts'o <[email protected]>Signed-off-by Tao Ma <[email protected]>--- fs/ext4/ialloc.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)fs/ext4/ialloc.c +3
-1@@ -772,7 +772,9 @@ got:ext4_itable_unused_set (sb, gdp, (EXT4_INODES_PER_GROUP (sb) - ino));up_read (&grp->alloc_sem); - } + }else +ext4_lock_group (sb, group); +ext4_free_inodes_set (sb, gdp,ext4_free_inodes_count (sb, gdp) -1 );if (S_ISDIR (mode)) {ext4_used_dirs_set (sb, gdp,ext4_used_dirs_count (sb, gdp) +1 );@@ -782,10 +784,9 @@ got:atomic_inc (&sbi->s_flex_groups[f].used_dirs); }fs/ext4/ialloc.c got: · line 792
Quoted 10 lines
fs/ext4/ialloc.c +2
-3} -if (EXT4_HAS_RO_COMPAT_FEATURE (sb,EXT4_FEATURE_RO_COMPAT_GDT_CSUM )) { +if (EXT4_HAS_RO_COMPAT_FEATURE (sb,EXT4_FEATURE_RO_COMPAT_GDT_CSUM )) gdp->bg_checksum =ext4_group_desc_csum (sbi, group, gdp); -ext4_unlock_group (sb, group); - } +ext4_unlock_group (sb, group);BUFFER_TRACE (inode_bitmap_bh,"call ext4_handle_dirty_metadata" ); err =ext4_handle_dirty_metadata (handle,NULL , inode_bitmap_bh);--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 11 lines · Tao Ma
From: Tao Ma <[email protected]>
Now when we set the group inode free count, we don't have a proper group lock so that multiple threads may decrease the inode free count at the same time. And e2fsck will complain something like:
fs/ext4/ialloc.c +0
-0
fs/ext4/ialloc.c got: · line 776
Quoted 6 lines
fs/ext4/ialloc.c +2
-1@@ -772,7 +772,9 @@ got:ext4_itable_unused_set (sb, gdp, (EXT4_INODES_PER_GROUP (sb) - ino));up_read (&grp->alloc_sem); - } + }else +ext4_lock_group (sb, group);
Minor coding style fix - when one half of if/else is using braces then the other half should also use braces, like:
if {
:
} else {
:
}Quoted 24 lines
fs/ext4/ialloc.c +3
-3+ext4_free_inodes_set (sb, gdp,ext4_free_inodes_count (sb, gdp) -1 );if (S_ISDIR (mode)) {ext4_used_dirs_set (sb, gdp,ext4_used_dirs_count (sb, gdp) +1 );@@ -782,10 +784,9 @@ got:atomic_inc (&sbi->s_flex_groups[f].used_dirs); } } -if (EXT4_HAS_RO_COMPAT_FEATURE (sb,EXT4_FEATURE_RO_COMPAT_GDT_CSUM )) { +if (EXT4_HAS_RO_COMPAT_FEATURE (sb,EXT4_FEATURE_RO_COMPAT_GDT_CSUM )) gdp->bg_checksum =ext4_group_desc_csum (sbi, group, gdp); -ext4_unlock_group (sb, group); - } +ext4_unlock_group (sb, group);BUFFER_TRACE (inode_bitmap_bh,"call ext4_handle_dirty_metadata" ); err =ext4_handle_dirty_metadata (handle,NULL , inode_bitmap_bh);Signature · 6 lines
1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Cheers, Andreas
Quoted 22 lines · Andreas Dilger
Quoted 11 lines · Tao Ma
From: Tao Ma <[email protected]>
Now when we set the group inode free count, we don't have a proper group lock so that multiple threads may decrease the inode free count at the same time. And e2fsck will complain something like:
fs/ext4/ialloc.c +0
-0fs/ext4/ialloc.c got: · line 776
Quoted 6 lines
fs/ext4/ialloc.c +2
-1@@ -772,7 +772,9 @@ got:ext4_itable_unused_set (sb, gdp, (EXT4_INODES_PER_GROUP (sb) - ino));up_read (&grp->alloc_sem); - } + }else +ext4_lock_group (sb, group);Minor coding style fix - when one half of if/else is using braces then the other half should also use braces, like:
Quoted 5 lines
if {
:
} else {
:
}thank you Andreas, and I will change it in the next version.
Thanks
Tao
Quoted 37 lines
Quoted 25 lines
fs/ext4/ialloc.c +3
-3+ext4_free_inodes_set (sb, gdp,ext4_free_inodes_count (sb, gdp) -1 );if (S_ISDIR (mode)) {ext4_used_dirs_set (sb, gdp,ext4_used_dirs_count (sb, gdp) +1 );@@ -782,10 +784,9 @@ got:atomic_inc (&sbi->s_flex_groups[f].used_dirs); } } -if (EXT4_HAS_RO_COMPAT_FEATURE (sb,EXT4_FEATURE_RO_COMPAT_GDT_CSUM )) { +if (EXT4_HAS_RO_COMPAT_FEATURE (sb,EXT4_FEATURE_RO_COMPAT_GDT_CSUM )) gdp->bg_checksum =ext4_group_desc_csum (sbi, group, gdp); -ext4_unlock_group (sb, group); - } +ext4_unlock_group (sb, group);BUFFER_TRACE (inode_bitmap_bh,"call ext4_handle_dirty_metadata" ); err =ext4_handle_dirty_metadata (handle,NULL , inode_bitmap_bh);Signature · 6 lines
1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.htmlCheers, Andreas
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Tao Ma
Quoted 7 lines · Eric Sandeen
Quoted 5 lines · Tao Ma
From: Tao Ma <[email protected]>
Now when we set the group inode free count, we don't have a proper group lock so that multiple threads may decrease the inode free count at the same time. And e2fsck will complain something like:
Quoted 6 lines
Quoted 2 lines
This is only in the !
EXT4_FEATURE_RO_COMPAT_GDT_CSUMcase I guess? That would be worth mentioning in the summary & changelog.sure, I will add it in v2.
Quoted 2 lines
I guess you were testing without that for some reason?
See my comments below. I found it when running xfstests 269.
Still not sure how you got a filesystem w/o that feature though, unless I am forgetting something obvious. Isn't it on by default?
-Eric
Quoted 11 lines · Eric Sandeen
Quoted 10 lines · Tao Ma
Quoted 9 lines · Eric Sandeen
Quoted 5 lines · Tao Ma
From: Tao Ma <[email protected]>
Now when we set the group inode free count, we don't have a proper group lock so that multiple threads may decrease the inode free count at the same time. And e2fsck will complain something like:
This is only in the !
EXT4_FEATURE_RO_COMPAT_GDT_CSUMcase I guess? That would be worth mentioning in the summary & changelog.
Quoted 7 lines
Quoted 4 lines
sure, I will add it in v2.
Quoted 2 lines
I guess you were testing without that for some reason?
See my comments below. I found it when running xfstests 269.
Still not sure how you got a filesystem w/o that feature though, unless I am forgetting something obvious. Isn't it on by default?
oh, I see. Yes, we mkfs the system with the following configurations:
mke2fs -O ^resize_inode,^uninit_bg,extent,meta_bg,flex_bg,ext_attr Maybe that's the reason why it has never be met by others before. ;)
Thanks
Tao
Quoted 14 lines · Tao Ma
Quoted 13 lines · Eric Sandeen
Quoted 12 lines · Tao Ma
Quoted 9 lines · Eric Sandeen
Quoted 5 lines · Tao Ma
From: Tao Ma <[email protected]>
Now when we set the group inode free count, we don't have a proper group lock so that multiple threads may decrease the inode free count at the same time. And e2fsck will complain something like:
This is only in the !
EXT4_FEATURE_RO_COMPAT_GDT_CSUMcase I guess? That would be worth mentioning in the summary & changelog.sure, I will add it in v2.
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Quoted 1 line
I guess you were testing without that for some reason?
See my comments below. I found it when running xfstests 269.
Still not sure how you got a filesystem w/o that feature though, unless I am forgetting something obvious. Isn't it on by default?
oh, I see. Yes, we mkfs the system with the following configurations:
mke2fs -O ^resize_inode,^uninit_bg,extent,meta_bg,flex_bg,ext_attr Maybe that's the reason why it has never be met by others before. ;)
Ok, good. I figured it was in some barely-reachable corner of the infinite test matrix ;)
-Eric
Quoted 6 lines
Thanks
Tao
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Ted Ts'o
maintainerQuoted 3 lines · Tao Ma
oh, I see. Yes, we mkfs the system with the following configurations:
mke2fs -O ^resize_inode,^uninit_bg,extent,meta_bg,flex_bg,ext_attr Maybe that's the reason why it has never be met by others before. ;)
I'm curious -- is there a specific reason you're disabling the group descriptor checksum? Or was that just something that was picked at one point and you haven't changed it since?
Thanks,
- Ted
Quoted 8 lines · Ted Ts'o
Quoted 3 lines · Tao Ma
oh, I see. Yes, we mkfs the system with the following configurations:
mke2fs -O ^resize_inode,^uninit_bg,extent,meta_bg,flex_bg,ext_attr Maybe that's the reason why it has never be met by others before. ;)I'm curious -- is there a specific reason you're disabling the group descriptor checksum? Or was that just something that was picked at one point and you haven't changed it since?
We are just disabling the uninit_bg so as to let the block group initialization happen in the mkfs time. I don't know why the checksum is also disabled by ^uninit_bg.
Thanks
Tao
Quoted 8 lines
Thanks,
- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines · Tao Ma
Quoted 5 lines · Ted Ts'o
Quoted 3 lines · Tao Ma
oh, I see. Yes, we mkfs the system with the following configurations:
mke2fs -O ^resize_inode,^uninit_bg,extent,meta_bg,flex_bg,ext_attr Maybe that's the reason why it has never be met by others before. ;)
Quoted 7 lines
Quoted 3 lines
I'm curious -- is there a specific reason you're disabling the group descriptor checksum? Or was that just something that was picked at one point and you haven't changed it since?
We are just disabling the
uninit_bgso as to let the block group initialization happen in the mkfs time. I don't know why the checksum is also disabled by ^uninit_bg.
The checksum is controlled by uninit_bg, because there was a need to ensure the bg_itable_unused count and the UNINIT flags could be trusted when doing an e2fsck.
If you don't want to do lazy inode table initialization, that is disabled by "mke2fs -E lazy_itable_init=0".
Cheers, Andreas
Ted Ts'o
maintainerQuoted 10 lines · Andreas Dilger
Quoted 3 lines
We are just disabling the
uninit_bgso as to let the block group initialization happen in the mkfs time. I don't know why the checksum is also disabled by ^uninit_bg.The checksum is controlled by
uninit_bg, because there was a need to ensure thebg_itable_unusedcount and the UNINIT flags could be trusted when doing an e2fsck.If you don't want to do lazy inode table initialization, that is disabled by "mke2fs -E lazy_itable_init=0".
You can also disable whether or not lazy inode table initialization happens by default via /etc/mke2fs.conf. At work we have a very fairly havily modified /etc/mke2fs.conf which has our production-specific mke2fs parameters defined, so that someone who runs mke2fs by hand will get the same result at as the automated systems.
I can easily see how if you are trying for predictable latency numbers, disabling lazy inode table initialization makes a huge amount of sense. I'd recommend doing it via /etc/mke2fs.conf, though.
Regards,
- Ted
Quoted 19 lines · Ted Ts'o
Quoted 10 lines · Andreas Dilger
Quoted 3 lines
We are just disabling the
uninit_bgso as to let the block group initialization happen in the mkfs time. I don't know why the checksum is also disabled by ^uninit_bg.The checksum is controlled by
uninit_bg, because there was a need to ensure thebg_itable_unusedcount and the UNINIT flags could be trusted when doing an e2fsck.If you don't want to do lazy inode table initialization, that is disabled by "mke2fs -E lazy_itable_init=0".
You can also disable whether or not lazy inode table initialization happens by default via
/etc/mke2fs.conf. At work we have a very fairly havily modified/etc/mke2fs.confwhich has our production-specific mke2fs parameters defined, so that someone who runs mke2fs by hand will get the same result at as the automated systems.
Quoted 3 lines
I can easily see how if you are trying for predictable latency numbers, disabling lazy inode table initialization makes a huge amount of sense. I'd recommend doing it via
/etc/mke2fs.conf, though.
OK, thank you all for the good suggestion.
Thanks
Tao