Skip to contentSkip to conversation

erofs: fix .fadvise() for page cache sharing

PATCH In review Gao Xiang 2 participants 2 messages Mar 24 – Mar 25 EROFS file system

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH v2 1/1 erofs: fix .fadvise() for page cache sharing

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")
Cc Hongbo Li <[email protected]>

---
v2:
- handle super_setup_bdi() failure properly.

 fs/erofs/ishare.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
fs/erofs/ishare.c +13 -2
index 829d50d5c717..ec433bacc592 100644
@@ -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)
Signature · 1 line
2.43.5
Reviewed-by on v2 1/1
#1 lore raw
Quoted 34 lines · Gao Xiang

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")
Cc Hongbo Li <[email protected]>

---
v2:
- handle super_setup_bdi() failure properly.

  fs/erofs/ishare.c | 15 +++++++++++++--
  1 file changed, 13 insertions(+), 2 deletions(-)
fs/erofs/ishare.c +4 -2
index 829d50d5c717..ec433bacc592 100644
@@ -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);

fs/erofs/ishare.c struct inode *erofs_real_inode(struct inode *inode, bool *need_iput) · line 216

Quoted 10 lines
fs/erofs/ishare.c +9 -0
+	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;
  }

ok, looks good.

Thanks,
Hongbo

Quoted 2 lines
fs/erofs/ishare.c +0 -0
  void erofs_exit_ishare(void)