mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Russ Fellows <russ.fellows@gmail.com>
To: miklos@szeredi.hu
Cc: fuse-devel@lists.linux.dev, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, amir73il@gmail.com,
	Russ Fellows <rfellows@xlrait.dev>
Subject: [PATCH v2 2/2] fuse: allow parallel direct writes in passthrough write_iter
Date: Tue, 16 Jun 2026 01:44:19 +0000	[thread overview]
Message-ID: <20260616014419.7913-3-russ.fellows@gmail.com> (raw)
In-Reply-To: <20260616014419.7913-1-russ.fellows@gmail.com>

From: Russ Fellows <rfellows@xlrait.dev>

fuse_passthrough_write_iter() currently relies on the generic fuse_dio_lock() path to decide whether writes may run under a shared inode lock. That couples passthrough to the regular direct-IO helpers and does not make the passthrough-specific safety conditions explicit.

Keep the decision local to passthrough.c instead. Allow shared inode locking only when all of the following are true:

- the open carries FOPEN_PARALLEL_DIRECT_WRITES
- the write is direct I/O
- the write is not append
- the write does not extend past EOF

Buffered writes, append writes, and EOF-extending writes remain serialized under the exclusive inode lock.

This preserves the parallel direct-write win for safe overwrite I/O without exporting extra helper APIs from file.c.

Signed-off-by: Russ Fellows <rfellows@xlrait.dev>
---
 fs/fuse/passthrough.c | 46 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/fs/fuse/passthrough.c b/fs/fuse/passthrough.c
index ee822a983..c32b35a6d 100644
--- a/fs/fuse/passthrough.c
+++ b/fs/fuse/passthrough.c
@@ -25,6 +25,38 @@ static void fuse_passthrough_end_write(struct kiocb *iocb, ssize_t ret)
	fuse_write_update_attr(inode, iocb->ki_pos, ret);
 }
 
+static bool fuse_passthrough_io_past_eof(struct kiocb *iocb,
+					 struct iov_iter *iter)
+{
+	struct inode *inode = file_inode(iocb->ki_filp);
+
+	return iocb->ki_pos + iov_iter_count(iter) > i_size_read(inode);
+}
+
+static bool fuse_passthrough_write_exclusive(struct kiocb *iocb,
+					     struct iov_iter *iter)
+{
+	struct file *file = iocb->ki_filp;
+	struct fuse_file *ff = file->private_data;
+
+	if (!(ff->open_flags & FOPEN_PARALLEL_DIRECT_WRITES))
+		return true;
+
+	/*
+	 * Passthrough writes do not use the regular FUSE direct-IO iomode path.
+	 * Allow shared locking only for direct overwrite I/O; buffered writes,
+	 * append writes, and writes that may extend EOF remain serialized.
+	 */
+	if (!(iocb->ki_flags & IOCB_DIRECT))
+		return true;
+	if (iocb->ki_flags & IOCB_APPEND)
+		return true;
+	if (fuse_passthrough_io_past_eof(iocb, iter))
+		return true;
+
+	return false;
+}
+
 ssize_t fuse_passthrough_read_iter(struct kiocb *iocb, struct iov_iter *iter)
 {
	struct file *file = iocb->ki_filp;
@@ -54,6 +86,7 @@ ssize_t fuse_passthrough_write_iter(struct kiocb *iocb,
				    struct iov_iter *iter)
 {
	struct file *file = iocb->ki_filp;
+	struct inode *inode = file_inode(file);
	struct fuse_file *ff = file->private_data;
	struct file *backing_file = fuse_file_passthrough(ff);
	size_t count = iov_iter_count(iter);
@@ -70,10 +103,19 @@ ssize_t fuse_passthrough_write_iter(struct kiocb *iocb,
	if (!count)
		return 0;
 
-	fuse_dio_lock(iocb, iter, &exclusive);
+	exclusive = fuse_passthrough_write_exclusive(iocb, iter);
+	if (exclusive)
+		inode_lock(inode);
+	else
+		inode_lock_shared(inode);
+
	ret = backing_file_write_iter(backing_file, iter, iocb, iocb->ki_flags,
				     &ctx);
-	fuse_dio_unlock(iocb, exclusive);
+
+	if (exclusive)
+		inode_unlock(inode);
+	else
+		inode_unlock_shared(inode);
 
	return ret;
 }
-- 
2.51.0

  parent reply	other threads:[~2026-06-16  1:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-29  3:19 [PATCH 0/2] fuse: fix and optimize parallel writes on passthrough mounts Russ Fellows
2026-05-29  3:19 ` [PATCH 1/2] fuse: fix FOPEN_PARALLEL_DIRECT_WRITES being ignored for passthrough writes Russ Fellows
2026-06-01 18:52   ` Amir Goldstein
2026-06-01 19:25     ` Russ Fellows
2026-06-01 20:23       ` Amir Goldstein
2026-05-29  3:19 ` [PATCH 2/2] fuse: reduce fi->lock contention on parallel direct I/O Russ Fellows
2026-06-16  1:44 ` [PATCH v2 0/2] fuse: fix passthrough parallel direct writes with a minimal series Russ Fellows
2026-06-16  1:44   ` [PATCH v2 1/2] fuse: preserve FOPEN_PARALLEL_DIRECT_WRITES for passthrough opens Russ Fellows
2026-06-16 11:06     ` Amir Goldstein
2026-06-16  1:44   ` Russ Fellows [this message]
2026-06-16 11:50     ` [PATCH v2 2/2] fuse: allow parallel direct writes in passthrough write_iter 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=20260616014419.7913-3-russ.fellows@gmail.com \
    --to=russ.fellows@gmail.com \
    --cc=amir73il@gmail.com \
    --cc=fuse-devel@lists.linux.dev \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=rfellows@xlrait.dev \
    /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

Powered by JetHome