Skip to content

Commit 80e4f25

Browse files
Hao XuMiklos Szeredi
authored andcommitted
fuse: invalidate page cache pages before direct write
In FOPEN_DIRECT_IO, page cache may still be there for a file since private mmap is allowed. Direct write should respect that and invalidate the corresponding pages so that page cache readers don't get stale data. Signed-off-by: Hao Xu <howeyxu@tencent.com> Tested-by: Jiachen Zhang <zhangjiachen.jaycee@bytedance.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent b8bd342 commit 80e4f25

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

fs/fuse/file.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,8 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
14281428
int write = flags & FUSE_DIO_WRITE;
14291429
int cuse = flags & FUSE_DIO_CUSE;
14301430
struct file *file = io->iocb->ki_filp;
1431-
struct inode *inode = file->f_mapping->host;
1431+
struct address_space *mapping = file->f_mapping;
1432+
struct inode *inode = mapping->host;
14321433
struct fuse_file *ff = file->private_data;
14331434
struct fuse_conn *fc = ff->fm->fc;
14341435
size_t nmax = write ? fc->max_write : fc->max_read;
@@ -1440,6 +1441,7 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
14401441
int err = 0;
14411442
struct fuse_io_args *ia;
14421443
unsigned int max_pages;
1444+
bool fopen_direct_io = ff->open_flags & FOPEN_DIRECT_IO;
14431445

14441446
max_pages = iov_iter_npages(iter, fc->max_pages);
14451447
ia = fuse_io_alloc(io, max_pages);
@@ -1454,6 +1456,14 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
14541456
inode_unlock(inode);
14551457
}
14561458

1459+
if (fopen_direct_io && write) {
1460+
res = invalidate_inode_pages2_range(mapping, idx_from, idx_to);
1461+
if (res) {
1462+
fuse_io_free(ia);
1463+
return res;
1464+
}
1465+
}
1466+
14571467
io->should_dirty = !write && user_backed_iter(iter);
14581468
while (count) {
14591469
ssize_t nres;

0 commit comments

Comments
 (0)