Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit babfbc08 authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim
Browse files

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 f9289908
Loading
Loading
Loading
Loading
+18 −13
Original line number Diff line number Diff line
@@ -828,13 +828,14 @@ static inline bool __force_buffered_io(struct inode *inode, int rw)
}

int f2fs_preallocate_blocks(struct inode *inode, loff_t pos,
					size_t count, bool dio)
				size_t count, bool direct_io)
{
	struct f2fs_map_blocks map;
	int flag;
	int err = 0;

	/* convert inline data for Direct I/O*/
	if (dio) {
	if (direct_io) {
		err = f2fs_convert_inline_inode(inode);
		if (err)
			return err;
@@ -853,29 +854,33 @@ int f2fs_preallocate_blocks(struct inode *inode, loff_t pos,
	map.m_next_pgofs = NULL;
	map.m_seg_type = NO_CHECK_TYPE;

	if (dio) {
	if (direct_io) {
		/* map.m_seg_type = rw_hint_to_seg_type(iocb->ki_hint); */
		map.m_seg_type = rw_hint_to_seg_type(WRITE_LIFE_NOT_SET);
		return f2fs_map_blocks(inode, &map, 1,
			__force_buffered_io(inode, WRITE) ?
		flag = __force_buffered_io(inode, WRITE) ?
					F2FS_GET_BLOCK_PRE_AIO :
				F2FS_GET_BLOCK_PRE_DIO);
					F2FS_GET_BLOCK_PRE_DIO;
		goto map_blocks;
	}
	if (pos + count > MAX_INLINE_DATA(inode)) {
		err = f2fs_convert_inline_inode(inode);
		if (err)
			return err;
	}
	if (!f2fs_has_inline_data(inode)) {
		err = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO);
	if (f2fs_has_inline_data(inode))
		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 (!direct_io)
			set_inode_flag(inode, FI_NO_PREALLOC);
		err = 0;
	}
	return err;
}
	return err;
}

static inline void __do_map_lock(struct f2fs_sb_info *sbi, int flag, bool lock)
{