@@ -4338,44 +4338,48 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
43384338 }
43394339
43404340 ret = generic_write_checks (iocb , from );
4341- if (ret > 0 ) {
4342- if (iocb -> ki_flags & IOCB_NOWAIT ) {
4343- if (!f2fs_overwrite_io (inode , iocb -> ki_pos ,
4344- iov_iter_count (from )) ||
4341+ if (ret <= 0 )
4342+ goto out_unlock ;
4343+
4344+ if (iocb -> ki_flags & IOCB_NOWAIT ) {
4345+ if (!f2fs_overwrite_io (inode , iocb -> ki_pos ,
4346+ iov_iter_count (from )) ||
43454347 f2fs_has_inline_data (inode ) ||
43464348 f2fs_force_buffered_io (inode , iocb , from )) {
4347- ret = - EAGAIN ;
4348- goto out_unlock ;
4349- }
4350- }
4351- if (iocb -> ki_flags & IOCB_DIRECT ) {
4352- ret = f2fs_convert_inline_inode (inode );
4353- if (ret )
4354- goto out_unlock ;
4355- }
4356- /* Possibly preallocate the blocks for the write. */
4357- target_size = iocb -> ki_pos + iov_iter_count (from );
4358- preallocated = f2fs_preallocate_blocks (iocb , from );
4359- if (preallocated < 0 ) {
4360- ret = preallocated ;
4349+ ret = - EAGAIN ;
43614350 goto out_unlock ;
43624351 }
4352+ }
43634353
4364- ret = __generic_file_write_iter (iocb , from );
4354+ if (iocb -> ki_flags & IOCB_DIRECT ) {
4355+ ret = f2fs_convert_inline_inode (inode );
4356+ if (ret )
4357+ goto out_unlock ;
4358+ }
4359+ /* Possibly preallocate the blocks for the write. */
4360+ target_size = iocb -> ki_pos + iov_iter_count (from );
4361+ preallocated = f2fs_preallocate_blocks (iocb , from );
4362+ if (preallocated < 0 ) {
4363+ ret = preallocated ;
4364+ goto out_unlock ;
4365+ }
43654366
4366- /* Don't leave any preallocated blocks around past i_size. */
4367- if (preallocated > 0 && i_size_read (inode ) < target_size ) {
4368- down_write (& F2FS_I (inode )-> i_gc_rwsem [WRITE ]);
4369- filemap_invalidate_lock (inode -> i_mapping );
4370- f2fs_truncate (inode );
4371- filemap_invalidate_unlock (inode -> i_mapping );
4372- up_write (& F2FS_I (inode )-> i_gc_rwsem [WRITE ]);
4373- }
4374- clear_inode_flag (inode , FI_PREALLOCATED_ALL );
4367+ ret = __generic_file_write_iter (iocb , from );
43754368
4376- if (ret > 0 )
4377- f2fs_update_iostat (F2FS_I_SB (inode ), APP_WRITE_IO , ret );
4369+ /* Don't leave any preallocated blocks around past i_size. */
4370+ if (preallocated > 0 && i_size_read (inode ) < target_size ) {
4371+ down_write (& F2FS_I (inode )-> i_gc_rwsem [WRITE ]);
4372+ filemap_invalidate_lock (inode -> i_mapping );
4373+ f2fs_truncate (inode );
4374+ filemap_invalidate_unlock (inode -> i_mapping );
4375+ up_write (& F2FS_I (inode )-> i_gc_rwsem [WRITE ]);
43784376 }
4377+
4378+ clear_inode_flag (inode , FI_PREALLOCATED_ALL );
4379+
4380+ if (ret > 0 )
4381+ f2fs_update_iostat (F2FS_I_SB (inode ), APP_WRITE_IO , ret );
4382+
43794383out_unlock :
43804384 inode_unlock (inode );
43814385out :
0 commit comments