linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: Bernd Schubert <bernd.schubert@fastmail.fm>,
	linux-fsdevel@vger.kernel.org
Subject: [PATCH v15 9/9] fuse: auto-invalidate inode attributes in passthrough mode
Date: Tue,  6 Feb 2024 16:24:53 +0200	[thread overview]
Message-ID: <20240206142453.1906268-10-amir73il@gmail.com> (raw)
In-Reply-To: <20240206142453.1906268-1-amir73il@gmail.com>

After passthrough read/write, we invalidate a/c/mtime/size attributes
if the backing inode attributes differ from FUSE inode attributes.

Do the same in fuse_getattr() and after detach of backing inode, so that
passthrough mmap read/write changes to a/c/mtime/size attribute of the
backing inode will be propagated to the FUSE inode.

The rules of invalidating a/c/mtime/size attributes with writeback cache
are more complicated, so for now, writeback cache and passthrough cannot
be enabled on the same filesystem.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 fs/fuse/dir.c         |  4 ++++
 fs/fuse/fuse_i.h      |  2 ++
 fs/fuse/inode.c       |  4 ++++
 fs/fuse/iomode.c      |  5 +++-
 fs/fuse/passthrough.c | 55 ++++++++++++++++++++++++++++++++++++-------
 5 files changed, 61 insertions(+), 9 deletions(-)

diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 95330c2ca3d8..7f9d002b8f23 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -2118,6 +2118,10 @@ static int fuse_getattr(struct mnt_idmap *idmap,
 		return -EACCES;
 	}
 
+	/* Maybe update/invalidate attributes from backing inode */
+	if (fuse_inode_backing(get_fuse_inode(inode)))
+		fuse_backing_update_attr_mask(inode, request_mask);
+
 	return fuse_update_get_attr(inode, NULL, stat, request_mask, flags);
 }
 
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 98f878a52af1..4b011d31012f 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1456,6 +1456,8 @@ void fuse_backing_files_init(struct fuse_conn *fc);
 void fuse_backing_files_free(struct fuse_conn *fc);
 int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map);
 int fuse_backing_close(struct fuse_conn *fc, int backing_id);
