From: Joanne Koong <joannelkoong@gmail.com>
To: miklos@szeredi.hu
Cc: amir73il@gmail.com, fuse-devel@lists.linux.dev, luis@igalia.com
Subject: [PATCH v1 04/17] fuse: implement passthrough for readdir
Date: Mon, 20 Apr 2026 15:16:24 -0700 [thread overview]
Message-ID: <20260420221637.2631478-5-joannelkoong@gmail.com> (raw)
In-Reply-To: <20260420221637.2631478-1-joannelkoong@gmail.com>
From: Amir Goldstein <amir73il@gmail.com>
Requires both requesting the passthrough inode op READDIR when setting
up the backing file and opening the dir with FOPEN_PASSTHROUGH.
The dir opened with FOPEN_PASSTHROUGH must not request cached readdir
with FOPEN_CACHE_DIR flag.
Like regular files, a directory inode cannot be opened at the same time
for cached readdir and readdir passthrough.
A directory opened without both FOPEN_CACHE_DIR and FOPEN_PASSTHROUGH
is marked as FOPEN_DIRECT_IO and does not affect io mode.
Note that opt-in for passthrough of READDIR operation means that there
is no READDIRPLUS call to server.
For the ls -l use case, the cost of FUSE_LOOKUP to server will be
paid for every entry, so passthrough of READDIR is not always a
performance win.
Reviewed-by: Joanne Koong <joannelkoong@gmail.com>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/fuse/backing.c | 5 +++++
fs/fuse/dir.c | 7 +++++++
fs/fuse/file.c | 15 +++++++++++++--
fs/fuse/fuse_i.h | 7 ++++++-
fs/fuse/iomode.c | 9 +++++++++
fs/fuse/passthrough.c | 24 ++++++++++++++++++++++++
fs/fuse/readdir.c | 3 +++
include/uapi/linux/fuse.h | 1 +
8 files changed, 68 insertions(+), 3 deletions(-)
diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c
index 830cbe2a4200..516f58e5ae18 100644
--- a/fs/fuse/backing.c
+++ b/fs/fuse/backing.c
@@ -113,6 +113,11 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)
!d_is_reg(file->f_path.dentry))
goto out_fput;
+ res = -ENOTDIR;
+ if (map->ops_mask & FUSE_PASSTHROUGH_DIR_OPS &&
+ !d_is_dir(file->f_path.dentry))
+ goto out_fput;
+
backing_sb = file_inode(file)->i_sb;
res = -ELOOP;
if (backing_sb->s_stack_depth >= fc->max_stack_depth)
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 015f0c103d06..16b266b51702 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -1891,6 +1891,7 @@ static const char *fuse_get_link(struct dentry *dentry, struct inode *inode,
static int fuse_dir_open(struct inode *inode, struct file *file)
{
struct fuse_mount *fm = get_fuse_mount(inode);
+ struct fuse_inode *fi = get_fuse_inode(inode);
int err;
if (fuse_is_bad(inode))
@@ -1904,6 +1905,12 @@ static int fuse_dir_open(struct inode *inode, struct file *file)
if (!err) {
struct fuse_file *ff = file->private_data;
+ err = fuse_file_io_open(file, inode);
+ if (err) {
+ fuse_sync_release(fi, ff, file->f_flags, true);
+ return err;
+ }
+
/*
* Keep handling FOPEN_STREAM and FOPEN_NONSEEKABLE for
* directories for backward compatibility, though it's unlikely
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 3da4ce73e11b..0db6abcf1033 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -180,8 +180,19 @@ struct fuse_file *fuse_file_open(struct fuse_mount *fm, u64 nodeid,
}
}
- if (isdir)
- ff->open_flags &= ~FOPEN_DIRECT_IO;
+ /*
+ * Mark an uncached dir open as FOPEN_DIRECT_IO for fuse_file_io_open().
+ * The explicit combination of FOPEN_PASSTHROUGH | FOPEN_DIRECT_IO is
+ * allowed and it means (similar to regular files) a request from the
+ * server for uncached readdir open for an inode that already has files
+ * open in passthrough readdir mode.
+ */
+ if (isdir) {
+ if (ff->open_flags & FOPEN_CACHE_DIR)
+ ff->open_flags &= ~FOPEN_DIRECT_IO;
+ else if (!(ff->open_flags & FOPEN_PASSTHROUGH))
+ ff->open_flags |= FOPEN_DIRECT_IO;
+ }
ff->nodeid = nodeid;
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 1c4646ad7c25..99798a9de3ed 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1559,9 +1559,13 @@ void fuse_file_release(struct inode *inode, struct fuse_file *ff,
#define FUSE_PASSTHROUGH_RW_OPS \
(FUSE_PASSTHROUGH_OP_READ | FUSE_PASSTHROUGH_OP_WRITE)
+/* Passthrough operations for directories */
+#define FUSE_PASSTHROUGH_DIR_OPS \
+ (FUSE_PASSTHROUGH_OP_READDIR)
+
/* File passthrough operations require a file opened with FOPEN_PASSTHROUGH */
#define FUSE_PASSTHROUGH_FILE_OPS \
- (FUSE_PASSTHROUGH_RW_OPS)
+ (FUSE_PASSTHROUGH_RW_OPS | FUSE_PASSTHROUGH_OP_READDIR)
/* Inode passthrough operations for backing file attached to inode */
#define FUSE_PASSTHROUGH_INODE_OPS (0)
@@ -1640,6 +1644,7 @@ ssize_t fuse_passthrough_splice_write(struct pipe_inode_info *pipe,
struct file *out, loff_t *ppos,
size_t len, unsigned int flags);
ssize_t fuse_passthrough_mmap(struct file *file, struct vm_area_struct *vma);
+int fuse_passthrough_readdir(struct file *file, struct dir_context *ctx);
static inline struct fuse_backing *fuse_inode_passthrough(struct fuse_inode *fi)
{
diff --git a/fs/fuse/iomode.c b/fs/fuse/iomode.c
index 2360b32793c2..3753b78cbb56 100644
--- a/fs/fuse/iomode.c
+++ b/fs/fuse/iomode.c
@@ -200,11 +200,18 @@ static int fuse_file_passthrough_open(struct inode *inode, struct file *file)
if (IS_ERR(fb))
return PTR_ERR(fb);
+ /* Readdir passthrough requires opt-in on backing file setup */
+ err = -EOPNOTSUPP;
+ if (S_ISDIR(inode->i_mode) &&
+ !(fb->ops_mask & FUSE_PASSTHROUGH_OP_READDIR))
+ goto fail;
+
/* First passthrough file open denies caching inode io mode */
err = fuse_file_uncached_io_open(inode, ff, fb);
if (!err)
return 0;
+fail:
fuse_passthrough_release(ff, fb);
fuse_backing_put(fb);
@@ -242,6 +249,8 @@ int fuse_file_io_open(struct file *file, struct inode *inode)
/*
* First passthrough file open denies caching inode io mode.
* First caching file open enters caching inode io mode.
+ * A directory opened without FOPEN_CACHE_DIR is marked with
+ * FOPEN_DIRECT_IO and like regular file dio, does not affect io mode.
*
* 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,
diff --git a/fs/fuse/passthrough.c b/fs/fuse/passthrough.c
index 72de97c03d0e..a1d87ed51a94 100644
--- a/fs/fuse/passthrough.c
+++ b/fs/fuse/passthrough.c
@@ -144,6 +144,30 @@ ssize_t fuse_passthrough_mmap(struct file *file, struct vm_area_struct *vma)
return backing_file_mmap(backing_file, vma, &ctx);
}
+int fuse_passthrough_readdir(struct file *file, struct dir_context *ctx)
+{
+ int ret;
+ const struct cred *old_cred;
+ struct inode *inode = file_inode(file);
+ struct fuse_file *ff = file->private_data;
+ struct file *backing_file = fuse_file_passthrough(ff);
+ bool locked;
+
+ pr_debug("%s: backing_file=0x%p, pos=%lld\n", __func__,
+ backing_file, ctx->pos);
+
+ old_cred = override_creds(ff->cred);
+ locked = fuse_lock_inode(inode);
+ /* Respect seekdir() on fuse dir */
+ vfs_llseek(backing_file, ctx->pos, SEEK_SET);
+ ret = iterate_dir(backing_file, ctx);
+ fuse_invalidate_atime(inode);
+ fuse_unlock_inode(inode, locked);
+ revert_creds(old_cred);
+
+ return ret;
+}
+
/*
* Setup passthrough to a backing file.
*
diff --git a/fs/fuse/readdir.c b/fs/fuse/readdir.c
index c88194e52d18..49226f022339 100644
--- a/fs/fuse/readdir.c
+++ b/fs/fuse/readdir.c
@@ -593,6 +593,9 @@ int fuse_readdir(struct file *file, struct dir_context *ctx)
if (fuse_is_bad(inode))
return -EIO;
+ if (fuse_file_passthrough(ff))
+ return fuse_passthrough_readdir(file, ctx);
+
err = UNCACHED;
if (ff->open_flags & FOPEN_CACHE_DIR)
err = fuse_readdir_cached(file, ctx);
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 0f1e1c1ec367..df366e390f0c 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -1142,6 +1142,7 @@ struct fuse_backing_map {
/* op bits for fuse_backing_map ops_mask */
#define FUSE_PASSTHROUGH_OP_READ FUSE_PASSTHROUGH_OP(FUSE_READ)
#define FUSE_PASSTHROUGH_OP_WRITE FUSE_PASSTHROUGH_OP(FUSE_WRITE)
+#define FUSE_PASSTHROUGH_OP_READDIR FUSE_PASSTHROUGH_OP(FUSE_READDIR)
/* Device ioctls: */
#define FUSE_DEV_IOC_MAGIC 229
--
2.52.0
next prev parent reply other threads:[~2026-04-20 22:18 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-20 22:16 [PATCH v1 00/17] fuse: extend passthrough to inode operations Joanne Koong
2026-04-20 22:16 ` [PATCH v1 01/17] fuse: introduce FUSE_PASSTHROUGH_INO mode Joanne Koong
2026-04-21 21:11 ` Darrick J. Wong
2026-04-21 23:38 ` Joanne Koong
2026-04-20 22:16 ` [PATCH v1 02/17] fuse: prepare for passthrough of inode operations Joanne Koong
2026-04-21 21:16 ` Darrick J. Wong
2026-04-22 1:12 ` Joanne Koong
2026-04-20 22:16 ` [PATCH v1 03/17] fuse: prepare for readdir passthrough on directories Joanne Koong
2026-04-21 21:17 ` Darrick J. Wong
2026-04-21 23:12 ` Joanne Koong
2026-04-20 22:16 ` Joanne Koong [this message]
2026-04-20 22:16 ` [PATCH v1 05/17] fuse: prepare for long lived reference on backing file Joanne Koong
2026-04-20 22:16 ` [PATCH v1 06/17] fuse: implement passthrough for getattr/statx Joanne Koong
2026-04-20 22:16 ` [PATCH v1 07/17] fuse: prepare to setup backing inode passthrough on lookup Joanne Koong
2026-04-20 22:16 ` [PATCH v1 08/17] fuse: add passthrough ops gating Joanne Koong
2026-04-21 10:48 ` Amir Goldstein
2026-04-22 2:57 ` Joanne Koong
2026-04-22 7:27 ` Amir Goldstein
2026-04-23 1:47 ` Joanne Koong
2026-04-20 22:16 ` [PATCH v1 09/17] fuse: prepare to cache statx attributes from entry replies Joanne Koong
2026-04-21 12:26 ` Amir Goldstein
2026-04-20 22:16 ` [PATCH v1 10/17] fuse: add struct fuse_entry2_out and helpers for extended " Joanne Koong
2026-04-21 12:25 ` Amir Goldstein
2026-04-22 0:50 ` Joanne Koong
2026-04-20 22:16 ` [PATCH v1 11/17] fuse: add passthrough lookup Joanne Koong
2026-04-21 13:23 ` Amir Goldstein
2026-04-22 3:17 ` Joanne Koong
2026-04-20 22:16 ` [PATCH v1 12/17] fuse: add passthrough support for entry creation Joanne Koong
2026-04-21 14:08 ` Amir Goldstein
2026-04-22 3:01 ` Joanne Koong
2026-04-20 22:16 ` [PATCH v1 13/17] fuse: add passthrough support for atomic file creation Joanne Koong
2026-04-21 19:51 ` Amir Goldstein
2026-04-22 0:40 ` Joanne Koong
2026-04-22 5:10 ` Amir Goldstein
2026-04-20 22:16 ` [PATCH v1 14/17] fuse: use passthrough getattr in setattr suid/sgid handling Joanne Koong
2026-04-21 14:25 ` Amir Goldstein
2026-04-22 3:48 ` Joanne Koong
2026-04-22 5:22 ` Amir Goldstein
2026-04-23 0:03 ` Joanne Koong
2026-04-20 22:16 ` [PATCH v1 15/17] fuse: add passthrough setattr Joanne Koong
2026-04-21 14:20 ` Amir Goldstein
2026-04-21 14:32 ` Amir Goldstein
2026-04-22 1:09 ` Joanne Koong
2026-04-20 22:16 ` [PATCH v1 16/17] fuse: add passthrough open Joanne Koong
2026-04-21 20:20 ` Amir Goldstein
2026-04-22 4:19 ` Joanne Koong
2026-04-22 4:23 ` Joanne Koong
2026-04-22 6:51 ` Amir Goldstein
2026-04-20 22:16 ` [PATCH v1 17/17] docs: fuse: document extended passthrough (FUSE_PASSTHROUGH_INO) Joanne Koong
2026-04-21 11:09 ` Amir Goldstein
2026-04-22 1:04 ` Joanne Koong
2026-04-21 9:37 ` [PATCH v1 00/17] fuse: extend passthrough to inode operations Amir Goldstein
2026-04-21 13:55 ` Amir Goldstein
2026-04-21 21:05 ` Joanne Koong
2026-04-22 6:02 ` Amir Goldstein
2026-04-23 1:02 ` Joanne Koong
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=20260420221637.2631478-5-joannelkoong@gmail.com \
--to=joannelkoong@gmail.com \
--cc=amir73il@gmail.com \
--cc=fuse-devel@lists.linux.dev \
--cc=luis@igalia.com \
--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