@@ -4338,44 +4338,48 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
4338
4338
}
4339
4339
4340
4340
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 )) ||
4345
4347
f2fs_has_inline_data (inode ) ||
4346
4348
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 ;
4361
4350
goto out_unlock ;
4362
4351
}
4352
+ }
4363
4353
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
+ }
4365
4366
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 );
4375
4368
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 ]);
4378
4376
}
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
+
4379
4383
out_unlock :
4380
4384
inode_unlock (inode );
4381
4385
out :
0 commit comments