Commit 6905af98 authored by Zhihao Cheng's avatar Zhihao Cheng
Browse files

ext4: Skip moving extents if page writeback failed

hulk inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IA5XLM


CVE: NA

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

Ext4 should check the return value of ext4_disable_buffered_iomap_aops()
before moving extents, otherwise the EXT4_STATE_BUFFERED_IOMAP state is
not cleared from the inode, which could trigger the WARNON in function
_ext4_get_block().

Fixes: 2a158d54 ("ext4: fall back to buffer_head path for defrag")
Signed-off-by: default avatarZhihao Cheng <chengzhihao@huaweicloud.com>
parent 14e87504
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -640,10 +640,16 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk,
	inode_dio_wait(donor_inode);

	/* Fallback to buffer_head aops for inodes with buffered iomap aops */
	if (ext4_test_inode_state(orig_inode, EXT4_STATE_BUFFERED_IOMAP))
		ext4_disable_buffered_iomap_aops(orig_inode);
	if (ext4_test_inode_state(donor_inode, EXT4_STATE_BUFFERED_IOMAP))
		ext4_disable_buffered_iomap_aops(donor_inode);
	if (ext4_test_inode_state(orig_inode, EXT4_STATE_BUFFERED_IOMAP)) {
		ret = ext4_disable_buffered_iomap_aops(orig_inode);
		if (ret)
			goto out_unlock;
	}
	if (ext4_test_inode_state(donor_inode, EXT4_STATE_BUFFERED_IOMAP)) {
		ret = ext4_disable_buffered_iomap_aops(donor_inode);
		if (ret)
			goto out_unlock;
	}

	/* Protect extent tree against block allocations via delalloc */
	ext4_double_down_write_data_sem(orig_inode, donor_inode);
@@ -728,6 +734,7 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk,

	ext4_free_ext_path(path);
	ext4_double_up_write_data_sem(orig_inode, donor_inode);
out_unlock:
	unlock_two_nondirectories(orig_inode, donor_inode);

	return ret;