+void fuse_backing_update_attr(struct inode *inode, struct fuse_backing *fb);
+void fuse_backing_update_attr_mask(struct inode *inode, u32 request_mask);
 
 struct fuse_backing *fuse_passthrough_open(struct file *file,
 					   struct inode *inode,
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index c26a84439934..c68f005b6e86 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -1302,9 +1302,13 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args,
 			 * on a stacked fs (e.g. overlayfs) themselves and with
 			 * max_stack_depth == 1, FUSE fs can be stacked as the
 			 * underlying fs of a stacked fs (e.g. overlayfs).
+			 *
+			 * For now, writeback cache and passthrough cannot be
+			 * enabled on the same filesystem.
 			 */
 			if (IS_ENABLED(CONFIG_FUSE_PASSTHROUGH) &&
 			    (flags & FUSE_PASSTHROUGH) &&
+			    !fc->writeback_cache &&
 			    arg->max_stack_depth > 0 &&
 			    arg->max_stack_depth <= FILESYSTEM_MAX_STACK_DEPTH) {
 				fc->passthrough = 1;
diff --git a/fs/fuse/iomode.c b/fs/fuse/iomode.c
index c545058a01e1..96eb311fe7bd 100644
--- a/fs/fuse/iomode.c
+++ b/fs/fuse/iomode.c
@@ -157,8 +157,11 @@ void fuse_file_uncached_io_end(struct inode *inode)
 	spin_unlock(&fi->lock);
 	if (!uncached_io)
 		wake_up(&fi->direct_io_waitq);
-	if (oldfb)
+	if (oldfb) {
+		/* Maybe update attributes after detaching backing inode */
+		fuse_backing_update_attr(inode, oldfb);
 		fuse_backing_put(oldfb);
+	}
 }
 
 /*
diff --git a/fs/fuse/passthrough.c b/fs/fuse/passthrough.c
index 260e76fc72d5..c1bb80a6e536 100644
--- a/fs/fuse/passthrough.c
+++ b/fs/fuse/passthrough.c
@@ -11,11 +11,8 @@
 #include <linux/backing-file.h>
 #include <linux/splice.h>
 
-static void fuse_file_accessed(struct file *file)
+static void fuse_backing_accessed(struct inode *inode, struct fuse_backing *fb)
 {
-	struct inode *inode = file_inode(file);
-	struct fuse_inode *fi = get_fuse_inode(inode);
-	struct fuse_backing *fb = fuse_inode_backing(fi);
 	struct inode *backing_inode = file_inode(fb->file);
 	struct timespec64 atime = inode_get_atime(inode);
 	struct timespec64 batime = inode_get_atime(backing_inode);
@@ -25,11 +22,8 @@ static void fuse_file_accessed(struct file *file)
 		fuse_invalidate_atime(inode);
 }
 
-static void fuse_file_modified(struct file *file)
+static void fuse_backing_modified(struct inode *inode, struct fuse_backing *fb)
 {
-	struct inode *inode = file_inode(file);
-	struct fuse_inode *fi = get_fuse_inode(inode);
-	struct fuse_backing *fb = fuse_inode_backing(fi);
 	struct inode *backing_inode = file_inode(fb->file);
 	struct timespec64 ctime = inode_get_ctime(inode);
 	struct timespec64 mtime = inode_get_mtime(inode);
@@ -42,6 +36,51 @@ static void fuse_file_modified(struct file *file)
 		fuse_invalidate_attr_mask(inode, FUSE_STATX_MODSIZE);
 }
 
+/* Called from fuse_file_uncached_io_end() after detach of backing inode */
+void fuse_backing_update_attr(struct inode *inode, struct fuse_backing *fb)
+{
+	fuse_backing_modified(inode, fb);
+	fuse_backing_accessed(inode, fb);
+}
+
+/* Called from fuse_getattr() - may race with detach of backing inode */
+void fuse_backing_update_attr_mask(struct inode *inode, u32 request_mask)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	struct fuse_backing *fb;
+
+	rcu_read_lock();
+	fb = fuse_backing_get(fuse_inode_backing(fi));
+	rcu_read_unlock();
+	if (!fb)
+		return;
+
+	if (request_mask & FUSE_STATX_MODSIZE)
+		fuse_backing_modified(inode, fb);
+	if (request_mask & STATX_ATIME)
+		fuse_backing_accessed(inode, fb);
+
+	fuse_backing_put(fb);
+}
+
+static void fuse_file_accessed(struct file *file)
+{
+	struct inode *inode = file_inode(file);
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	struct fuse_backing *fb = fuse_inode_backing(fi);
+
+	fuse_backing_accessed(inode, fb);
+}
+
+static void fuse_file_modified(struct file *file)
+{
+	struct inode *inode = file_inode(file);
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	struct fuse_backing *fb = fuse_inode_backing(fi);
+
+	fuse_backing_modified(inode, fb);
+}
+
 ssize_t fuse_passthrough_read_iter(struct kiocb *iocb, struct iov_iter *iter)
 {
 	struct file *file = iocb->ki_filp;
-- 
2.34.1


  parent reply	other threads:[~2024-02-06 14:25 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-06 14:24 [PATCH v15 0/9] FUSE passthrough for file io Amir Goldstein
2024-02-06 14:24 ` [PATCH v15 1/9] fuse: factor out helper for FUSE_DEV_IOC_CLONE Amir Goldstein
2024-02-06 14:24 ` [PATCH v15 2/9] fuse: introduce FUSE_PASSTHROUGH capability Amir Goldstein
2024-02-06 14:24 ` [PATCH v15 3/9] fuse: implement ioctls to manage backing files Amir Goldstein
2024-02-28 10:50   ` Jingbo Xu
2024-02-28 11:07     ` Amir Goldstein
2024-02-28 11:14       ` Miklos Szeredi
2024-02-28 11:28         ` Amir Goldstein
2024-02-28 14:32           ` Jens Axboe
2024-02-28 15:01             ` Miklos Szeredi
2024-02-28 15:05               ` Jens Axboe
2024-02-28 16:21               ` Amir Goldstein
2024-02-29 10:15               ` Christian Brauner
2024-02-29 10:17                 ` Christian Brauner
2024-03-05 10:57                   ` Miklos Szeredi
2024-02-28 13:22         ` Bernd Schubert
2024-02-06 14:24 ` [PATCH v15 4/9] fuse: prepare for opening file in passthrough mode Amir Goldstein
2024-02-06 14:24 ` [PATCH v15 5/9] fuse: implement open " Amir Goldstein
2024-02-06 14:24 ` [PATCH v15 6/9] fuse: implement read/write passthrough Amir Goldstein
2024-02-06 14:24 ` [PATCH v15 7/9] fuse: implement splice " Amir Goldstein
2024-02-06 14:24 ` [PATCH v15 8/9] fuse: implement passthrough for mmap Amir Goldstein
2024-02-06 14:24 ` Amir Goldstein [this message]
2024-04-02 20:13   ` [PATCH v15 9/9] fuse: auto-invalidate inode attributes in passthrough mode Sweet Tea Dorminy
2024-04-02 21:18     ` Bernd Schubert
2024-04-03  8:18       ` Amir Goldstein
2024-04-04 14:07         ` Sweet Tea Dorminy
2024-05-09 14:32           ` Amir Goldstein

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240206142453.1906268-10-amir73il@gmail.com \
    --to=amir73il@gmail.com \
    --cc=bernd.schubert@fastmail.fm \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).