emm: mm/swap: misc: print a warning for swapping on block file over fs

Upstream: pending

Looking at setup_swap_extents, swap_activate never get called if the
overlying file for swap is a block file.

And swap_activate is the only place that sets SWP_FS_OPS, so a block
file over filesystem will make SWP_FS_OPS never take effect and swap_rw
get ignored.

Although there is currently no such mis-combination in kernel, make this
a warn so things are clear.

Signed-off-by: Kairui Song <kasong@tencent.com>
This commit is contained in:
Kairui Song 2023-04-21 15:32:49 +08:00
parent cb0c04e9a0
commit c24b2ddf1f
1 changed files with 5 additions and 0 deletions

View File

@ -2802,6 +2802,11 @@ static int claim_swapfile(struct swap_info_struct *p, struct inode *inode)
int error;
if (S_ISBLK(inode->i_mode)) {
#ifdef CONFIG_ENHANCED_MM
WARN(p->swap_file->f_mapping->a_ops->swap_activate,
"Swapping on block file over filesystem %s, file system operations may get bypassed unexpectedly and lead to data loss.\n",
p->swap_file->f_inode->i_sb->s_id);
#endif
p->bdev = blkdev_get_by_dev(inode->i_rdev,
BLK_OPEN_READ | BLK_OPEN_WRITE, p, NULL);
if (IS_ERR(p->bdev)) {