aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Sandeen <sandeen@redhat.com>2008-08-02 21:21:08 -0400
committerTheodore Ts'o <tytso@mit.edu>2008-08-02 21:21:08 -0400
commitb5f10eed8125702929e57cca7e5956b1b9b6d015 (patch)
treee5b38a6f654baea3658bf100320a4d66387988a3
parente29d1cde63be0b5f1739416b5574a83c34bf8eeb (diff)
ext4: lock block groups when initializing
I noticed when filling a 1T filesystem with 4 threads using the fs_mark benchmark: fs_mark -d /mnt/test -D 256 -n 100000 -t 4 -s 20480 -F -S 0 that I occasionally got checksum mismatch errors: EXT4-fs error (device sdb): ext4_init_inode_bitmap: Checksum bad for group 6935 etc. I'd reliably get 4-5 of them during the run. It appears that the problem is likely a race to init the bg's when the uninit_bg feature is enabled. With the patch below, which adds sb_bgl_locking around initialization, I was able to complete several runs with no errors or warnings. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r--fs/ext4/balloc.c3
-rw-r--r--fs/ext4/ialloc.c5
-rw-r--r--fs/ext4/mballoc.c3
-rw-r--r--fs/ext4/super.c2
4 files changed, 12 insertions, 1 deletions
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index 386cb79ac4b6..1ae5004e93fc 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -321,12 +321,15 @@ ext4_read_block_bitmap(struct super_block *sb, ext4_group_t block_group)
321 if (bh_uptodate_or_lock(bh)) 321 if (bh_uptodate_or_lock(bh))
322 return bh; 322 return bh;
323 323
324 spin_lock(sb_bgl_lock(EXT4_SB(sb), block_group));
324 if (desc->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) { 325 if (desc->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {
325 ext4_init_block_bitmap(sb, bh, block_group, desc); 326 ext4_init_block_bitmap(sb, bh, block_group, desc);
326 set_buffer_uptodate(bh); 327 set_buffer_uptodate(bh);
327 unlock_buffer(bh); 328 unlock_buffer(bh);
329 spin_unlock(sb_bgl_lock(EXT4_SB(sb), block_group));
328 return bh; 330 return bh;
329 } 331 }
332 spin_unlock(sb_bgl_lock(EXT4_SB(sb), block_group));
330 if (bh_submit_read(bh) < 0) { 333 if (bh_submit_read(bh) < 0) {
331 put_bh(bh); 334 put_bh(bh);
332 ext4_error(sb, __func__, 335 ext4_error(sb, __func__,
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index 09cdcd5914d0..655e760212b8 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -118,12 +118,15 @@ ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
118 if (bh_uptodate_or_lock(bh)) 118 if (bh_uptodate_or_lock(bh))
119 return bh; 119 return bh;
120 120
121 spin_lock(sb_bgl_lock(EXT4_SB(sb), block_group));
121 if (desc->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT)) { 122 if (desc->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT)) {
122 ext4_init_inode_bitmap(sb, bh, block_group, desc); 123 ext4_init_inode_bitmap(sb, bh, block_group, desc);
123 set_buffer_uptodate(bh); 124 set_buffer_uptodate(bh);
124 unlock_buffer(bh); 125 unlock_buffer(bh);
126 spin_unlock(sb_bgl_lock(EXT4_SB(sb), block_group));
125 return bh; 127 return bh;
126 } 128 }
129 spin_unlock(sb_bgl_lock(EXT4_SB(sb), block_group));
127 if (bh_submit_read(bh) < 0) { 130 if (bh_submit_read(bh) < 0) {
128 put_bh(bh); 131 put_bh(bh);
129 ext4_error(sb, __func__, 132 ext4_error(sb, __func__,
@@ -735,7 +738,7 @@ got:
735 738
736 /* When marking the block group with 739 /* When marking the block group with
737 * ~EXT4_BG_INODE_UNINIT we don't want to depend 740 * ~EXT4_BG_INODE_UNINIT we don't want to depend
738 * on the value of bg_itable_unsed even though 741 * on the value of bg_itable_unused even though
739 * mke2fs could have initialized the same for us. 742 * mke2fs could have initialized the same for us.
740 * Instead we calculated the value below 743 * Instead we calculated the value below
741 */ 744 */
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 8d141a25bbee..4258d3289a6f 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -787,13 +787,16 @@ static int ext4_mb_init_cache(struct page *page, char *incore)
787 if (bh_uptodate_or_lock(bh[i])) 787 if (bh_uptodate_or_lock(bh[i]))
788 continue; 788 continue;
789 789
790 spin_lock(sb_bgl_lock(EXT4_SB(sb), first_group + i));
790 if (desc->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) { 791 if (desc->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {
791 ext4_init_block_bitmap(sb, bh[i], 792 ext4_init_block_bitmap(sb, bh[i],
792 first_group + i, desc); 793 first_group + i, desc);
793 set_buffer_uptodate(bh[i]); 794 set_buffer_uptodate(bh[i]);
794 unlock_buffer(bh[i]); 795 unlock_buffer(bh[i]);
796 spin_unlock(sb_bgl_lock(EXT4_SB(sb), first_group + i));
795 continue; 797 continue;
796 } 798 }
799 spin_unlock(sb_bgl_lock(EXT4_SB(sb), first_group + i));
797 get_bh(bh[i]); 800 get_bh(bh[i]);
798 bh[i]->b_end_io = end_buffer_read_sync; 801 bh[i]->b_end_io = end_buffer_read_sync;
799 submit_bh(READ, bh[i]); 802 submit_bh(READ, bh[i]);
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 876e1c620365..511997ef6f0e 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1621,6 +1621,7 @@ static int ext4_check_descriptors(struct super_block *sb)
1621 "(block %llu)!", i, inode_table); 1621 "(block %llu)!", i, inode_table);
1622 return 0; 1622 return 0;
1623 } 1623 }
1624 spin_lock(sb_bgl_lock(sbi, i));
1624 if (!ext4_group_desc_csum_verify(sbi, i, gdp)) { 1625 if (!ext4_group_desc_csum_verify(sbi, i, gdp)) {
1625 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1626 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: "
1626 "Checksum for group %lu failed (%u!=%u)\n", 1627 "Checksum for group %lu failed (%u!=%u)\n",
@@ -1629,6 +1630,7 @@ static int ext4_check_descriptors(struct super_block *sb)
1629 if (!(sb->s_flags & MS_RDONLY)) 1630 if (!(sb->s_flags & MS_RDONLY))
1630 return 0; 1631 return 0;
1631 } 1632 }
1633 spin_unlock(sb_bgl_lock(sbi, i));
1632 if (!flexbg_flag) 1634 if (!flexbg_flag)
1633 first_block += EXT4_BLOCKS_PER_GROUP(sb); 1635 first_block += EXT4_BLOCKS_PER_GROUP(sb);
1634 } 1636 }