ovl: update inode size after extending passthrough write
Subsystems (3)
Amir Goldstein
maintainerPATCH 1/1 ovl: update inode size after extending passthrough write
yangyun reported that libfuse test test_copy_file_range() copies zero bytes from a newly written file when fuse passthrough is enabled.
The reason is that extending passthrough write is not updating the fuse inode size and when vfs_copy_file_range() observes a zero size inode, it returns without calling the filesystem copy_file_range() method.
Extend the fuse inode size to the size of the backing inode after every passthrough write if the backing inode size is larger.
This does not yet provide cache coherency of fuse inode attributes and backing inode attributes, but it should prevent situations where fuse inode size is too small, causing read/copy to be wrongly shortened.
--- fs/fuse/passthrough.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
fs/fuse/passthrough.c +11 -2
@@ -20,9 +20,18 @@ static void fuse_file_accessed(struct file *file)static void fuse_file_modified (struct file *file) { +struct fuse_file *ff = file->private_data; +struct file *backing_file =fuse_file_passthrough (ff);struct inode *inode =file_inode (file); - -fuse_invalidate_attr_mask (inode,FUSE_STATX_MODSIZE ); +loff_t size =i_size_read (file_inode (backing_file)); + +/* +* Most of the time we will be holding inode_lock(), but even if we are +* called from async io completion without inode_lock(), the last write +* will update fuse inode size to the size of the backing inode, even if +* the last write was not the extending write. +*/ +fuse_write_update_attr (inode, size, size); }ssize_t fuse_passthrough_read_iter (struct kiocb *iocb,struct iov_iter *iter)
Signature · 1 line
2.34.1
Amir Goldstein
maintainerWrong subject line - resending...
Quoted 51 lines · Amir Goldstein
yangyun reported that libfuse test
test_copy_file_range()copies zero bytes from a newly written file when fuse passthrough is enabled.The reason is that extending passthrough write is not updating the fuse inode size and when
vfs_copy_file_range()observes a zero size inode, it returns without calling the filesystemcopy_file_range()method.Extend the fuse inode size to the size of the backing inode after every passthrough write if the backing inode size is larger.
This does not yet provide cache coherency of fuse inode attributes and backing inode attributes, but it should prevent situations where fuse inode size is too small, causing read/copy to be wrongly shortened.
Reported-by yangyun <[email protected]>Fixes 57e1176e6086 ("fuse: implement read/write passthrough")Signed-off-by Amir Goldstein <[email protected]>--- fs/fuse/passthrough.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)fs/fuse/passthrough.c +11
-3@@ -20,9 +20,18 @@ static void fuse_file_accessed(struct file *file)static void fuse_file_modified (struct file *file) { +struct fuse_file *ff = file->private_data; +struct file *backing_file =fuse_file_passthrough (ff);struct inode *inode =file_inode (file); - -fuse_invalidate_attr_mask (inode,FUSE_STATX_MODSIZE ); +loff_t size =i_size_read (file_inode (backing_file)); + +/* +* Most of the time we will be holding inode_lock(), but even if we are +* called from async io completion without inode_lock(), the last write +* will update fuse inode size to the size of the backing inode, even if +* the last write was not the extending write. +*/ +fuse_write_update_attr (inode, size, size); }ssize_t fuse_passthrough_read_iter (struct kiocb *iocb,struct iov_iter *iter) --2.34.1