From: Joanne Koong <joannelkoong@gmail.com>
To: amir73il@gmail.com, miklos@szeredi.hu
Cc: fuse-devel@lists.linux.dev, linux-unionfs@vger.kernel.org
Subject: [PATCH v2 04/21] fuse: implement passthrough for readdir
Date: Fri, 15 May 2026 17:39:47 -0700 [thread overview]
Message-ID: <20260516004004.1455526-5-joannelkoong@gmail.com> (raw)
In-Reply-To: <20260516004004.1455526-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, 67 insertions(+), 4 deletions(-)
diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c
index 1fbb4d876eec..52fccb9ff283 100644
--- a/fs/fuse/backing.c
+++ b/fs/fuse/backing.c
@@ -114,6 +114,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 937165788e79..05f69b8fa4c4 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 332032cd5622..828e3fc0ec31 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 2436219338b3..23d2510f8e93 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1264,9 +1264,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)
@@ -1343,6 +1347,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 bool fuse_passthrough_op(struct inode *inode, enum fuse_opcode op)
{
diff --git a/fs/fuse/iomode.c b/fs/fuse/iomode.c
index e2e7fbaac9af..c83a070cd834 100644
--- a/fs/fuse/iomode.c
+++ b/fs/fuse/iomode.c
@@ -201,15 +201,20 @@ static int fuse_file_passthrough_open(struct inode *inode, struct file *file)
if (IS_ERR(fb))
return PTR_ERR(fb);
+ err = -EOPNOTSUPP;
/*
* Inode ops passthrough requires backing file setup at
* creation/lookup time.
*/
- err = -EOPNOTSUPP;
if (!fuse_inode_backing(fi) &&
(fb->ops_mask & FUSE_PASSTHROUGH_INODE_OPS))
goto fail;
+ /* Readdir passthrough requires opt-in on backing file setup */
+ 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)
@@ -253,6 +258,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-05-16 0:52 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-16 0:39 [PATCH v2 00/21] fuse: extend passthrough to inode operations Joanne Koong
2026-05-16 0:39 ` [PATCH v2 01/21] fuse: introduce FUSE_PASSTHROUGH_INO mode Joanne Koong
2026-05-16 0:39 ` [PATCH v2 02/21] fuse: prepare for passthrough of inode operations Joanne Koong
2026-05-16 1:34 ` Joanne Koong
2026-05-16 0:39 ` [PATCH v2 03/21] fuse: prepare for readdir passthrough on directories Joanne Koong
2026-05-16 0:39 ` Joanne Koong [this message]
2026-05-16 0:39 ` [PATCH v2 05/21] fuse: prepare for long lived reference on backing file Joanne Koong
2026-05-16 0:39 ` [PATCH v2 06/21] fuse: implement passthrough for getattr/statx Joanne Koong
2026-05-16 12:42 ` Amir Goldstein
2026-05-16 0:39 ` [PATCH v2 07/21] fuse: prepare to setup backing inode passthrough on lookup Joanne Koong
2026-05-16 0:39 ` [PATCH v2 08/21] fuse: handle zero ops_mask in FUSE_DEV_IOC_BACKING_OPEN Joanne Koong
2026-05-16 0:39 ` [PATCH v2 09/21] fuse: handle partial io passthrough for read/write, splice, and mmap Joanne Koong
2026-05-16 0:39 ` [PATCH v2 10/21] fuse: prepare to cache statx attributes from entry replies Joanne Koong
2026-05-16 0:39 ` [PATCH v2 11/21] fuse: clean up fuse_dentry_revalidate() Joanne Koong
2026-05-16 0:39 ` [PATCH v2 12/21] fuse: add struct fuse_entry2_out and helpers for extended entry replies Joanne Koong
2026-05-16 0:39 ` [PATCH v2 13/21] fuse: add passthrough lookup Joanne Koong
2026-05-16 0:39 ` [PATCH v2 14/21] fuse: add passthrough support for entry creation Joanne Koong
2026-05-16 0:39 ` [PATCH v2 15/21] fuse: add passthrough support for create+open Joanne Koong
2026-05-16 0:39 ` [PATCH v2 16/21] fuse: allow backing_id=0 in open to inherit inode's backing file Joanne Koong
2026-05-16 0:40 ` [PATCH v2 17/21] backing-inode: add backing_inode_copyattr() Joanne Koong
2026-05-16 0:40 ` [PATCH v2 18/21] backing-inode: add backing_inode_setattr() Joanne Koong
2026-05-16 0:40 ` [PATCH v2 19/21] fuse: add passthrough setattr Joanne Koong
2026-05-16 1:04 ` Joanne Koong
2026-05-16 0:40 ` [PATCH v2 20/21] fuse: use passthrough getattr in setattr suid/sgid handling Joanne Koong
2026-05-16 1:20 ` Joanne Koong
2026-05-16 0:40 ` [PATCH v2 21/21] docs: fuse: document extended passthrough (FUSE_PASSTHROUGH_INO) 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=20260516004004.1455526-5-joannelkoong@gmail.com \
--to=joannelkoong@gmail.com \
--cc=amir73il@gmail.com \
--cc=fuse-devel@lists.linux.dev \
--cc=linux-unionfs@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.