]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
erofs: fix .fadvise() for page cache sharing
authorGao Xiang <hsiangkao@linux.alibaba.com>
Tue, 24 Mar 2026 15:54:07 +0000 (23:54 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Wed, 25 Mar 2026 02:40:02 +0000 (10:40 +0800)
Currently, .fadvise() doesn't work well if page cache sharing is on
since shared inodes belong to a pseudo fs generated with init_pseudo(),
and sb->s_bdi is the default one &noop_backing_dev_info.

Then, generic_fadvise() will just behave as a no-op if sb->s_bdi is
&noop_backing_dev_info, but as the bdev fs (the bdev fs changes
inode_to_bdi() instead), it's actually NOT a pure memfs.

Let's generate a real bdi for erofs_ishare_mnt instead.

Fixes: d86d7817c042 ("erofs: implement .fadvise for page cache share")
Reviewed-by: Hongbo Li <lihongbo22@huawei.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
fs/erofs/ishare.c

index 829d50d5c717dfcdfae4f0cb3897996e79667c87..ec433bacc592522a169f42b22594eb8a43ac6c46 100644 (file)
@@ -200,8 +200,19 @@ struct inode *erofs_real_inode(struct inode *inode, bool *need_iput)
 
 int __init erofs_init_ishare(void)
 {
-       erofs_ishare_mnt = kern_mount(&erofs_anon_fs_type);
-       return PTR_ERR_OR_ZERO(erofs_ishare_mnt);
+       struct vfsmount *mnt;
+       int ret;
+
+       mnt = kern_mount(&erofs_anon_fs_type);
+       if (IS_ERR(mnt))
+               return PTR_ERR(mnt);
+       /* generic_fadvise() doesn't work if s_bdi == &noop_backing_dev_info */
+       ret = super_setup_bdi(mnt->mnt_sb);
+       if (ret)
+               kern_unmount(mnt);
+       else
+               erofs_ishare_mnt = mnt;
+       return ret;
 }
 
 void erofs_exit_ishare(void)