Commit a38e9381 authored by Zhang Yi's avatar Zhang Yi
Browse files

ext4: implement buffered read iomap path

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I9DN5Z


CVE: NA

--------------------------------

Add ext4_iomap_buffered_io_begin() for the iomap read path, it call
ext4_map_blocks() to query map status and call ext4_set_iomap() to
convert ext4 map to iomap.

Signed-off-by: default avatarZhang Yi <yi.zhang@huawei.com>
parent b5f3b274
Loading
Loading
Loading
Loading
+34 −2
Original line number Diff line number Diff line
@@ -3554,14 +3554,46 @@ const struct iomap_ops ext4_iomap_report_ops = {
	.iomap_begin = ext4_iomap_begin_report,
};

static int ext4_iomap_read_folio(struct file *file, struct folio *folio)
static int ext4_iomap_buffered_io_begin(struct inode *inode, loff_t offset,
				loff_t length, unsigned int iomap_flags,
				struct iomap *iomap, struct iomap *srcmap)
{
	int ret;
	struct ext4_map_blocks map;
	u8 blkbits = inode->i_blkbits;

	if (unlikely(ext4_forced_shutdown(inode->i_sb)))
		return -EIO;
	if ((offset >> blkbits) > EXT4_MAX_LOGICAL_BLOCK)
		return -EINVAL;
	if (WARN_ON_ONCE(ext4_has_inline_data(inode)))
		return -ERANGE;

	/* Calculate the first and last logical blocks respectively. */
	map.m_lblk = offset >> blkbits;
	map.m_len = min_t(loff_t, (offset + length - 1) >> blkbits,
			  EXT4_MAX_LOGICAL_BLOCK) - map.m_lblk + 1;

	ret = ext4_map_blocks(NULL, inode, &map, 0);
	if (ret < 0)
		return ret;

	ext4_set_iomap(inode, iomap, &map, offset, length, iomap_flags);
	return 0;
}

static void ext4_iomap_readahead(struct readahead_control *rac)
const struct iomap_ops ext4_iomap_buffered_read_ops = {
	.iomap_begin = ext4_iomap_buffered_io_begin,
};

static int ext4_iomap_read_folio(struct file *file, struct folio *folio)
{
	return iomap_read_folio(folio, &ext4_iomap_buffered_read_ops);
}

static void ext4_iomap_readahead(struct readahead_control *rac)
{
	iomap_readahead(rac, &ext4_iomap_buffered_read_ops);
}

static int ext4_iomap_writepages(struct address_space *mapping,