Commit d6d478a1 authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

f2fs: continue to do direct IO if we only preallocate partial blocks

While doing direct IO, if we run out-of-space when we preallocate blocks,
we should not return ENOSPC error directly, instead, we should continue
to do following direct IO, which will keep directIO of f2fs acting like
other filesystems.
Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 6279398d
...@@ -832,10 +832,12 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from) ...@@ -832,10 +832,12 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
{ {
struct inode *inode = file_inode(iocb->ki_filp); struct inode *inode = file_inode(iocb->ki_filp);
struct f2fs_map_blocks map; struct f2fs_map_blocks map;
int flag;
int err = 0; int err = 0;
bool direct_io = iocb->ki_flags & IOCB_DIRECT;
/* convert inline data for Direct I/O*/ /* convert inline data for Direct I/O*/
if (iocb->ki_flags & IOCB_DIRECT) { if (direct_io) {
err = f2fs_convert_inline_inode(inode); err = f2fs_convert_inline_inode(inode);
if (err) if (err)
return err; return err;
...@@ -854,27 +856,31 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from) ...@@ -854,27 +856,31 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
map.m_next_pgofs = NULL; map.m_next_pgofs = NULL;
map.m_seg_type = NO_CHECK_TYPE; map.m_seg_type = NO_CHECK_TYPE;
if (iocb->ki_flags & IOCB_DIRECT) { if (direct_io) {
map.m_seg_type = rw_hint_to_seg_type(iocb->ki_hint); map.m_seg_type = rw_hint_to_seg_type(iocb->ki_hint);
return f2fs_map_blocks(inode, &map, 1, flag = __force_buffered_io(inode, WRITE) ?
__force_buffered_io(inode, WRITE) ?
F2FS_GET_BLOCK_PRE_AIO : F2FS_GET_BLOCK_PRE_AIO :
F2FS_GET_BLOCK_PRE_DIO); F2FS_GET_BLOCK_PRE_DIO;
goto map_blocks;
} }
if (iocb->ki_pos + iov_iter_count(from) > MAX_INLINE_DATA(inode)) { if (iocb->ki_pos + iov_iter_count(from) > MAX_INLINE_DATA(inode)) {
err = f2fs_convert_inline_inode(inode); err = f2fs_convert_inline_inode(inode);
if (err) if (err)
return err; return err;
} }
if (!f2fs_has_inline_data(inode)) { if (f2fs_has_inline_data(inode))
err = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO); return err;
flag = F2FS_GET_BLOCK_PRE_AIO;
map_blocks:
err = f2fs_map_blocks(inode, &map, 1, flag);
if (map.m_len > 0 && err == -ENOSPC) { if (map.m_len > 0 && err == -ENOSPC) {
if (!direct_io)
set_inode_flag(inode, FI_NO_PREALLOC); set_inode_flag(inode, FI_NO_PREALLOC);
err = 0; err = 0;
} }
return err; return err;
}
return err;
} }
static inline void __do_map_lock(struct f2fs_sb_info *sbi, int flag, bool lock) static inline void __do_map_lock(struct f2fs_sb_info *sbi, int flag, bool lock)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment