diff mbox series

[1/1] fuse: Keep attributes consistent with Passthrough

Message ID 20240703010215.2013266-2-drosen@google.com (mailing list archive)
State New
Headers show
Series Fuse Passthrough cache issues | expand

Commit Message

Daniel Rosenberg July 3, 2024, 1:02 a.m. UTC
If writeback cache is enabled, and we attempt to use fuse passthrough,
fuse will invalidate attributes on write, but will then ignore when the
server attempts to update those attributes. Since the kernel is the
arbiter of truth with writeback cache, passthrough holds the
responsibility to keep these values updated.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
---
 fs/fuse/passthrough.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/fs/fuse/passthrough.c b/fs/fuse/passthrough.c
index 9666d13884ce..6f63a1a38d7c 100644
--- a/fs/fuse/passthrough.c
+++ b/fs/fuse/passthrough.c
@@ -21,8 +21,19 @@  static void fuse_file_accessed(struct file *file)
 static void fuse_file_modified(struct file *file)
 {
 	struct inode *inode = file_inode(file);
-
-	fuse_invalidate_attr_mask(inode, FUSE_STATX_MODSIZE);
+	struct fuse_conn *fc = get_fuse_conn(inode);
+	struct fuse_file *ff = file->private_data;
+	struct file *backing_file = fuse_file_passthrough(ff);
+	struct inode *backing_inode = file_inode(backing_file);
+
+	if (!fc->writeback_cache) {
+		fuse_invalidate_attr_mask(inode, FUSE_STATX_MODSIZE);
+	} else {
+		inode_set_mtime_to_ts(inode, inode_get_mtime(backing_inode));
+		inode_set_ctime_to_ts(inode, inode_get_ctime(backing_inode));
+		inode->i_blocks = backing_inode->i_blocks;
+		i_size_write(inode, i_size_read(backing_inode));
+	}
 }
 
 ssize_t fuse_passthrough_read_iter(struct kiocb *iocb, struct iov_iter *iter)