FROMLIST: fuse: Introduce passthrough for mmap

Enabling FUSE passthrough for mmap-ed operations not only affects
performance, but has also been shown as mandatory for the correct
functioning of FUSE passthrough.
yanwu noticed [1] that a FUSE file with passthrough enabled may suffer
data inconsistencies if the same file is also accessed with mmap. What
happens is that read/write operations are directly applied to the lower
file system (and its cache), while mmap-ed operations are affecting the
FUSE cache.

Extend the FUSE passthrough implementation to also handle memory-mapped
FUSE file, to both fix the cache inconsistencies and extend the
passthrough performance benefits to mmap-ed operations.

[1] https://lore.kernel.org/lkml/20210119110654.11817-1-wu-yan@tcl.com/

Bug: 168023149
Link: https://lore.kernel.org/lkml/20210125153057.3623715-9-balsini@android.com/
Signed-off-by: Alessio Balsini <balsini@android.com>
Change-Id: Ifad4698b0380f6e004c487940ac6907b9a9f2964
Signed-off-by: Alessio Balsini <balsini@google.com>
This commit is contained in:
Alessio Balsini 2021-01-25 17:05:31 +00:00 committed by Michael Bestas
parent 2d336e55a8
commit 5d232ddb88
No known key found for this signature in database
GPG Key ID: CC95044519BE6669
3 changed files with 45 additions and 0 deletions

View File

@ -2330,6 +2330,9 @@ static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma)
{
struct fuse_file *ff = file->private_data;
if (ff->passthrough.filp)
return fuse_passthrough_mmap(file, vma);
if (ff->open_flags & FOPEN_DIRECT_IO) {
/* Can't provide the coherency needed for MAP_SHARED */
if (vma->vm_flags & VM_MAYSHARE)

View File

@ -1142,5 +1142,6 @@ int fuse_passthrough_setup(struct fuse_conn *fc, struct fuse_file *ff,
void fuse_passthrough_release(struct fuse_passthrough *passthrough);
ssize_t fuse_passthrough_read_iter(struct kiocb *iocb, struct iov_iter *to);
ssize_t fuse_passthrough_write_iter(struct kiocb *iocb, struct iov_iter *from);
ssize_t fuse_passthrough_mmap(struct file *file, struct vm_area_struct *vma);
#endif /* _FS_FUSE_I_H */

View File

@ -147,6 +147,47 @@ out:
return ret;
}
ssize_t fuse_passthrough_mmap(struct file *file, struct vm_area_struct *vma)
{
int ret;
const struct cred *old_cred;
struct fuse_file *ff = file->private_data;
struct inode *fuse_inode = file_inode(file);
struct file *passthrough_filp = ff->passthrough.filp;
struct inode *passthrough_inode = file_inode(passthrough_filp);
if (!passthrough_filp->f_op->mmap)
return -ENODEV;
if (WARN_ON(file != vma->vm_file))
return -EIO;
vma->vm_file = get_file(passthrough_filp);
old_cred = override_creds(ff->passthrough.cred);
ret = call_mmap(vma->vm_file, vma);
revert_creds(old_cred);
if (ret)
fput(passthrough_filp);
else
fput(file);
if (file->f_flags & O_NOATIME)
return ret;
if ((!timespec64_equal(&fuse_inode->i_mtime,
&passthrough_inode->i_mtime) ||
!timespec64_equal(&fuse_inode->i_ctime,
&passthrough_inode->i_ctime))) {
fuse_inode->i_mtime = passthrough_inode->i_mtime;
fuse_inode->i_ctime = passthrough_inode->i_ctime;
}
touch_atime(&file->f_path);
return ret;
}
int fuse_passthrough_open(struct fuse_dev *fud,
struct fuse_passthrough_out *pto)
{