mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Russ Fellows <russ.fellows@gmail.com>
To: miklos@szeredi.hu, fuse-devel@lists.linux.dev,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Amir Goldstein <amir73il@gmail.com>,
	Russ Fellows <russ.fellows@gmail.com>
Subject: [PATCH v3 1/2] fuse: preserve FOPEN_PARALLEL_DIRECT_WRITES for passthrough opens
Date: Tue, 16 Jun 2026 23:13:21 +0000	[thread overview]
Message-ID: <20260616231325.16788-2-russ.fellows@gmail.com> (raw)
In-Reply-To: <20260616231325.16788-1-russ.fellows@gmail.com>

fuse_file_io_open() clears FOPEN_PARALLEL_DIRECT_WRITES for any open
that lacks FOPEN_DIRECT_IO.  That rule is too strict for passthrough
opens, which already bypass the page cache through the backing file
and do not need FOPEN_DIRECT_IO to guarantee direct-I/O semantics.
Clearing the flag before the passthrough write path sees it prevents
the kernel from ever taking the shared-lock path for passthrough writes.

Introduce FOPEN_IOMODE helper macros to classify the effective I/O mode
of an open file:

  FOPEN_IOMODE_IS_CACHED(oflags)      - page-cache I/O (neither flag)
  FOPEN_IOMODE_IS_DIRECT(oflags)      - DIRECT_IO is set
  FOPEN_IOMODE_IS_PASSTHROUGH(oflags) - PASSTHROUGH only (no DIRECT_IO)

Use FOPEN_IOMODE_IS_CACHED to express the PARALLEL_DIRECT_WRITES guard
cleanly: the flag is only suppressed for cached iomode, not for passthrough
or direct-IO mode.

This is a prerequisite for passthrough write parallelism; without it the
shared-lock path in the subsequent patch never activates.

Signed-off-by: Russ Fellows <russ.fellows@gmail.com>
---
 fs/fuse/iomode.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/fs/fuse/iomode.c b/fs/fuse/iomode.c
index c99e285f3..46e60b04c 100644
--- a/fs/fuse/iomode.c
+++ b/fs/fuse/iomode.c
@@ -165,6 +165,23 @@ static void fuse_file_uncached_io_release(struct fuse_file *ff,
 	(FOPEN_PASSTHROUGH | FOPEN_DIRECT_IO | FOPEN_PARALLEL_DIRECT_WRITES | \
 	 FOPEN_NOFLUSH)
 
+/*
+ * Helpers to classify the effective I/O mode of an open file.
+ *
+ * FOPEN_IOMODE()         - extract the mode-relevant bits
+ * FOPEN_IOMODE_IS_CACHED - neither DIRECT_IO nor PASSTHROUGH: page-cache I/O
+ * FOPEN_IOMODE_IS_DIRECT - DIRECT_IO is set (may also have PASSTHROUGH)
+ * FOPEN_IOMODE_IS_PASSTHROUGH - PASSTHROUGH only, without DIRECT_IO
+ */
+#define FOPEN_IOMODE(oflags) \
+	((oflags) & (FOPEN_DIRECT_IO | FOPEN_PASSTHROUGH))
+#define FOPEN_IOMODE_IS_CACHED(oflags) \
+	(FOPEN_IOMODE(oflags) == 0)
+#define FOPEN_IOMODE_IS_DIRECT(oflags) \
+	(FOPEN_IOMODE(oflags) & FOPEN_DIRECT_IO)
+#define FOPEN_IOMODE_IS_PASSTHROUGH(oflags) \
+	(FOPEN_IOMODE(oflags) == FOPEN_PASSTHROUGH)
+
 static int fuse_file_passthrough_open(struct inode *inode, struct file *file)
 {
 	struct fuse_file *ff = file->private_data;
@@ -216,9 +233,11 @@ int fuse_file_io_open(struct file *file, struct inode *inode)
 		goto fail;
 
 	/*
-	 * FOPEN_PARALLEL_DIRECT_WRITES requires FOPEN_DIRECT_IO.
+	 * FOPEN_PARALLEL_DIRECT_WRITES is not supported with cached iomode.
+	 * Passthrough and direct-IO both bypass the page cache, so both are
+	 * eligible to enable parallel direct writes.
 	 */
-	if (!(ff->open_flags & FOPEN_DIRECT_IO))
+	if (FOPEN_IOMODE_IS_CACHED(ff->open_flags))
 		ff->open_flags &= ~FOPEN_PARALLEL_DIRECT_WRITES;
 
 	/*
@@ -228,8 +247,13 @@ int fuse_file_io_open(struct file *file, struct inode *inode)
 	 * Note that if user opens a file open with O_DIRECT, but server did
 	 * not specify FOPEN_DIRECT_IO, a later fcntl() could remove O_DIRECT,
 	 * so we put the inode in caching mode to prevent parallel dio.
+	 *
+	 * Pure direct-IO (DIRECT_IO without PASSTHROUGH) needs no page-cache
+	 * iomode machinery — return early.  When DIRECT_IO and PASSTHROUGH are
+	 * both set, write_iter uses the direct-IO path but the backing file
+	 * still needs to be opened below.
 	 */
-	if ((ff->open_flags & FOPEN_DIRECT_IO) &&
+	if (FOPEN_IOMODE_IS_DIRECT(ff->open_flags) &&
 	    !(ff->open_flags & FOPEN_PASSTHROUGH))
 		return 0;
 
-- 
2.51.0


  reply	other threads:[~2026-06-16 23:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-16 23:13 [PATCH v3 0/2] fuse: fix passthrough parallel direct writes Russ Fellows
2026-06-16 23:13 ` Russ Fellows [this message]
2026-06-19  8:12   ` [PATCH v3 1/2] fuse: preserve FOPEN_PARALLEL_DIRECT_WRITES for passthrough opens Amir Goldstein
2026-06-16 23:13 ` [PATCH v3 2/2] fuse: allow parallel direct writes in passthrough write_iter Russ Fellows
2026-06-19  9:05   ` Amir Goldstein
2026-07-26  1:59 ` [PATCH v4 0/2] fuse: allow parallel direct writes for passthrough Russ Fellows
2026-07-26  1:59   ` [PATCH v4 1/2] fuse: preserve FOPEN_PARALLEL_DIRECT_WRITES for passthrough opens Russ Fellows
2026-07-26  1:59   ` [PATCH v4 2/2] fuse: allow parallel direct writes in passthrough write_iter Russ Fellows
2026-08-01 19:41   ` [PATCH v4 0/2] fuse: allow parallel direct writes for passthrough 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=20260616231325.16788-2-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 \
    /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

all inboxes | Powered by JetHome®