@@ -1687,6 +1687,7 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
1687
1687
1688
1688
map .m_seg_type = CURSEG_COLD_DATA_PINNED ;
1689
1689
err = f2fs_map_blocks (inode , & map , 1 , F2FS_GET_BLOCK_PRE_DIO );
1690
+ file_dont_truncate (inode );
1690
1691
1691
1692
up_write (& sbi -> pin_sem );
1692
1693
@@ -4257,6 +4258,13 @@ static int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *iter)
4257
4258
/* If it will be an out-of-place direct write, don't bother. */
4258
4259
if (dio && f2fs_lfs_mode (sbi ))
4259
4260
return 0 ;
4261
+ /*
4262
+ * Don't preallocate holes aligned to DIO_SKIP_HOLES which turns into
4263
+ * buffered IO, if DIO meets any holes.
4264
+ */
4265
+ if (dio && i_size_read (inode ) &&
4266
+ (F2FS_BYTES_TO_BLK (pos ) < F2FS_BLK_ALIGN (i_size_read (inode ))))
4267
+ return 0 ;
4260
4268
4261
4269
/* No-wait I/O can't allocate blocks. */
4262
4270
if (iocb -> ki_flags & IOCB_NOWAIT )
@@ -4292,8 +4300,8 @@ static int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *iter)
4292
4300
}
4293
4301
4294
4302
ret = f2fs_map_blocks (inode , & map , 1 , flag );
4295
- /* -ENOSPC is only a fatal error if no blocks could be allocated. */
4296
- if (ret < 0 && !(ret == - ENOSPC && map .m_len > 0 ))
4303
+ /* -ENOSPC|-EDQUOT are fine to report the number of allocated blocks . */
4304
+ if (ret < 0 && !(( ret == - ENOSPC || ret == - EDQUOT ) && map .m_len > 0 ))
4297
4305
return ret ;
4298
4306
if (ret == 0 )
4299
4307
set_inode_flag (inode , FI_PREALLOCATED_ALL );
@@ -4359,20 +4367,21 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
4359
4367
/* Possibly preallocate the blocks for the write. */
4360
4368
target_size = iocb -> ki_pos + iov_iter_count (from );
4361
4369
preallocated = f2fs_preallocate_blocks (iocb , from );
4362
- if (preallocated < 0 ) {
4370
+ if (preallocated < 0 )
4363
4371
ret = preallocated ;
4364
- goto out_unlock ;
4365
- }
4366
-
4367
- ret = __generic_file_write_iter (iocb , from );
4372
+ else
4373
+ ret = __generic_file_write_iter (iocb , from );
4368
4374
4369
4375
/* Don't leave any preallocated blocks around past i_size. */
4370
- if (preallocated > 0 && i_size_read (inode ) < target_size ) {
4376
+ if (preallocated && i_size_read (inode ) < target_size ) {
4371
4377
down_write (& F2FS_I (inode )-> i_gc_rwsem [WRITE ]);
4372
4378
filemap_invalidate_lock (inode -> i_mapping );
4373
- f2fs_truncate (inode );
4379
+ if (!f2fs_truncate (inode ))
4380
+ file_dont_truncate (inode );
4374
4381
filemap_invalidate_unlock (inode -> i_mapping );
4375
4382
up_write (& F2FS_I (inode )-> i_gc_rwsem [WRITE ]);
4383
+ } else {
4384
+ file_dont_truncate (inode );
4376
4385
}
4377
4386
4378
4387
clear_inode_flag (inode , FI_PREALLOCATED_ALL );
0 commit comments