f2fs: Prevent swap file in LFS mode
authorShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Mon, 10 May 2021 11:24:44 +0000 (20:24 +0900)
committerJaegeuk Kim <jaegeuk@kernel.org>
Fri, 14 May 2021 18:22:08 +0000 (11:22 -0700)
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: 4969c06a0d83 ("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>
fs/f2fs/data.c

index d352f2b..d4795ed 100644 (file)
@@ -4076,6 +4076,12 @@ static int f2fs_swap_activate(struct swap_info_struct *sis, struct file *file,
        if (f2fs_readonly(F2FS_I_SB(inode)->sb))
                return -EROFS;
 
+       if (f2fs_lfs_mode(F2FS_I_SB(inode))) {
+               f2fs_err(F2FS_I_SB(inode),
+                       "Swapfile not supported in LFS mode");
+               return -EINVAL;
+       }
+
        ret = f2fs_convert_inline_inode(inode);
        if (ret)
                return ret;