ext4: check missed return value in ext4_sync_file()
Subsystems (2)
Theodore Ts'o
maintainerPATCH 2/28 ext4: fix memory leaks in error path handling of ext4_ext_zeroout()
In reply to Theodore Ts'oFrom: Jing Zhang <[email protected]>
commit b720303df7352d4a7a1f61e467e0a124913c0d41 upstream (as of v2.6.34-git13)
When EIO occurs after bio is submitted, there is no memory free operation for bio, which results in memory leakage. And there is also no check against bio_alloc() for bio.
--- fs/ext4/extents.c | 15 ++++++++------- 1 files changed, 8 insertions(+), 7 deletions(-)
fs/ext4/extents.c +8 -7
@@ -2544,7 +2544,7 @@ static void bi_complete(struct bio *bio, int error)/* FIXME!! we need to try to merge to left or right after zero-out */ static int ext4_ext_zeroout (struct inode *inode,struct ext4_extent *ex) { -int ret = -EIO ; +int ret;struct bio *bio;int blkbits, blocksize;sector_t ee_pblock;
@@ -2568,6 +2568,9 @@ static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex) len = ee_len; bio =bio_alloc (GFP_NOIO , len); +if (!bio) +return -ENOMEM ; + bio->bi_sector = ee_pblock; bio->bi_bdev = inode->i_sb->s_bdev;
@@ -2595,17 +2598,15 @@ static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex)submit_bio (WRITE , bio);wait_for_completion (&event); -if (test_bit (BIO_UPTODATE , &bio->bi_flags)) - ret =0 ; -else { - ret = -EIO ; -break ; +if (!test_bit (BIO_UPTODATE , &bio->bi_flags)) { +bio_put (bio); +return -EIO ; }bio_put (bio); ee_len -= done; ee_pblock += done << (blkbits -9 ); } -return ret; +return 0 ; }#define EXT4_EXT_ZERO_LEN 7
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 4/28 ext4: rename ext4_mb_release_desc() to ext4_mb_unload_buddy()
In reply to Theodore Ts'oFrom: Jing Zhang <[email protected]>
commit e39e07fdfd98be8650385f12a7b81d6adc547510 upstream (as of v2.6.34-git13)
This function cleans up after ext4_mb_load_buddy(), so the renaming makes the code clearer.
--- fs/ext4/mballoc.c | 24 ++++++++++++------------ 1 files changed, 12 insertions(+), 12 deletions(-)
fs/ext4/mballoc.c +12 -12
@@ -1150,7 +1150,7 @@ err:return ret; } -static void ext4_mb_release_desc (struct ext4_buddy *e4b) +static void ext4_mb_unload_buddy (struct ext4_buddy *e4b) {if (e4b->bd_bitmap_page)page_cache_release (e4b->bd_bitmap_page);
@@ -1617,7 +1617,7 @@ int ext4_mb_try_best_found(struct ext4_allocation_context *ac, }ext4_unlock_group (ac->ac_sb, group); -ext4_mb_release_desc (e4b); +ext4_mb_unload_buddy (e4b);return 0 ; }
@@ -1672,7 +1672,7 @@ int ext4_mb_find_by_goal(struct ext4_allocation_context *ac,ext4_mb_use_best_found (ac, e4b); }ext4_unlock_group (ac->ac_sb, group); -ext4_mb_release_desc (e4b); +ext4_mb_unload_buddy (e4b);return 0 ; }
@@ -2042,7 +2042,7 @@ repeat:if (!ext4_mb_good_group (ac, group, cr)) {/* someone did allocation from this group */ ext4_unlock_group (sb, group); -ext4_mb_release_desc (&e4b); +ext4_mb_unload_buddy (&e4b);continue ; }
@@ -2056,7 +2056,7 @@ repeat:ext4_mb_complex_scan_group (ac, &e4b);ext4_unlock_group (sb, group); -ext4_mb_release_desc (&e4b); +ext4_mb_unload_buddy (&e4b);if (ac->ac_status !=AC_STATUS_CONTINUE )break ;
@@ -2146,7 +2146,7 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)ext4_lock_group (sb, group);memcpy (&sg,ext4_get_group_info (sb, group), i);ext4_unlock_group (sb, group); -ext4_mb_release_desc (&e4b); +ext4_mb_unload_buddy (&e4b);seq_printf (seq,"#%-5u: %-5u %-5u %-5u [" , group, sg.info.bb_free, sg.info.bb_fragments, sg.info.bb_first_free);
@@ -2566,7 +2566,7 @@ static void release_blocks_on_commit(journal_t *journal, transaction_t *txn) }ext4_unlock_group (sb, entry->group);kmem_cache_free (ext4_free_ext_cachep, entry); -ext4_mb_release_desc (&e4b); +ext4_mb_unload_buddy (&e4b); }mb_debug (1 ,"freed %u blocks in %u structures\n" , count, count2);
@@ -3695,7 +3695,7 @@ out:ext4_unlock_group (sb, group);if (ac)kmem_cache_free (ext4_ac_cachep, ac); -ext4_mb_release_desc (&e4b); +ext4_mb_unload_buddy (&e4b);put_bh (bitmap_bh);return free; }
@@ -3799,7 +3799,7 @@ repeat:if (bitmap_bh ==NULL ) {ext4_error (sb,"Error reading block bitmap for %u" , group); -ext4_mb_release_desc (&e4b); +ext4_mb_unload_buddy (&e4b);continue ; }
@@ -3808,7 +3808,7 @@ repeat:ext4_mb_release_inode_pa (&e4b, bitmap_bh, pa, ac);ext4_unlock_group (sb, group); -ext4_mb_release_desc (&e4b); +ext4_mb_unload_buddy (&e4b);put_bh (bitmap_bh);list_del (&pa->u.pa_tmp_list);
@@ -4072,7 +4072,7 @@ ext4_mb_discard_lg_preallocations(struct super_block *sb,ext4_mb_release_group_pa (&e4b, pa, ac);ext4_unlock_group (sb, group); -ext4_mb_release_desc (&e4b); +ext4_mb_unload_buddy (&e4b);list_del (&pa->u.pa_tmp_list);call_rcu (&(pa)->u.pa_rcu, ext4_mb_pa_callback); }
@@ -4608,7 +4608,7 @@ do_more:atomic_add (count, &sbi->s_flex_groups[flex_group].free_blocks); } -ext4_mb_release_desc (&e4b); +ext4_mb_unload_buddy (&e4b); freed += count;
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 8/28 ext4: don't return to userspace after freezing the fs with a mutex held
In reply to Theodore Ts'oFrom: Eric Sandeen <[email protected]>
commit 6b0310fbf087ad6e9e3b8392adca97cd77184084 upstream (as of v2.6.34-git13)
ext4_freeze() used jbd2_journal_lock_updates() which takes the j_barrier mutex, and then returns to userspace. The kernel does not like this:
================================================
[ BUG: lock held when returning to user space! ]
------------------------------------------------
lvcreate/1075 is leaving the kernel with locks still held! 1 lock held by lvcreate/1075:
#0: (&journal->j_barrier){+.+...}, at: [<ffffffff811c6214>]jbd2_journal_lock_updates+0xe1/0xf0
Use vfs_check_frozen() added to ext4_journal_start_sb() and ext4_force_commit() instead.
Addresses-Red-Hat-Bugzilla: #568503
--- fs/ext4/super.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-)
fs/ext4/super.c +10 -10
@@ -241,6 +241,7 @@ handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks)if (sb->s_flags &MS_RDONLY )return ERR_PTR (-EROFS ); +vfs_check_frozen (sb,SB_FREEZE_WRITE );/* Special case here: if the journal has aborted behind our * backs (eg. EIO in the commit thread), then we still need to * take the FS itself readonly cleanly. */
@@ -3485,8 +3486,10 @@ int ext4_force_commit(struct super_block *sb)return 0 ; journal =EXT4_SB (sb)->s_journal; -if (journal) +if (journal) { +vfs_check_frozen (sb,SB_FREEZE_WRITE ); ret =ext4_journal_force_commit (journal); + }return ret; }
@@ -3535,18 +3538,16 @@ static int ext4_freeze(struct super_block *sb)* the journal. */ error =jbd2_journal_flush (journal); -if (error <0 ) { - out: -jbd2_journal_unlock_updates (journal); -return error; - } +if (error <0 ) + goto out;/* Journal blocked and flushed, clear needs_recovery flag. */ EXT4_CLEAR_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_RECOVER ); error =ext4_commit_super (sb,1 ); -if (error) - goto out; -return 0 ; +out: +/* we rely on s_frozen to stop further updates */ +jbd2_journal_unlock_updates (EXT4_SB (sb)->s_journal); +return error; }/*
@@ -3563,7 +3564,6 @@ static int ext4_unfreeze(struct super_block *sb)EXT4_SET_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_RECOVER );ext4_commit_super (sb,1 );unlock_super (sb); -jbd2_journal_unlock_updates (EXT4_SB (sb)->s_journal);return 0 ; }
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 23/28 ext4: Avoid crashing on NULL ptr dereference on a filesystem error
In reply to Theodore Ts'ocommit f70f362b4a6fe47c239dbfb3efc0cc2c10e4f09c upstream (as of v2.6.34-git13)
If the EOFBLOCK_FL flag is set when it should not be and the inode is zero length, then eh_entries is zero, and ex is NULL, so dereferencing ex to print ex->ee_block causes a kernel OOPS in ext4_ext_map_blocks().
On top of that, the error message which is printed isn't very helpful. So we fix this by printing something more explanatory which doesn't involve trying to print ex->ee_block.
Addresses-Google-Bug: #2655740
--- fs/ext4/extents.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
fs/ext4/extents.c +5 -4
@@ -3381,8 +3381,9 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,*/ if (unlikely (path[depth].p_ext ==NULL && depth !=0 )) {EXT4_ERROR_INODE (inode,"bad extent address " -"iblock: %d, depth: %d pblock %lld" , - iblock, depth, path[depth].p_block); +"iblock: %lu, depth: %d pblock %lld" , + (unsigned long ) iblock, depth, + path[depth].p_block); err = -EIO ; goto out2; }
@@ -3512,8 +3513,8 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,if (unlikely (ext4_test_inode_flag (inode,EXT4_INODE_EOFBLOCKS ))) {if (unlikely (!eh->eh_entries)) {EXT4_ERROR_INODE (inode, -"eh->eh_entries == 0 ee_block %d" , - ex->ee_block); +"eh->eh_entries == 0 and " +"EOFBLOCKS_FL set" ); err = -EIO ; goto out2; }
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 27/28 ext4: Fix compat EXT4_IOC_ADD_GROUP
In reply to Theodore Ts'oFrom: Ben Hutchings <[email protected]>
commit 4d92dc0f00a775dc2e1267b0e00befb783902fe7 upstream (as of v2.6.34-git13)
struct ext4_new_group_input needs to be converted because u64 has only 32-bit alignment on some 32-bit architectures, notably i386.
--- fs/ext4/ext4.h | 16 ++++++++++++++++ fs/ext4/ioctl.c | 25 +++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-)
fs/ext4/ext4.h +16 -0
@@ -29,6 +29,9 @@#include <linux/wait.h> #include <linux/blockgroup_lock.h> #include <linux/percpu_counter.h> +#ifdef __KERNEL__ +#include <linux/compat.h> +#endif /* * The fourth extended filesystem constants/structures
@@ -409,6 +412,18 @@ struct ext4_new_group_input {__u16 unused; }; +#if defined(__KERNEL__) && defined(CONFIG_COMPAT ) +struct compat_ext4_new_group_input { +u32 group; +compat_u64 block_bitmap; +compat_u64 inode_bitmap; +compat_u64 inode_table; +u32 blocks_count; +u16 reserved_blocks; +u16 unused; +}; +#endif +/* The struct ext4_new_group_input in kernel space, with free_blocks_count */ struct ext4_new_group_data {__u32 group;
@@ -486,6 +501,7 @@ struct ext4_new_group_data {#define EXT4_IOC32_GETRSVSZ _IOR('f', 5, int)#define EXT4_IOC32_SETRSVSZ _IOW('f', 6, int)#define EXT4_IOC32_GROUP_EXTEND _IOW('f', 7, unsigned int) +#define EXT4_IOC32_GROUP_ADD _IOW('f', 8, struct compat_ext4_new_group_input)#ifdef CONFIG_JBD2_DEBUG #define EXT4_IOC32_WAIT_FOR_READONLY _IOR('f', 99, int)#endif
fs/ext4/ioctl.c +23 -2
@@ -373,8 +373,29 @@ long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)case EXT4_IOC32_SETRSVSZ : cmd =EXT4_IOC_SETRSVSZ ;break ; -case EXT4_IOC_GROUP_ADD : -break ; +case EXT4_IOC32_GROUP_ADD : { +struct compat_ext4_new_group_input __user *uinput; +struct ext4_new_group_input input; +mm_segment_t old_fs; +int err; + + uinput =compat_ptr (arg); + err =get_user (input.group, &uinput->group); + err |=get_user (input.block_bitmap, &uinput->block_bitmap); + err |=get_user (input.inode_bitmap, &uinput->inode_bitmap); + err |=get_user (input.inode_table, &uinput->inode_table); + err |=get_user (input.blocks_count, &uinput->blocks_count); + err |=get_user (input.reserved_blocks, + &uinput->reserved_blocks); +if (err) +return -EFAULT ; + old_fs =get_fs (); +set_fs (KERNEL_DS ); + err =ext4_ioctl (file,EXT4_IOC_GROUP_ADD , + (unsigned long ) &input); +set_fs (old_fs); +return err; + }case EXT4_IOC_MOVE_EXT :break ;default :
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 1/28 ext4: check missed return value in ext4_sync_file()
From: Dmitry Monakhov <[email protected]>
commit 0671e704658b9f26f85e78d51176daa861f955c7 upstream (as of v2.6.34-git13)
--- fs/ext4/fsync.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fs/ext4/fsync.c +1 -1
@@ -101,7 +101,7 @@ int ext4_sync_file(struct file *file, struct dentry *dentry, int datasync) (journal->j_fs_dev != journal->j_dev) && (journal->j_flags & JBD2_BARRIER))blkdev_issue_flush (inode->i_sb->s_bdev,NULL ); -jbd2_log_wait_commit (journal, commit_tid); + ret =jbd2_log_wait_commit (journal, commit_tid); }else if (journal->j_flags &JBD2_BARRIER )blkdev_issue_flush (inode->i_sb->s_bdev,NULL );return ret;
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 3/28 ext4: Remove unnecessary call to ext4_get_group_desc() in mballoc
From: Jing Zhang <[email protected]>
commit 62e823a2cba18509ee826d775270e8ef9071b5bc upstream (as of v2.6.34-git13)
--- fs/ext4/mballoc.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
fs/ext4/mballoc.c +0 -2
@@ -2025,7 +2025,6 @@ repeat:for (i =0 ; i < ngroups; group++, i++) {struct ext4_group_info *grp; -struct ext4_group_desc *desc;if (group == ngroups) group =0 ;
@@ -2048,7 +2047,6 @@ repeat: } ac->ac_groups_scanned++; - desc =ext4_get_group_desc (sb, group,NULL );if (cr ==0 )ext4_mb_simple_scan_group (ac, &e4b); else if (cr == 1 &&
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 6/28 ext4: fix quota accounting in case of fallocate
In reply to Theodore Ts'oFrom: Dmitry Monakhov <[email protected]>
commit 35121c9860316d7799cea0fbc359a9186e7c2747 upstream (as of v2.6.34-git13)
allocated_meta_data is already included in 'used' variable.
--- fs/ext4/inode.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
fs/ext4/inode.c +2 -1
@@ -1126,7 +1126,8 @@ void ext4_da_update_reserve_space(struct inode *inode,*/ if (allocated_meta_blocks)dquot_claim_block (inode, allocated_meta_blocks); -dquot_release_reservation_block (inode, mdb_free + used); +dquot_release_reservation_block (inode, mdb_free + used - + allocated_meta_blocks); }/*
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 7/28 ext4: check s_log_groups_per_flex in online resize code
In reply to Theodore Ts'oFrom: Eric Sandeen <[email protected]>
commit 42007efd569f1cf3bfb9a61da60ef6c2179508ca upstream (as of v2.6.34-git13)
If groups_per_flex < 2, sbi->s_flex_groups[] doesn't get filled out, and every other access to this first tests s_log_groups_per_flex; same thing needs to happen in resize or we'll wander off into a null pointer when doing an online resize of the file system.
Thanks to Christoph Biedl, who came up with the trivial testcase:
# truncate --size 128M fsfile # mkfs.ext3 -F fsfile # tune2fs -O extents,uninit_bg,dir_index,flex_bg,huge_file,dir_nlink,extra_isize fsfile # e2fsck -yDf -C0 fsfile # truncate --size 132M fsfile # losetup /dev/loop0 fsfile # mount /dev/loop0 mnt # resize2fs -p /dev/loop0
https://bugzilla.kernel.org/show_bug.cgi?id=13549
--- fs/ext4/resize.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
fs/ext4/resize.c +2 -1
@@ -911,7 +911,8 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)percpu_counter_add (&sbi->s_freeinodes_counter,EXT4_INODES_PER_GROUP (sb)); -if (EXT4_HAS_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_FLEX_BG )) { +if (EXT4_HAS_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_FLEX_BG ) && + sbi->s_log_groups_per_flex) {ext4_group_t flex_group; flex_group =ext4_flex_group (sbi, input->group); atomic_add(input->free_blocks_count,
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 9/28 ext4: stop issuing discards if not supported by device
In reply to Theodore Ts'oFrom: Eric Sandeen <[email protected]>
commit a30eec2a8650a77f754e84b2e15f062fe652baa7 upstream (as of v2.6.34-git13)
Turn off issuance of discard requests if the device does not support it - similar to the action we take for barriers. This will save a little computation time if a non-discardable device is mounted with -o discard, and also makes it obvious that it's not doing what was asked at mount time ...
--- fs/ext4/mballoc.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
fs/ext4/mballoc.c +7 -1
@@ -2534,6 +2534,7 @@ static void release_blocks_on_commit(journal_t *journal, transaction_t *txn) entry->count, entry->group, entry);if (test_opt (sb,DISCARD )) { +int ret;ext4_fsblk_t discard_block; discard_block = entry->start_blk +
@@ -2541,7 +2542,12 @@ static void release_blocks_on_commit(journal_t *journal, transaction_t *txn)trace_ext4_discard_blocks (sb, (unsigned long long )discard_block, entry->count); -sb_issue_discard (sb, discard_block, entry->count); + ret =sb_issue_discard (sb, discard_block, entry->count); +if (ret ==EOPNOTSUPP ) { +ext4_warning (sb, __func__, +"discard not supported, disabling" ); +clear_opt (EXT4_SB (sb)->s_mount_opt,DISCARD ); + } } err =ext4_mb_load_buddy (sb, entry->group, &e4b);
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 12/28 ext4: clean up inode bitmaps manipulation in ext4_free_inode
In reply to Theodore Ts'oFrom: Dmitry Monakhov <[email protected]>
commit d17413c08cd2b1dd2bf2cfdbb0f7b736b2b2b15c upstrea (as of v2..34-git13)
- Reorganize locking scheme to batch two atomic operation in to one. This also allow us to state what healthy group must obey following rule ext4_free_inodes_count(sb, gdp) == ext4_count_free(inode_bitmap, NUM);
- Fix possible undefined pointer dereference.
- Even if group descriptor stats aren't accessible we have to update inode bitmaps.
- Move non-group members update out of group_lock.
Note: this commit has been observed to fix fs corruption problems under heavy fs load
--- fs/ext4/ialloc.c | 81 ++++++++++++++++++++++++----------------------------- 1 files changed, 37 insertions(+), 44 deletions(-)
fs/ext4/ialloc.c +39 -46
@@ -240,56 +240,49 @@ void ext4_free_inode(handle_t *handle, struct inode *inode)if (fatal) goto error_return; -/* Ok, now we can actually update the inode bitmaps.. */ - cleared =ext4_clear_bit_atomic (ext4_group_lock_ptr (sb, block_group), - bit, bitmap_bh->b_data); -if (!cleared) -ext4_error (sb,"bit already cleared for inode %lu" , ino); -else { - gdp =ext4_get_group_desc (sb, block_group, &bh2); - + fatal = -ESRCH ; + gdp =ext4_get_group_desc (sb, block_group, &bh2); +if (gdp) {BUFFER_TRACE (bh2,"get_write_access" ); fatal =ext4_journal_get_write_access (handle, bh2); -if (fatal) goto error_return; - -if (gdp) { -ext4_lock_group (sb, block_group); - count =ext4_free_inodes_count (sb, gdp) +1 ; -ext4_free_inodes_set (sb, gdp, count); -if (is_directory) { - count =ext4_used_dirs_count (sb, gdp) -1 ; -ext4_used_dirs_set (sb, gdp, count); -if (sbi->s_log_groups_per_flex) { -ext4_group_t f; - - f =ext4_flex_group (sbi, block_group); -atomic_dec (&sbi->s_flex_groups[f].used_dirs); - } + } +ext4_lock_group (sb, block_group); + cleared =ext4_clear_bit (bit, bitmap_bh->b_data); +if (fatal || !cleared) { +ext4_unlock_group (sb, block_group); + goto out; + } - } - gdp->bg_checksum =ext4_group_desc_csum (sbi, - block_group, gdp); -ext4_unlock_group (sb, block_group); -percpu_counter_inc (&sbi->s_freeinodes_counter); -if (is_directory) -percpu_counter_dec (&sbi->s_dirs_counter); - -if (sbi->s_log_groups_per_flex) { -ext4_group_t f; - - f =ext4_flex_group (sbi, block_group); -atomic_inc (&sbi->s_flex_groups[f].free_inodes); - } - } -BUFFER_TRACE (bh2,"call ext4_handle_dirty_metadata" ); - err =ext4_handle_dirty_metadata (handle,NULL , bh2); -if (!fatal) fatal = err; + count =ext4_free_inodes_count (sb, gdp) +1 ; +ext4_free_inodes_set (sb, gdp, count); +if (is_directory) { + count =ext4_used_dirs_count (sb, gdp) -1 ; +ext4_used_dirs_set (sb, gdp, count); +percpu_counter_dec (&sbi->s_dirs_counter); } -BUFFER_TRACE (bitmap_bh,"call ext4_handle_dirty_metadata" ); - err =ext4_handle_dirty_metadata (handle,NULL , bitmap_bh); -if (!fatal) - fatal = err; - sb->s_dirt =1 ; + gdp->bg_checksum =ext4_group_desc_csum (sbi, block_group, gdp); +ext4_unlock_group (sb, block_group); + +percpu_counter_inc (&sbi->s_freeinodes_counter); +if (sbi->s_log_groups_per_flex) { +ext4_group_t f =ext4_flex_group (sbi, block_group); + +atomic_inc (&sbi->s_flex_groups[f].free_inodes); +if (is_directory) +atomic_dec (&sbi->s_flex_groups[f].used_dirs); + } +BUFFER_TRACE (bh2,"call ext4_handle_dirty_metadata" ); + fatal =ext4_handle_dirty_metadata (handle,NULL , bh2); +out: +if (cleared) { +BUFFER_TRACE (bitmap_bh,"call ext4_handle_dirty_metadata" ); + err =ext4_handle_dirty_metadata (handle,NULL , bitmap_bh); +if (!fatal) + fatal = err; + sb->s_dirt =1 ; + }else +ext4_error (sb,"bit already cleared for inode %lu" , ino); + error_return:brelse (bitmap_bh);ext4_std_error (sb, fatal);
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 17/28 ext4: Remove extraneous newlines in ext4_msg() calls
In reply to Theodore Ts'oFrom: Curt Wohlgemuth <[email protected]>
commit fbe845ddf368f77f86aa7500f8fd2690f54c66a8 upstream (as of v2.6.34-git13)
Addresses-Google-Bug: #2562325
--- fs/ext4/inode.c | 6 +++--- fs/ext4/super.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
fs/ext4/inode.c +3 -3
@@ -2276,7 +2276,7 @@ static int mpage_da_map_blocks(struct mpage_da_data *mpd)ext4_msg (mpd->inode->i_sb,KERN_CRIT ,"delayed block allocation failed for inode %lu at " "logical offset %llu with max blocks %zd with " -"error %d\n" , mpd->inode->i_ino, +"error %d" , mpd->inode->i_ino, (unsigned long long ) next, mpd->b_size >> mpd->inode->i_blkbits, err); printk(KERN_CRIT "This should not happen!! "
@@ -2944,7 +2944,7 @@ retry:if (IS_ERR (handle)) { ret =PTR_ERR (handle);ext4_msg (inode->i_sb,KERN_CRIT ,"%s: jbd2_start: " -"%ld pages, ino %lu; err %d\n" , __func__, +"%ld pages, ino %lu; err %d" , __func__, wbc->nr_to_write, inode->i_ino, ret); goto out_writepages; }
@@ -3019,7 +3019,7 @@ retry:if (pages_skipped != wbc->pages_skipped)ext4_msg (inode->i_sb,KERN_CRIT ,"This should not happen leaving %s " -"with nr_to_write = %ld ret = %d\n" , +"with nr_to_write = %ld ret = %d" , __func__, wbc->nr_to_write, ret);/* Update index */
fs/ext4/super.c +1 -1
@@ -2998,7 +2998,7 @@ no_journal: err =ext4_setup_system_zone (sb);if (err) {ext4_msg (sb,KERN_ERR ,"failed to initialize system " -"zone (%d)\n" , err); +"zone (%d)" , err); goto failed_mount4; }
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 22/28 ext4: Use bitops to read/modify i_flags in struct ext4_inode_info
In reply to Theodore Ts'oFrom: Dmitry Monakhov <[email protected]>
commit 12e9b892002d9af057655d35b44db8ee9243b0dc upstream (as of v2.6.34-git13)
At several places we modify EXT4_I(inode)->i_flags without holding i_mutex (ext4_do_update_inode, ...). These modifications are racy and we can lose updates to i_flags. So convert handling of i_flags to use bitops which are atomic.
https://bugzilla.kernel.org/show_bug.cgi?id=15792
--- fs/ext4/dir.c | 4 +- fs/ext4/ext4.h | 109 ++++++++++++++++++++++++++++++++++++++++++------- fs/ext4/ext4_jbd2.h | 8 ++-- fs/ext4/extents.c | 10 ++-- fs/ext4/file.c | 2 +- fs/ext4/ialloc.c | 4 +- fs/ext4/inode.c | 30 +++++++------- fs/ext4/mballoc.c | 4 +- fs/ext4/migrate.c | 2 +- fs/ext4/move_extent.c | 4 +- fs/ext4/namei.c | 10 ++-- fs/ext4/super.c | 1 + fs/ext4/xattr.c | 4 +- 13 files changed, 136 insertions(+), 56 deletions(-)
fs/ext4/dir.c +2 -2
@@ -111,7 +111,7 @@ static int ext4_readdir(struct file *filp,if (EXT4_HAS_COMPAT_FEATURE (inode->i_sb,EXT4_FEATURE_COMPAT_DIR_INDEX ) && - ((EXT4_I (inode)->i_flags &EXT4_INDEX_FL ) || + ((ext4_test_inode_flag (inode,EXT4_INODE_INDEX )) || ((inode->i_size >> sb->s_blocksize_bits) ==1 ))) { err =ext4_dx_readdir (filp, dirent, filldir);if (err !=ERR_BAD_DX_DIR ) {
@@ -122,7 +122,7 @@ static int ext4_readdir(struct file *filp,* We don't set the inode dirty flag since it's not * critical that it get flushed back to the disk. */ -EXT4_I (filp->f_path.dentry->d_inode)->i_flags &= ~EXT4_INDEX_FL ; +ext4_clear_inode_flag (filp->f_path.dentry->d_inode,EXT4_INODE_INDEX ); } stored =0 ; offset = filp->f_pos & (sb->s_blocksize -1 );
fs/ext4/ext4.h +94 -15
142 lines not on this page · raw message
fs/ext4/ext4_jbd2.h +4 -4
@@ -273,7 +273,7 @@ static inline int ext4_should_journal_data(struct inode *inode)return 1 ;if (test_opt (inode->i_sb,DATA_FLAGS ) ==EXT4_MOUNT_JOURNAL_DATA )return 1 ; -if (EXT4_I (inode)->i_flags &EXT4_JOURNAL_DATA_FL ) +if (ext4_test_inode_flag (inode,EXT4_INODE_JOURNAL_DATA ))return 1 ;return 0 ; }
@@ -284,7 +284,7 @@ static inline int ext4_should_order_data(struct inode *inode)return 0 ;if (!S_ISREG (inode->i_mode))return 0 ; -if (EXT4_I (inode)->i_flags &EXT4_JOURNAL_DATA_FL ) +if (ext4_test_inode_flag (inode,EXT4_INODE_JOURNAL_DATA ))return 0 ;if (test_opt (inode->i_sb,DATA_FLAGS ) ==EXT4_MOUNT_ORDERED_DATA )return 1 ;
@@ -297,7 +297,7 @@ static inline int ext4_should_writeback_data(struct inode *inode)return 0 ;if (EXT4_JOURNAL (inode) ==NULL )return 1 ; -if (EXT4_I (inode)->i_flags &EXT4_JOURNAL_DATA_FL ) +if (ext4_test_inode_flag (inode,EXT4_INODE_JOURNAL_DATA ))return 0 ;if (test_opt (inode->i_sb,DATA_FLAGS ) ==EXT4_MOUNT_WRITEBACK_DATA )return 1 ;
@@ -321,7 +321,7 @@ static inline int ext4_should_dioread_nolock(struct inode *inode)return 0 ;if (!S_ISREG (inode->i_mode))return 0 ; -if (!(EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL )) +if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )))return 0 ;if (ext4_should_journal_data (inode))return 0 ;
fs/ext4/extents.c +5 -5
@@ -3509,7 +3509,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,set_buffer_uninit (bh_result); } -if (unlikely (EXT4_I (inode)->i_flags &EXT4_EOFBLOCKS_FL )) { +if (unlikely (ext4_test_inode_flag (inode,EXT4_INODE_EOFBLOCKS ))) {if (unlikely (!eh->eh_entries)) { EXT4_ERROR_INODE(inode, "eh->eh_entries == 0 ee_block %d",
@@ -3520,7 +3520,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, last_ex =EXT_LAST_EXTENT (eh);if (iblock + ar.len >le32_to_cpu (last_ex->ee_block) +ext4_ext_get_actual_len (last_ex)) -EXT4_I (inode)->i_flags &= ~EXT4_EOFBLOCKS_FL ; +ext4_clear_inode_flag (inode,EXT4_INODE_EOFBLOCKS ); } err =ext4_ext_insert_extent (handle, inode, path, &newex, flags);if (err) {
@@ -3661,7 +3661,7 @@ static void ext4_falloc_update_inode(struct inode *inode,* can proceed even if the new size is the same as i_size. */ if (new_size >i_size_read (inode)) -EXT4_I (inode)->i_flags |=EXT4_EOFBLOCKS_FL ; +ext4_set_inode_flag (inode,EXT4_INODE_EOFBLOCKS ); } }
@@ -3689,7 +3689,7 @@ long ext4_fallocate(struct inode *inode, int mode, loff_t offset, loff_t len)* currently supporting (pre)allocate mode for extent-based * files _only_ */ -if (!(EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL )) +if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )))return -EOPNOTSUPP ;/* preallocation to directories is currently not supported */
@@ -3939,7 +3939,7 @@ int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,int error =0 ;/* fallback to generic here if not in extents fmt */ -if (!(EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL )) +if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )))return generic_block_fiemap (inode, fieinfo, start, len, ext4_get_block);
fs/ext4/file.c +1 -1
@@ -66,7 +66,7 @@ ext4_file_write(struct kiocb *iocb, const struct iovec *iov,* is smaller than s_maxbytes, which is for extent-mapped files. */ -if (!(EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL )) { +if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))) {struct ext4_sb_info *sbi =EXT4_SB (inode->i_sb);size_t length =iov_length (iov, nr_segs);
fs/ext4/ialloc.c +2 -2
@@ -492,7 +492,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent,if (S_ISDIR (mode) && ((parent == sb->s_root->d_inode) || - (EXT4_I (parent)->i_flags &EXT4_TOPDIR_FL ))) { + (ext4_test_inode_flag (parent,EXT4_INODE_TOPDIR )))) {int best_ndir = inodes_per_group;int ret =-1 ;
@@ -1038,7 +1038,7 @@ got:if (EXT4_HAS_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_EXTENTS )) {/* set extent flag only for directory, file and normal symlink*/ if (S_ISDIR (mode) ||S_ISREG (mode) ||S_ISLNK (mode)) { -EXT4_I (inode)->i_flags |=EXT4_EXTENTS_FL ; +ext4_set_inode_flag (inode,EXT4_INODE_EXTENTS );ext4_ext_tree_init (handle, inode); } }
fs/ext4/inode.c +15 -15
@@ -933,7 +933,7 @@ static int ext4_ind_get_blocks(handle_t *handle, struct inode *inode,int count =0 ;ext4_fsblk_t first_block =0 ; -J_ASSERT (!(EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL )); +J_ASSERT (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )));J_ASSERT (handle !=NULL || (flags &EXT4_GET_BLOCKS_CREATE ) ==0 ); depth =ext4_block_to_path (inode, iblock, offsets, &blocks_to_boundary);
@@ -1061,7 +1061,7 @@ static int ext4_indirect_calc_metadata_amount(struct inode *inode,*/ static int ext4_calc_metadata_amount (struct inode *inode,sector_t lblock) { -if (EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL ) +if (ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))return ext4_ext_calc_metadata_amount (inode, lblock);return ext4_indirect_calc_metadata_amount (inode, lblock);
@@ -1241,7 +1241,7 @@ int ext4_get_blocks(handle_t *handle, struct inode *inode, sector_t block,* file system block. */ down_read ((&EXT4_I (inode)->i_data_sem)); -if (EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL ) { +if (ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )) { retval =ext4_ext_get_blocks (handle, inode, block, max_blocks, bh,0 ); }else {
@@ -1303,7 +1303,7 @@ int ext4_get_blocks(handle_t *handle, struct inode *inode, sector_t block,* We need to check for EXT4 here because migrate * could have changed the inode type in between */ -if (EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL ) { +if (ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )) { retval =ext4_ext_get_blocks (handle, inode, block, max_blocks, bh, flags); }else {
@@ -2353,7 +2353,7 @@ static void mpage_add_bh_to_extent(struct mpage_da_data *mpd, goto flush_it;/* check if thereserved journal credits might overflow */ -if (!(EXT4_I (mpd->inode)->i_flags &EXT4_EXTENTS_FL )) { +if (!(ext4_test_inode_flag (mpd->inode,EXT4_INODE_EXTENTS ))) {if (nrblocks >=EXT4_MAX_TRANS_DATA ) {/* * With non-extent format we are limited by the journal
@@ -2813,7 +2813,7 @@ static int ext4_da_writepages_trans_blocks(struct inode *inode)* number of contiguous block. So we will limit * number of contiguous block to a sane value */ -if (!(EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL ) && +if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )) && (max_blocks >EXT4_MAX_TRANS_DATA )) max_blocks =EXT4_MAX_TRANS_DATA ;
@@ -4057,7 +4057,7 @@ static ssize_t ext4_direct_IO(int rw, struct kiocb *iocb,struct file *file = iocb->ki_filp;struct inode *inode = file->f_mapping->host; -if (EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL ) +if (ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))return ext4_ext_direct_IO (rw, iocb, iov, offset, nr_segs);return ext4_ind_direct_IO (rw, iocb, iov, offset, nr_segs);
@@ -4696,12 +4696,12 @@ void ext4_truncate(struct inode *inode)if (!ext4_can_truncate (inode))return ; -EXT4_I (inode)->i_flags &= ~EXT4_EOFBLOCKS_FL ; +ext4_clear_inode_flag (inode,EXT4_INODE_EOFBLOCKS );if (inode->i_size ==0 && !test_opt (inode->i_sb,NO_AUTO_DA_ALLOC ))ext4_set_inode_state (inode,EXT4_STATE_DA_ALLOC_CLOSE ); -if (EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL ) { +if (ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )) {ext4_ext_truncate (inode);return ; }
@@ -5539,7 +5539,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr) }if (attr->ia_valid &ATTR_SIZE ) { -if (!(EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL )) { +if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))) {struct ext4_sb_info *sbi =EXT4_SB (inode->i_sb);if (attr->ia_size > sbi->s_bitmap_maxbytes) {
@@ -5552,7 +5552,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)if (S_ISREG (inode->i_mode) && attr->ia_valid &ATTR_SIZE && (attr->ia_size < inode->i_size || - (EXT4_I (inode)->i_flags &EXT4_EOFBLOCKS_FL ))) { + (ext4_test_inode_flag (inode,EXT4_INODE_EOFBLOCKS )))) {handle_t *handle; handle =ext4_journal_start (inode,3 );
@@ -5584,7 +5584,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr) } }/* ext4_truncate will clear the flag */ -if ((EXT4_I (inode)->i_flags &EXT4_EOFBLOCKS_FL )) +if ((ext4_test_inode_flag (inode,EXT4_INODE_EOFBLOCKS )))ext4_truncate (inode); }
@@ -5660,7 +5660,7 @@ static int ext4_indirect_trans_blocks(struct inode *inode, int nrblocks,static int ext4_index_trans_blocks (struct inode *inode,int nrblocks,int chunk) { -if (!(EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL )) +if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )))return ext4_indirect_trans_blocks (inode, nrblocks, chunk);return ext4_ext_index_trans_blocks (inode, nrblocks, chunk); }
@@ -5995,9 +5995,9 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)*/ if (val) -EXT4_I (inode)->i_flags |=EXT4_JOURNAL_DATA_FL ; +ext4_set_inode_flag (inode,EXT4_INODE_JOURNAL_DATA );else -EXT4_I (inode)->i_flags &= ~EXT4_JOURNAL_DATA_FL ; +ext4_clear_inode_flag (inode,EXT4_INODE_JOURNAL_DATA );ext4_set_aops (inode);jbd2_journal_unlock_updates (journal);
fs/ext4/mballoc.c +2 -2
@@ -2006,7 +2006,7 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac) sbi =EXT4_SB (sb); ngroups =ext4_get_groups_count (sb);/* non-extent files are limited to low blocks/groups */ -if (!(EXT4_I (ac->ac_inode)->i_flags &EXT4_EXTENTS_FL )) +if (!(ext4_test_inode_flag (ac->ac_inode,EXT4_INODE_EXTENTS ))) ngroups = sbi->s_blockfile_groups;BUG_ON (ac->ac_status ==AC_STATUS_FOUND );
@@ -3171,7 +3171,7 @@ ext4_mb_use_preallocated(struct ext4_allocation_context *ac)continue ;/* non-extent files can't have physical blocks past 2^32 */ -if (!(EXT4_I (ac->ac_inode)->i_flags &EXT4_EXTENTS_FL ) && +if (!(ext4_test_inode_flag (ac->ac_inode,EXT4_INODE_EXTENTS )) && pa->pa_pstart + pa->pa_len >EXT4_MAX_BLOCK_FILE_PHYS )continue ;
fs/ext4/migrate.c +1 -1
@@ -475,7 +475,7 @@ int ext4_ext_migrate(struct inode *inode)*/ if (!EXT4_HAS_INCOMPAT_FEATURE (inode->i_sb,EXT4_FEATURE_INCOMPAT_EXTENTS ) || - (EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL )) + (ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )))return -EINVAL ;if (S_ISLNK (inode->i_mode) && inode->i_blocks ==0 )
fs/ext4/move_extent.c +2 -2
@@ -976,11 +976,11 @@ mext_check_arguments(struct inode *orig_inode, }/* Ext4 move extent supports only extent based file */ -if (!(EXT4_I (orig_inode)->i_flags &EXT4_EXTENTS_FL )) { +if (!(ext4_test_inode_flag (orig_inode,EXT4_INODE_EXTENTS ))) {ext4_debug ("ext4 move extent: orig file is not extents " "based file [ino:orig %lu]\n" , orig_inode->i_ino);return -EOPNOTSUPP ; - }else if (!(EXT4_I (donor_inode)->i_flags &EXT4_EXTENTS_FL )) { + }else if (!(ext4_test_inode_flag (donor_inode,EXT4_INODE_EXTENTS ))) {ext4_debug ("ext4 move extent: donor file is not extents " "based file [ino:donor %lu]\n" , donor_inode->i_ino);return -EOPNOTSUPP ;
fs/ext4/namei.c +5 -5
@@ -656,7 +656,7 @@ int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,dxtrace (printk (KERN_DEBUG "In htree_fill_tree, start hash: %x:%x\n" , start_hash, start_minor_hash)); dir = dir_file->f_path.dentry->d_inode; -if (!(EXT4_I (dir)->i_flags &EXT4_INDEX_FL )) { +if (!(ext4_test_inode_flag (dir,EXT4_INODE_INDEX ))) { hinfo.hash_version =EXT4_SB (dir->i_sb)->s_def_hash_version;if (hinfo.hash_version <=DX_HASH_TEA ) hinfo.hash_version +=
@@ -801,7 +801,7 @@ static void ext4_update_dx_flag(struct inode *inode) {if (!EXT4_HAS_COMPAT_FEATURE (inode->i_sb,EXT4_FEATURE_COMPAT_DIR_INDEX )) -EXT4_I (inode)->i_flags &= ~EXT4_INDEX_FL ; +ext4_clear_inode_flag (inode,EXT4_INODE_INDEX ); }/*
@@ -1418,7 +1418,7 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,brelse (bh);return retval; } -EXT4_I (dir)->i_flags |=EXT4_INDEX_FL ; +ext4_set_inode_flag (dir,EXT4_INODE_INDEX ); data1 = bh2->b_data;memcpy (data1, de, len);
@@ -1491,7 +1491,7 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, retval =ext4_dx_add_entry (handle, dentry, inode);if (!retval || (retval !=ERR_BAD_DX_DIR ))return retval; -EXT4_I (dir)->i_flags &= ~EXT4_INDEX_FL ; +ext4_clear_inode_flag (dir,EXT4_INODE_INDEX ); dx_fallback++;ext4_mark_inode_dirty (handle, dir); }
@@ -2297,7 +2297,7 @@ retry: } }else {/* clear the extent format for fast symlink */ -EXT4_I (inode)->i_flags &= ~EXT4_EXTENTS_FL ; +ext4_clear_inode_flag (inode,EXT4_INODE_EXTENTS ); inode->i_op = &ext4_fast_symlink_inode_operations;memcpy ((char *)&EXT4_I (inode)->i_data, symname, l); inode->i_size = l-1 ;
fs/ext4/super.c +1 -0
@@ -4139,6 +4139,7 @@ static int __init init_ext4_fs(void) {int err; +ext4_check_flag_values (); err =init_ext4_system_zone ();if (err)return err;
fs/ext4/xattr.c +2 -2
@@ -820,7 +820,7 @@ inserted: EXT4_I(inode)->i_block_group);/* non-extent files can't have physical blocks past 2^32 */ -if (!(EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL )) +if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))) goal = goal &EXT4_MAX_BLOCK_FILE_PHYS ; block = ext4_new_meta_blocks(handle, inode,
@@ -828,7 +828,7 @@ inserted:if (error) goto cleanup; -if (!(EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL )) +if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )))BUG_ON (block >EXT4_MAX_BLOCK_FILE_PHYS );ea_idebug (inode,"creating block %d" , block);
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 24/28 ext4: Clear the EXT4_EOFBLOCKS_FL flag only when warranted
In reply to Theodore Ts'ocommit 786ec7915e530936b9eb2e3d12274145cab7aa7d upstream (as of v2.6.34-git13)
Dimitry Monakhov discovered an edge case where it was possible for the EXT4_EOFBLOCKS_FL flag could get cleared unnecessarily. This is true; I have a test case that can be exercised via downloading and decompressing the file:
wget ftp://ftp.kernel.org/pub/linux/kernel/people/tytso/ext4-testcases/eofblocks-fl-test-case.img.bz2 bunzip2 eofblocks-fl-test-case.img
dd if=/dev/zero of=eofblocks-fl-test-case.img bs=1k seek=17925 bs=1k count=1 conv=notrunc
However, triggering it in real life is highly unlikely since it requires an extremely fragmented sparse file with a hole in exactly the right place in the extent tree. (It actually took quite a bit of work to generate this test case.) Still, it's nice to get even extreme corner cases to be correct, so this patch makes sure that we don't clear the EXT4_EOFBLOCKS_FL incorrectly even in this corner case.
--- fs/ext4/extents.c | 18 +++++++++++++++--- 1 files changed, 15 insertions(+), 3 deletions(-)
fs/ext4/extents.c +15 -3
@@ -3329,7 +3329,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,struct ext4_extent_header *eh;struct ext4_extent newex, *ex, *last_ex;ext4_fsblk_t newblock; -int err =0 , depth, ret, cache_type; +int i, err =0 , depth, ret, cache_type;unsigned int allocated =0 ;struct ext4_allocation_request ar;ext4_io_end_t *io =EXT4_I (inode)->cur_aio_dio;
@@ -3519,8 +3519,20 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, goto out2; } last_ex =EXT_LAST_EXTENT (eh); -if (iblock + ar.len >le32_to_cpu (last_ex->ee_block) - +ext4_ext_get_actual_len (last_ex)) +/* +* If the current leaf block was reached by looking at +* the last index block all the way down the tree, and +* we are extending the inode beyond the last extent +* in the current leaf block, then clear the +* EOFBLOCKS_FL flag. +*/ +for (i = depth-1 ; i >=0 ; i--) { +if (path[i].p_idx !=EXT_LAST_INDEX (path[i].p_hdr)) +break ; + } +if ((i <0 ) && + (iblock + ar.len >le32_to_cpu (last_ex->ee_block) + +ext4_ext_get_actual_len (last_ex)))ext4_clear_inode_flag (inode,EXT4_INODE_EOFBLOCKS ); } err =ext4_ext_insert_extent (handle, inode, path, &newex, flags);
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 25/28 ext4: restart ext4_ext_remove_space() after transaction restart
In reply to Theodore Ts'oFrom: Dmitry Monakhov <[email protected]>
commit 0617b83fa239db9743a18ce6cc0e556f4d0fd567 upstream (as of v2.6.34-git13)
If i_data_sem was internally dropped due to transaction restart, it is necessary to restart path look-up because extents tree was possibly modified by ext4_get_block().
https://bugzilla.kernel.org/show_bug.cgi?id=15827
--- fs/ext4/extents.c | 16 +++++++++------- 1 files changed, 9 insertions(+), 7 deletions(-)
fs/ext4/extents.c +9 -7
@@ -107,11 +107,8 @@ static int ext4_ext_truncate_extend_restart(handle_t *handle,if (err <=0 )return err; err =ext4_truncate_restart_trans (handle, inode, needed); -/* -* We have dropped i_data_sem so someone might have cached again -* an extent we are going to truncate. -*/ -ext4_ext_invalidate_cache (inode); +if (err ==0 ) + err = -EAGAIN ;return err; }
@@ -2361,7 +2358,7 @@ static int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start)int depth =ext_depth (inode);struct ext4_ext_path *path;handle_t *handle; -int i =0 , err =0 ; +int i, err;ext_debug ("truncate since %u\n" , start);
@@ -2370,23 +2367,26 @@ static int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start)if (IS_ERR (handle))return PTR_ERR (handle); +again:ext4_ext_invalidate_cache (inode);/* * We start scanning from right side, freeing all the blocks * after i_size and walking into the tree depth-wise. */ + depth =ext_depth (inode); path =kzalloc (sizeof (struct ext4_ext_path ) * (depth +1 ),GFP_NOFS );if (path ==NULL ) {ext4_journal_stop (handle);return -ENOMEM ; } + path[0 ].p_depth = depth; path[0 ].p_hdr =ext_inode_hdr (inode);if (ext4_ext_check (inode, path[0 ].p_hdr, depth)) { err = -EIO ; goto out; } - path[0 ].p_depth = depth; + i = err =0 ;while (i >=0 && err ==0 ) {if (i == depth) {
@@ -2480,6 +2480,8 @@ static int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start) out:ext4_ext_drop_refs (path);kfree (path); +if (err == -EAGAIN ) + goto again;ext4_journal_stop (handle);return err;
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 26/28 ext4: Conditionally define compat ioctl numbers
In reply to Theodore Ts'oFrom: Ben Hutchings <[email protected]>
commit 899ad0cea6ad7ff4ba24b16318edbc3cbbe03fad upstream (as of v2.6.34-git13)
It is unnecessary, and in general impossible, to define the compat ioctl numbers except when building the filesystem with CONFIG_COMPAT defined.
--- fs/ext4/ext4.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
fs/ext4/ext4.h +2 -0
@@ -475,6 +475,7 @@ struct ext4_new_group_data {#define EXT4_IOC_ALLOC_DA_BLKS _IO('f', 12)#define EXT4_IOC_MOVE_EXT _IOWR('f', 15, struct move_extent) +#if defined(__KERNEL__) && defined(CONFIG_COMPAT )/* * ioctl commands in 32 bit emulation */
@@ -490,6 +491,7 @@ struct ext4_new_group_data {#endif #define EXT4_IOC32_GETVERSION_OLD FS_IOC32_GETVERSION#define EXT4_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION +#endif /*
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 28/28 ext4: Make fsync sync new parent directories in no-journal mode
In reply to Theodore Ts'oFrom: Frank Mayhar <[email protected]>
commit 14ece1028b3ed53ffec1b1213ffc6acaf79ad77c upstream (as of v2.6.34-git13)
Add a new ext4 state to tell us when a file has been newly created; use that state in ext4_sync_file in no-journal mode to tell us when we need to sync the parent directory as well as the inode and data itself. This fixes a problem in which a panic or power failure may lose the entire file even when using fsync, since the parent directory entry is lost.
Addresses-Google-Bug: #2480057
--- fs/ext4/ext4.h | 1 + fs/ext4/fsync.c | 31 +++++++++++++++++++++++++++++-- fs/ext4/namei.c | 2 ++ 3 files changed, 32 insertions(+), 2 deletions(-)
fs/ext4/ext4.h +1 -0
@@ -1157,6 +1157,7 @@ enum {EXT4_STATE_DA_ALLOC_CLOSE ,/* Alloc DA blks on close */ EXT4_STATE_EXT_MIGRATE ,/* Inode is migrating */ EXT4_STATE_DIO_UNWRITTEN ,/* need convert on dio done*/ + EXT4_STATE_NEWENTRY, /* File just added to dir */ };#define EXT4_INODE_BIT_FNS (name, field) \
fs/ext4/fsync.c +29 -2
@@ -35,6 +35,29 @@#include <trace/events/ext4.h> /* +* If we're not journaling and this is a just-created file, we have to +* sync our parent directory (if it was freshly created) since +* otherwise it will only be written by writeback, leaving a huge +* window during which a crash may lose the file. This may apply for +* the parent directory's parent as well, and so on recursively, if +* they are also freshly created. +*/ +static void ext4_sync_parent (struct inode *inode) +{ +struct dentry *dentry =NULL ; + +while (inode &&ext4_test_inode_state (inode,EXT4_STATE_NEWENTRY )) { +ext4_clear_inode_state (inode,EXT4_STATE_NEWENTRY ); + dentry =list_entry (inode->i_dentry.next, + struct dentry, d_alias); +if (!dentry || !dentry->d_parent || !dentry->d_parent->d_inode) +break ; + inode = dentry->d_parent->d_inode; +sync_mapping_buffers (inode->i_mapping); + } +} + +/* * akpm: A new design for ext4_sync_file(). * * This is only called from sys_fsync(), sys_fdatasync() and sys_msync().
@@ -67,8 +90,12 @@ int ext4_sync_file(struct file *file, struct dentry *dentry, int datasync)if (ret <0 )return ret; -if (!journal) -return simple_fsync (file, dentry, datasync); +if (!journal) { + ret =simple_fsync (file, dentry, datasync); +if (!ret && !list_empty (&inode->i_dentry)) +ext4_sync_parent (inode); +return ret; + }/* * data=writeback,ordered:
fs/ext4/namei.c +2 -0
@@ -1519,6 +1519,8 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, de->rec_len =ext4_rec_len_to_disk (blocksize, blocksize); retval =add_dirent_to_buf (handle, dentry, inode, de, bh);brelse (bh); +if (retval ==0 ) +ext4_set_inode_state (inode,EXT4_STATE_NEWENTRY );return retval; }
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 10/28 ext4: don't scan/accumulate more pages than mballoc will allocate
In reply to Theodore Ts'oFrom: Eric Sandeen <[email protected]>
commit c445e3e0a5c2804524dec6e55f66d63f6bc5bc3e upstream (as of v2.6.34-git13)
There was a bug reported on RHEL5 that a 10G dd on a 12G box had a very, very slow sync after that.
At issue was the loop in write_cache_pages scanning all the way to the end of the 10G file, even though the subsequent call to mpage_da_submit_io would only actually write a smallish amt; then we went back to the write_cache_pages loop ... wasting tons of time in calling __mpage_da_writepage for thousands of pages we would just revisit (many times) later.
Upstream it's not such a big issue for sys_sync because we get to the loop with a much smaller nr_to_write, which limits the loop.
However, talking with Aneesh he realized that fsync upstream still gets here with a very large nr_to_write and we face the same problem.
This patch makes mpage_add_bh_to_extent stop the loop after we've accumulated 2048 pages, by setting mpd->io_done = 1; which ultimately causes the write_cache_pages loop to break.
Repeating the test with a dirty_ratio of 80 (to leave something for fsync to do), I don't see huge IO performance gains, but the reduction in cpu usage is striking: 80% usage with stock, and 2% with the below patch. Instrumenting the loop in write_cache_pages clearly shows that we are wasting time here.
Eventually we need to change mpage_da_map_pages() also submit its I/O to the block layer, subsuming mpage_da_submit_io(), and then change it call ext4_get_blocks() multiple times.
--- fs/ext4/inode.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
fs/ext4/inode.c +9 -0
@@ -2350,6 +2350,15 @@ static void mpage_add_bh_to_extent(struct mpage_da_data *mpd,sector_t next;int nrblocks = mpd->b_size >> mpd->inode->i_blkbits; +/* +* XXX Don't go larger than mballoc is willing to allocate +* This is a stopgap solution. We eventually need to fold +* mpage_da_submit_io() into this function and then call +* ext4_get_blocks() multiple times in a loop +*/ +if (nrblocks >=8 *1024 *1024 /mpd->inode->i_sb->s_blocksize) + goto flush_it; +/* check if thereserved journal credits might overflow */ if (!(EXT4_I (mpd->inode)->i_flags &EXT4_EXTENTS_FL )) {if (nrblocks >=EXT4_MAX_TRANS_DATA ) {
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 5/28 ext4: allow defrag (EXT4_IOC_MOVE_EXT) in 32bit compat mode
In reply to Theodore Ts'oFrom: Christian Borntraeger <[email protected]>
commit b684b2ee9409f2890a8b3aea98525bbe5f84e276 upstream (as of v2.6.34-git13)
I have an x86_64 kernel with i386 userspace. e4defrag fails on the EXT4_IOC_MOVE_EXT ioctl because it is not wired up for the compat case. It seems that struct move_extent is compat save, only types with fixed widths are used:
{
__u32 reserved; /* should be zero */
__u32 donor_fd; /* donor file descriptor */
__u64 orig_start; /* logical start offset in block for orig */
__u64 donor_start; /* logical start offset in block for donor */
__u64 len; /* block length to be moved */
__u64 moved_len; /* moved block length */};
Lets just wire up EXT4_IOC_MOVE_EXT for the compat case.
--- fs/ext4/ioctl.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
fs/ext4/ioctl.c +2 -0
@@ -375,6 +375,8 @@ long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)break ;case EXT4_IOC_GROUP_ADD :break ; +case EXT4_IOC_MOVE_EXT : +break ;default :return -ENOIOCTLCMD ; }
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 11/28 ext4: Do not zero out uninitialized extents beyond i_size
In reply to Theodore Ts'oFrom: Dmitry Monakhov <[email protected]>
commit 21ca087a3891efab4d45488db8febee474d26c68 upstream (as of v2.6.34-git13)
The extents code will sometimes zero out blocks and mark them as initialized instead of splitting an extent into several smaller ones. This optimization however, causes problems if the extent is beyond i_size because fsck will complain if there are uninitialized blocks after i_size as this can not be distinguished from an inode that has an incorrect i_size field.
https://bugzilla.kernel.org/show_bug.cgi?id=15742
--- fs/ext4/extents.c | 67 ++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 51 insertions(+), 16 deletions(-)
fs/ext4/extents.c +51 -16
@@ -2631,11 +2631,21 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,struct ext4_extent *ex2 =NULL ;struct ext4_extent *ex3 =NULL ;struct ext4_extent_header *eh; -ext4_lblk_t ee_block; +ext4_lblk_t ee_block, eof_block;unsigned int allocated, ee_len, depth;ext4_fsblk_t newblock;int err =0 ;int ret =0 ; +int may_zeroout; + +ext_debug ("ext4_ext_convert_to_initialized: inode %lu, logical" +"block %llu, max_blocks %u\n" , inode->i_ino, + (unsigned long long )iblock, max_blocks); + + eof_block = (inode->i_size + inode->i_sb->s_blocksize -1 ) >> + inode->i_sb->s_blocksize_bits; +if (eof_block < iblock + max_blocks) + eof_block = iblock + max_blocks; depth =ext_depth (inode); eh = path[depth].p_hdr;
@@ -2644,16 +2654,23 @@ static int ext4_ext_convert_to_initialized(handle_t *handle, ee_len =ext4_ext_get_actual_len (ex); allocated = ee_len - (iblock - ee_block); newblock = iblock - ee_block +ext_pblock (ex); + ex2 = ex; orig_ex.ee_block = ex->ee_block; orig_ex.ee_len =cpu_to_le16 (ee_len);ext4_ext_store_pblock (&orig_ex,ext_pblock (ex)); +/* +* It is safe to convert extent to initialized via explicit +* zeroout only if extent is fully insde i_size or new_size. +*/ + may_zeroout = ee_block + ee_len <= eof_block; + err =ext4_ext_get_access (handle, inode, path + depth);if (err) goto out;/* If extent has less than 2*EXT4_EXT_ZERO_LEN zerout directly */ -if (ee_len <=2 *EXT4_EXT_ZERO_LEN ) { +if (ee_len <=2 *EXT4_EXT_ZERO_LEN && may_zeroout) { err =ext4_ext_zeroout (inode, &orig_ex);if (err) goto fix_extent_len;
@@ -2684,7 +2701,7 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,if (allocated > max_blocks) {unsigned int newdepth;/* If extent has less than EXT4_EXT_ZERO_LEN zerout directly */ -if (allocated <=EXT4_EXT_ZERO_LEN ) { +if (allocated <=EXT4_EXT_ZERO_LEN && may_zeroout) {/* * iblock == ee_block is handled by the zerouout * at the beginning.
@@ -2760,7 +2777,7 @@ static int ext4_ext_convert_to_initialized(handle_t *handle, ex3->ee_len =cpu_to_le16 (allocated - max_blocks);ext4_ext_mark_uninitialized (ex3); err =ext4_ext_insert_extent (handle, inode, path, ex3,0 ); -if (err == -ENOSPC ) { +if (err == -ENOSPC && may_zeroout) { err =ext4_ext_zeroout (inode, &orig_ex);if (err) goto fix_extent_len;
@@ -2784,8 +2801,10 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,* update the extent length after successful insert of the * split extent */ - orig_ex.ee_len =cpu_to_le16 (ee_len - -ext4_ext_get_actual_len (ex3)); + ee_len -=ext4_ext_get_actual_len (ex3); + orig_ex.ee_len =cpu_to_le16 (ee_len); + may_zeroout = ee_block + ee_len <= eof_block; + depth = newdepth;ext4_ext_drop_refs (path); path =ext4_ext_find_extent (inode, iblock, path);
@@ -2809,7 +2828,7 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,* otherwise give the extent a chance to merge to left */ if (le16_to_cpu (orig_ex.ee_len) <=EXT4_EXT_ZERO_LEN && - iblock != ee_block) { + iblock != ee_block && may_zeroout) { err =ext4_ext_zeroout (inode, &orig_ex);if (err) goto fix_extent_len;
@@ -2878,7 +2897,7 @@ static int ext4_ext_convert_to_initialized(handle_t *handle, goto out; insert: err =ext4_ext_insert_extent (handle, inode, path, &newex,0 ); -if (err == -ENOSPC ) { +if (err == -ENOSPC && may_zeroout) { err =ext4_ext_zeroout (inode, &orig_ex);if (err) goto fix_extent_len;
@@ -2938,14 +2957,21 @@ static int ext4_split_unwritten_extents(handle_t *handle,struct ext4_extent *ex2 =NULL ;struct ext4_extent *ex3 =NULL ;struct ext4_extent_header *eh; -ext4_lblk_t ee_block; +ext4_lblk_t ee_block, eof_block;unsigned int allocated, ee_len, depth;ext4_fsblk_t newblock;int err =0 ; +int may_zeroout; + +ext_debug ("ext4_split_unwritten_extents: inode %lu, logical" +"block %llu, max_blocks %u\n" , inode->i_ino, + (unsigned long long )iblock, max_blocks); + + eof_block = (inode->i_size + inode->i_sb->s_blocksize -1 ) >> + inode->i_sb->s_blocksize_bits; +if (eof_block < iblock + max_blocks) + eof_block = iblock + max_blocks; -ext_debug ("ext4_split_unwritten_extents: inode %lu," -"iblock %llu, max_blocks %u\n" , inode->i_ino, - (unsigned long long )iblock, max_blocks); depth =ext_depth (inode); eh = path[depth].p_hdr; ex = path[depth].p_ext;
@@ -2953,12 +2979,19 @@ static int ext4_split_unwritten_extents(handle_t *handle, ee_len =ext4_ext_get_actual_len (ex); allocated = ee_len - (iblock - ee_block); newblock = iblock - ee_block +ext_pblock (ex); + ex2 = ex; orig_ex.ee_block = ex->ee_block; orig_ex.ee_len =cpu_to_le16 (ee_len);ext4_ext_store_pblock (&orig_ex,ext_pblock (ex));/* +* It is safe to convert extent to initialized via explicit +* zeroout only if extent is fully insde i_size or new_size. +*/ + may_zeroout = ee_block + ee_len <= eof_block; + +/* * If the uninitialized extent begins at the same logical * block where the write begins, and the write completely * covers the extent, then we don't need to split it.
@@ -2992,7 +3025,7 @@ static int ext4_split_unwritten_extents(handle_t *handle, ex3->ee_len =cpu_to_le16 (allocated - max_blocks);ext4_ext_mark_uninitialized (ex3); err =ext4_ext_insert_extent (handle, inode, path, ex3, flags); -if (err == -ENOSPC ) { +if (err == -ENOSPC && may_zeroout) { err =ext4_ext_zeroout (inode, &orig_ex);if (err) goto fix_extent_len;
@@ -3016,8 +3049,10 @@ static int ext4_split_unwritten_extents(handle_t *handle,* update the extent length after successful insert of the * split extent */ - orig_ex.ee_len =cpu_to_le16 (ee_len - -ext4_ext_get_actual_len (ex3)); + ee_len -=ext4_ext_get_actual_len (ex3); + orig_ex.ee_len =cpu_to_le16 (ee_len); + may_zeroout = ee_block + ee_len <= eof_block; + depth = newdepth;ext4_ext_drop_refs (path); path =ext4_ext_find_extent (inode, iblock, path);
@@ -3063,7 +3098,7 @@ static int ext4_split_unwritten_extents(handle_t *handle, goto out; insert: err =ext4_ext_insert_extent (handle, inode, path, &newex, flags); -if (err == -ENOSPC ) { +if (err == -ENOSPC && may_zeroout) { err =ext4_ext_zeroout (inode, &orig_ex);if (err) goto fix_extent_len;
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 13/28 ext4: init statistics after journal recovery
In reply to Theodore Ts'oFrom: Dmitry Monakhov <[email protected]>
commit 84061e07c5fbbbf9dc8aef8fb750fc3a2dfc31f3 upstream (as of v2.6.34-git13)
Currently block/inode/dir counters initialized before journal was recovered. In fact after journal recovery this info will probably change. And freeblocks it critical for correct delalloc mode accounting.
https://bugzilla.kernel.org/show_bug.cgi?id=15768
--- fs/ext4/super.c | 40 ++++++++++++++++++---------------------- 1 files changed, 18 insertions(+), 22 deletions(-)
fs/ext4/super.c +18 -22
@@ -2794,24 +2794,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)get_random_bytes (&sbi->s_next_generation,sizeof (u32));spin_lock_init (&sbi->s_next_gen_lock); - err =percpu_counter_init (&sbi->s_freeblocks_counter, -ext4_count_free_blocks (sb)); -if (!err) { - err =percpu_counter_init (&sbi->s_freeinodes_counter, -ext4_count_free_inodes (sb)); - } -if (!err) { - err =percpu_counter_init (&sbi->s_dirs_counter, -ext4_count_dirs (sb)); - } -if (!err) { - err =percpu_counter_init (&sbi->s_dirtyblocks_counter,0 ); - } -if (err) { -ext4_msg (sb,KERN_ERR ,"insufficient memory" ); - goto failed_mount3; - } - sbi->s_stripe =ext4_get_stripe_size (sbi); sbi->s_max_writeback_mb_bump =128 ;
@@ -2911,6 +2893,20 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)set_task_ioprio (sbi->s_journal->j_task, journal_ioprio); no_journal: + err =percpu_counter_init (&sbi->s_freeblocks_counter, +ext4_count_free_blocks (sb)); +if (!err) + err =percpu_counter_init (&sbi->s_freeinodes_counter, +ext4_count_free_inodes (sb)); +if (!err) + err =percpu_counter_init (&sbi->s_dirs_counter, +ext4_count_dirs (sb)); +if (!err) + err =percpu_counter_init (&sbi->s_dirtyblocks_counter,0 ); +if (err) { +ext4_msg (sb,KERN_ERR ,"insufficient memory" ); + goto failed_mount_wq; + }if (test_opt (sb,NOBH )) {if (!(test_opt (sb,DATA_FLAGS ) ==EXT4_MOUNT_WRITEBACK_DATA )) { ext4_msg(sb, KERN_WARNING, "Ignoring nobh option - "
@@ -3060,6 +3056,10 @@ failed_mount_wq:jbd2_journal_destroy (sbi->s_journal); sbi->s_journal =NULL ; } +percpu_counter_destroy (&sbi->s_freeblocks_counter); +percpu_counter_destroy (&sbi->s_freeinodes_counter); +percpu_counter_destroy (&sbi->s_dirs_counter); +percpu_counter_destroy (&sbi->s_dirtyblocks_counter); failed_mount3:if (sbi->s_flex_groups) {if (is_vmalloc_addr (sbi->s_flex_groups))
@@ -3067,10 +3067,6 @@ failed_mount3:else kfree (sbi->s_flex_groups); } -percpu_counter_destroy (&sbi->s_freeblocks_counter); -percpu_counter_destroy (&sbi->s_freeinodes_counter); -percpu_counter_destroy (&sbi->s_dirs_counter); -percpu_counter_destroy (&sbi->s_dirtyblocks_counter); failed_mount2:for (i =0 ; i < db_count; i++)brelse (sbi->s_group_desc[i]);
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 14/28 quota: use flags interface for dquot alloc/free space
In reply to Theodore Ts'oFrom: Eric Sandeen <[email protected]>
commit 56246f9ae4cfa95b460f9dfbcfb1b772d85db046 upstream (as of 2.6.34-git13)
Switch __dquot_alloc_space and __dquot_free_space to take flags to indicate whether to warn and/or to reserve (or free reserve).
This is slightly more readable at the callpoints, and makes it cleaner to add a "nofail" option in the next patch.
--- fs/quota/dquot.c | 8 +++++--- include/linux/quotaops.h | 25 ++++++++++++++----------- 2 files changed, 19 insertions(+), 14 deletions(-)
fs/quota/dquot.c +5 -3
@@ -1488,11 +1488,12 @@ static void inode_decr_space(struct inode *inode, qsize_t number, int reserve)/* * This operation can block, but only after everything is updated */ -int __dquot_alloc_space (struct inode *inode,qsize_t number, -int warn,int reserve) +int __dquot_alloc_space (struct inode *inode,qsize_t number,int flags) {int cnt, ret =0 ;char warntype[MAXQUOTAS ]; +int warn = flags &DQUOT_SPACE_WARN ; +int reserve = flags &DQUOT_SPACE_RESERVE ;/* * First test before acquiring mutex - solves deadlocks when we
@@ -1612,10 +1613,11 @@ EXPORT_SYMBOL(dquot_claim_space_nodirty);/* * This operation can block, but only after everything is updated */ -void __dquot_free_space (struct inode *inode,qsize_t number,int reserve) +void __dquot_free_space (struct inode *inode,qsize_t number,int flags) {unsigned int cnt;char warntype[MAXQUOTAS ]; +int reserve = flags &DQUOT_SPACE_RESERVE ;/* First test before acquiring mutex - solves deadlocks when we * re-enter the quota code and are already holding the mutex */
include/linux/quotaops.h +14 -11
@@ -9,6 +9,9 @@#include <linux/fs.h> +#define DQUOT_SPACE_WARN 0x1 +#define DQUOT_SPACE_RESERVE 0x2 +static inline struct quota_info *sb_dqopt (struct super_block *sb) {return &sb->s_dquot;
@@ -33,9 +36,8 @@ int dquot_scan_active(struct super_block *sb,struct dquot *dquot_alloc (struct super_block *sb,int type);void dquot_destroy (struct dquot *dquot); -int __dquot_alloc_space (struct inode *inode,qsize_t number, -int warn,int reserve); -void __dquot_free_space (struct inode *inode,qsize_t number,int reserve); +int __dquot_alloc_space (struct inode *inode,qsize_t number,int flags); +void __dquot_free_space (struct inode *inode,qsize_t number,int flags);int dquot_alloc_inode (const struct inode *inode);
@@ -231,17 +233,17 @@ static inline int dquot_transfer(struct inode *inode, struct iattr *iattr) }static inline int __dquot_alloc_space (struct inode *inode,qsize_t number, -int warn,int reserve) +int flags) { -if (!reserve) +if (!(flags &DQUOT_SPACE_RESERVE ))inode_add_bytes (inode, number);return 0 ; }static inline void __dquot_free_space (struct inode *inode,qsize_t number, -int reserve) +int flags) { -if (!reserve) +if (!(flags &DQUOT_SPACE_RESERVE ))inode_sub_bytes (inode, number); }
@@ -257,7 +259,7 @@ static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)static inline int dquot_alloc_space_nodirty (struct inode *inode,qsize_t nr) { -return __dquot_alloc_space (inode, nr,1 ,0 ); +return __dquot_alloc_space (inode, nr,DQUOT_SPACE_WARN ); }static inline int dquot_alloc_space (struct inode *inode,qsize_t nr)
@@ -282,7 +284,7 @@ static inline int dquot_alloc_block(struct inode *inode, qsize_t nr)static inline int dquot_prealloc_block_nodirty (struct inode *inode,qsize_t nr) { -return __dquot_alloc_space (inode, nr << inode->i_blkbits,0 ,0 ); +return __dquot_alloc_space (inode, nr << inode->i_blkbits,0 ); }static inline int dquot_prealloc_block (struct inode *inode,qsize_t nr)
@@ -297,7 +299,8 @@ static inline int dquot_prealloc_block(struct inode *inode, qsize_t nr)static inline int dquot_reserve_block (struct inode *inode,qsize_t nr) { -return __dquot_alloc_space (inode, nr << inode->i_blkbits,1 ,1 ); +return __dquot_alloc_space (inode, nr << inode->i_blkbits, +DQUOT_SPACE_WARN |DQUOT_SPACE_RESERVE ); }static inline int dquot_claim_block (struct inode *inode,qsize_t nr)
@@ -334,7 +337,7 @@ static inline void dquot_free_block(struct inode *inode, qsize_t nr)static inline void dquot_release_reservation_block (struct inode *inode,qsize_t nr) { -__dquot_free_space (inode, nr << inode->i_blkbits,1 ); +__dquot_free_space (inode, nr << inode->i_blkbits,DQUOT_SPACE_RESERVE ); }#endif /* _LINUX_QUOTAOPS_ */
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 15/28 quota: add the option to not fail with EDQUOT in block
In reply to Theodore Ts'oFrom: Eric Sandeen <[email protected]>
commit 0e05842bc117ea70ceb979cca798fd026879951b upstream (as of 2.6.34-git13)
To simplify metadata tracking for delalloc writes, ext4 will simply claim metadata blocks at allocation time, without first speculatively reserving the worst case and then freeing what was not used.
To do this, we need a mechanism to track allocations in the quota subsystem, but potentially allow that allocation to actually go over quota.
This patch adds a DQUOT_SPACE_NOFAIL flag and function variants for this purpose.
--- fs/quota/dquot.c | 3 ++- include/linux/quotaops.h | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletions(-)
fs/quota/dquot.c +2 -1
@@ -1494,6 +1494,7 @@ int __dquot_alloc_space(struct inode *inode, qsize_t number, int flags)char warntype[MAXQUOTAS ];int warn = flags &DQUOT_SPACE_WARN ;int reserve = flags &DQUOT_SPACE_RESERVE ; +int nofail = flags &DQUOT_SPACE_NOFAIL ;/* * First test before acquiring mutex - solves deadlocks when we
@@ -1514,7 +1515,7 @@ int __dquot_alloc_space(struct inode *inode, qsize_t number, int flags)continue ; ret =check_bdq (inode->i_dquot[cnt], number, !warn, warntype+cnt); -if (ret) { +if (ret && !nofail) {spin_unlock (&dq_data_lock); goto out_flush_warn; }
include/linux/quotaops.h +12 -0
@@ -11,6 +11,7 @@#define DQUOT_SPACE_WARN 0x1#define DQUOT_SPACE_RESERVE 0x2 +#define DQUOT_SPACE_NOFAIL 0x4static inline struct quota_info *sb_dqopt (struct super_block *sb) {
@@ -262,6 +263,12 @@ static inline int dquot_alloc_space_nodirty(struct inode *inode, qsize_t nr)return __dquot_alloc_space (inode, nr,DQUOT_SPACE_WARN ); } +static inline void dquot_alloc_space_nofail (struct inode *inode,qsize_t nr) +{ +__dquot_alloc_space (inode, nr,DQUOT_SPACE_WARN |DQUOT_SPACE_NOFAIL ); +mark_inode_dirty (inode); +} +static inline int dquot_alloc_space (struct inode *inode,qsize_t nr) {int ret;
@@ -277,6 +284,11 @@ static inline int dquot_alloc_block_nodirty(struct inode *inode, qsize_t nr)return dquot_alloc_space_nodirty (inode, nr << inode->i_blkbits); } +static inline void dquot_alloc_block_nofail (struct inode *inode,qsize_t nr) +{ +dquot_alloc_space_nofail (inode, nr << inode->i_blkbits); +} +static inline int dquot_alloc_block (struct inode *inode,qsize_t nr) {return dquot_alloc_space (inode, nr << inode->i_blkbits);
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 16/28 ext4: don't use quota reservation for speculative metadata
In reply to Theodore Ts'oFrom: Eric Sandeen <[email protected]>
commit 72b8ab9dde211ea518ff27e631b2046ef90c29a2 upstream (as of 2.6.34-git13)
Because we can badly over-reserve metadata when we calculate worst-case, it complicates things for quota, since we must reserve and then claim later, retry on EDQUOT, etc. Quota is also a generally smaller pool than fs free blocks, so this over-reservation hurts more, and more often.
I'm of the opinion that it's not the worst thing to allow metadata to push a user slightly over quota. This simplifies the code and avoids the false quota rejections that result from worst-case speculation.
This patch stops the speculative quota-charging for worst-case metadata requirements, and just charges quota when the blocks are allocated at writeout. It also is able to remove the try-again loop on EDQUOT.
This patch has been tested indirectly by running the xfstests suite with a hack to mount & enable quota prior to the test.
I also did a more specific test of fragmenting freespace and then doing a large delalloc write under quota; quota stopped me at the right amount of file IO, and then the writeout generated enough metadata (due to the fragmentation) that it put me slightly over quota, as expected.
--- fs/ext4/balloc.c | 5 ++- fs/ext4/inode.c | 69 ++++++++++++++++++------------------------------------ 2 files changed, 26 insertions(+), 48 deletions(-)
fs/ext4/balloc.c +3 -2
@@ -591,14 +591,15 @@ ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode, ret =ext4_mb_new_blocks (handle, &ar, errp);if (count) *count = ar.len; -/* -* Account for the allocated meta blocks +* Account for the allocated meta blocks. We will never +* fail EDQUOT for metdata, but we do account for it. */ if (!(*errp) &&EXT4_I (inode)->i_delalloc_reserved_flag) {spin_lock (&EXT4_I (inode)->i_block_reservation_lock);EXT4_I (inode)->i_allocated_meta_blocks += ar.len;spin_unlock (&EXT4_I (inode)->i_block_reservation_lock); +dquot_alloc_block_nofail (inode, ar.len); }return ret; }
fs/ext4/inode.c +23 -30
123 lines not on this page · raw message
Theodore Ts'o
maintainerPATCH 19/28 ext4: check for a good block group before loading buddy pages
In reply to Theodore Ts'oFrom: Curt Wohlgemuth <[email protected]>
commit 8a57d9d61a6e361c7bb159dda797672c1df1a691 upstream (as of v2.6.34-git13)
This adds a new field in ext4_group_info to cache the largest available block range in a block group; and don't load the buddy pages until *after* we've done a sanity check on the block group.
With large allocation requests (e.g., fallocate(), 8MiB) and relatively full partitions, it's easy to have no block groups with a block extent large enough to satisfy the input request length. This currently causes the loop during cr == 0 in ext4_mb_regular_allocator() to load the buddy bitmap pages for EVERY block group. That can be a lot of pages. The patch below allows us to call ext4_mb_good_group() BEFORE we load the buddy pages (although we have check again after we lock the block group).
Addresses-Google-Bug: #2578108
Addresses-Google-Bug: #2704453
--- fs/ext4/ext4.h | 1 + fs/ext4/mballoc.c | 70 +++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 58 insertions(+), 13 deletions(-)
fs/ext4/ext4.h +1 -0
@@ -1678,6 +1678,7 @@ struct ext4_group_info {ext4_grpblk_t bb_first_free;/* first free block */ ext4_grpblk_t bb_free;/* total free blocks */ ext4_grpblk_t bb_fragments;/* nr of freespace fragments */ +ext4_grpblk_t bb_largest_free_order;/* order of largest frag in BG */ struct list_head bb_prealloc_list;#ifdef DOUBLE_CHECK void *bb_bitmap;
fs/ext4/mballoc.c +57 -13
160 lines not on this page · raw message
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 20/28 ext4: Show journal_checksum option
In reply to Theodore Ts'oFrom: Jan Kara <[email protected]>
commit 39a4bade8c1826b658316d66ee81c09b0a4d7d42 upstream (as of v2.6.34-git13)
We failed to show journal_checksum option in /proc/mounts. Fix it.
--- fs/ext4/super.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
fs/ext4/super.c +2 -0
@@ -942,6 +942,8 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)seq_puts (seq,test_opt (sb,BARRIER ) ?"1" :"0" );if (test_opt (sb,JOURNAL_ASYNC_COMMIT ))seq_puts (seq,",journal_async_commit" ); +else if (test_opt (sb,JOURNAL_CHECKSUM )) +seq_puts (seq,",journal_checksum" );if (test_opt (sb,NOBH ))seq_puts (seq,",nobh" );if (test_opt (sb,I_VERSION ))
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 21/28 ext4: Use our own write_cache_pages()
In reply to Theodore Ts'oMake a copy of write_cache_pages() for the benefit of ext4_da_writepages(). This allows us to simplify the code some, and will allow us to further customize the code in future patches.
There are some nasty hacks in write_cache_pages(), which Linus has (correctly) characterized as vile. I've just copied it into write_cache_pages_da(), without trying to clean those bits up lest I break something in the ext4's delalloc implementation, which is a bit fragile right now. This will allow Dave Chinner to clean up write_cache_pages() in mm/page-writeback.c, without worrying about breaking ext4. Eventually write_cache_pages_da() will go away when I rewrite ext4's delayed allocation and create a general ext4_writepages() which is used for all of ext4's writeback. Until now this is the lowest risk way to clean up the core write_cache_pages() function.
--- fs/ext4/inode.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 119 insertions(+), 22 deletions(-)
fs/ext4/inode.c +119 -22
@@ -2426,17 +2426,6 @@ static int __mpage_da_writepage(struct page *page,struct buffer_head *bh, *head;sector_t logical; -if (mpd->io_done) { -/* -* Rest of the page in the page_vec -* redirty then and skip then. We will -* try to write them again after -* starting a new transaction -*/ -redirty_page_for_writepage (wbc, page); -unlock_page (page); -return MPAGE_DA_EXTENT_TAIL ; - }/* * Can we merge this page to current extent? */
@@ -2831,6 +2820,124 @@ static int ext4_da_writepages_trans_blocks(struct inode *inode)return ext4_chunk_trans_blocks (inode, max_blocks); } +/* +* write_cache_pages_da - walk the list of dirty pages of the given +* address space and call the callback function (which usually writes +* the pages). +* +* This is a forked version of write_cache_pages(). Differences: +* Range cyclic is ignored. +* no_nrwrite_index_update is always presumed true +*/ +static int write_cache_pages_da (struct address_space *mapping, +struct writeback_control *wbc, +struct mpage_da_data *mpd) +{ +int ret =0 ; +int done =0 ; +struct pagevec pvec; +int nr_pages; +pgoff_t index; +pgoff_t end;/* Inclusive */ +long nr_to_write = wbc->nr_to_write; + +pagevec_init (&pvec,0 ); + index = wbc->range_start >>PAGE_CACHE_SHIFT ; + end = wbc->range_end >>PAGE_CACHE_SHIFT ; + +while (!done && (index <= end)) { +int i; + + nr_pages =pagevec_lookup_tag (&pvec, mapping, &index, +PAGECACHE_TAG_DIRTY , +min (end - index, (pgoff_t )PAGEVEC_SIZE -1 ) +1 ); +if (nr_pages ==0 ) +break ; + +for (i =0 ; i < nr_pages; i++) { +struct page *page = pvec.pages[i]; + +/* +* At this point, the page may be truncated or +* invalidated (changing page->mapping to NULL), or +* even swizzled back from swapper_space to tmpfs file +* mapping. However, page->index will not change +* because we have a reference on the page. +*/ +if (page->index > end) { + done =1 ; +break ; + } + +lock_page (page); + +/* +* Page truncated or invalidated. We can freely skip it +* then, even for data integrity operations: the page +* has disappeared concurrently, so there could be no +* real expectation of this data interity operation +* even if there is now a new, dirty page at the same +* pagecache address. +*/ +if (unlikely (page->mapping != mapping)) { +continue_unlock: +unlock_page (page); +continue ; + } + +if (!PageDirty (page)) { +/* someone wrote it for us */ + goto continue_unlock; + } + +if (PageWriteback (page)) { +if (wbc->sync_mode !=WB_SYNC_NONE ) +wait_on_page_writeback (page); +else + goto continue_unlock; + } + +BUG_ON (PageWriteback (page)); +if (!clear_page_dirty_for_io (page)) + goto continue_unlock; + + ret =__mpage_da_writepage (page, wbc, mpd); +if (unlikely (ret)) { +if (ret ==AOP_WRITEPAGE_ACTIVATE ) { +unlock_page (page); + ret =0 ; + }else { + done =1 ; +break ; + } + } + +if (nr_to_write >0 ) { + nr_to_write--; +if (nr_to_write ==0 && + wbc->sync_mode ==WB_SYNC_NONE ) { +/* +* We stop writing back only if we are +* not doing integrity sync. In case of +* integrity sync we have to keep going +* because someone may be concurrently +* dirtying pages, and we might have +* synced a lot of newly appeared dirty +* pages, but have not synced all of the +* old dirty pages. +*/ + done =1 ; +break ; + } + } + } +pagevec_release (&pvec); +cond_resched (); + } +return ret; +} + +static int ext4_da_writepages (struct address_space *mapping,struct writeback_control *wbc) {
@@ -2839,7 +2946,6 @@ static int ext4_da_writepages(struct address_space *mapping,handle_t *handle =NULL ;struct mpage_da_data mpd;struct inode *inode = mapping->host; -int no_nrwrite_index_update;int pages_written =0 ;long pages_skipped;unsigned int max_pages;
@@ -2919,12 +3025,6 @@ static int ext4_da_writepages(struct address_space *mapping, mpd.wbc = wbc; mpd.inode = mapping->host; -/* -* we don't want write_cache_pages to update -* nr_to_write and writeback_index -*/ - no_nrwrite_index_update = wbc->no_nrwrite_index_update; - wbc->no_nrwrite_index_update =1 ; pages_skipped = wbc->pages_skipped; retry:
@@ -2966,8 +3066,7 @@ retry: mpd.io_done =0 ; mpd.pages_written =0 ; mpd.retval =0 ; - ret =write_cache_pages (mapping, wbc, __mpage_da_writepage, - &mpd); + ret =write_cache_pages_da (mapping, wbc, &mpd);/* * If we have a contiguous extent of pages and we * haven't done the I/O yet, map the blocks and submit
@@ -3033,8 +3132,6 @@ retry: mapping->writeback_index = index; out_writepages: -if (!no_nrwrite_index_update) - wbc->no_nrwrite_index_update =0 ; wbc->nr_to_write -= nr_to_writebump; wbc->range_start = range_start;trace_ext4_da_writepages_result (inode, wbc, ret, pages_written);
Signature · 1 line
1.6.6.1.1.g974db.dirty
Theodore Ts'o
maintainerPATCH 18/28 ext4: Prevent creation of files larger than RLIMIT_FSIZE using fallocate
In reply to Theodore Ts'oFrom: Nikanth Karthikesan <[email protected]>
commit 6d19c42b7cf81c39632b6d4dbc514e8449bcd346 upstream (as of v2.6.34-git13)
Currently using posix_fallocate one can bypass an RLIMIT_FSIZE limit and create a file larger than the limit. Add a check for that.
--- fs/ext4/extents.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
fs/ext4/extents.c +5 -0
@@ -3708,6 +3708,11 @@ long ext4_fallocate(struct inode *inode, int mode, loff_t offset, loff_t len)*/ credits =ext4_chunk_trans_blocks (inode, max_blocks);mutex_lock (&inode->i_mutex); + ret =inode_newsize_ok (inode, (len + offset)); +if (ret) { +mutex_unlock (&inode->i_mutex); +return ret; + } retry:while (ret >=0 && ret < max_blocks) { block = block + ret;
Signature · 1 line
1.6.6.1.1.g974db.dirty