Skip to content

Commit e582a2f

Browse files
kawasakigregkh
authored andcommitted
f2fs: Prevent swap file in LFS mode
commit d927ccf upstream. The kernel writes to swap files on f2fs directly without the assistance of the filesystem. This direct write by kernel can be non-sequential even when the f2fs is in LFS mode. Such non-sequential write conflicts with the LFS semantics. Especially when f2fs is set up on zoned block devices, the non-sequential write causes unaligned write command errors. To avoid the non-sequential writes to swap files, prevent swap file activation when the filesystem is in LFS mode. Fixes: 4969c06 ("f2fs: support swap file w/ DIO") Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com> Cc: stable@vger.kernel.org # v5.10+ Reviewed-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 36ae903 commit e582a2f

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎fs/f2fs/data.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4112,6 +4112,12 @@ static int f2fs_swap_activate(struct swap_info_struct *sis, struct file *file,
41124112
if (f2fs_readonly(F2FS_I_SB(inode)->sb))
41134113
return -EROFS;
41144114

4115+
if (f2fs_lfs_mode(F2FS_I_SB(inode))) {
4116+
f2fs_err(F2FS_I_SB(inode),
4117+
"Swapfile not supported in LFS mode");
4118+
return -EINVAL;
4119+
}
4120+
41154121
ret = f2fs_convert_inline_inode(inode);
41164122
if (ret)
41174123
return ret;

0 commit comments

Comments
 (0)