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 02/17] fuse: prepare for passthrough of inode operations
Date: Mon, 20 Apr 2026 15:16:22 -0700 [thread overview]
Message-ID: <20260420221637.2631478-3-joannelkoong@gmail.com> (raw)
In-Reply-To: <20260420221637.2631478-1-joannelkoong@gmail.com>
From: Amir Goldstein <amir73il@gmail.com>
So far, fuse passthrough was implemented for read/write/splice/mmap
operations for regular files opened with FOPEN_PASSTHROUGH.
A backing file is attached to a fuse inode, but only for as long as
there are FOPEN_PASSTHROUGH files opened on this inode.
We would like to attach a backing file to fuse inode also without an
open file to allow passthrough of some inode operations.
Add field ops_mask to the input argument of FUSE_DEV_IOC_BACKING_OPEN
ioctl to declare the operations that would passthrough to the backing
file once it has been attached to the fuse inode on lookup.
Setting the FUSE_READ/FUSE_WRITE operations in the ops_mask is not
required because those operations are implied by FOPEN_PASSTHROUGH.
When setting operations other than FUSE_READ/FUSE_WRITE in ops_mask,
non-regular backing files are allowed, so we need to verify when
attaching a backing file to a fuse inode, that their file types match.
For simplification of inode attribute caching, for now, require a
filesystem with FUSE_PASSTHROUGH_INO (one-to-one mapping from fuse inode
to backing inode) for setting up passthrough of any inode operations.
We may consider relaxing this requirement for some inode operations
in the future.
Reviewed-by: Joanne Koong <joannelkoong@gmail.com>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/fuse/backing.c | 13 ++++++++++---
fs/fuse/fuse_i.h | 40 +++++++++++++++++++++++++++++++++++++++
fs/fuse/iomode.c | 5 +++++
include/uapi/linux/fuse.h | 9 ++++++++-
4 files changed, 63 insertions(+), 4 deletions(-)
diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c
index d95dfa48483f..830cbe2a4200 100644
--- a/fs/fuse/backing.c
+++ b/fs/fuse/backing.c
@@ -86,7 +86,8 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)
struct fuse_backing *fb = NULL;
int res;
- pr_debug("%s: fd=%d flags=0x%x\n", __func__, map->fd, map->flags);
+ pr_debug("%s: fd=%d flags=0x%x ops_mask=0x%llx\n", __func__,
+ map->fd, map->flags, map->ops_mask);
/* TODO: relax CAP_SYS_ADMIN once backing files are visible to lsof */
res = -EPERM;
@@ -94,7 +95,11 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)
goto out;
res = -EINVAL;
- if (map->flags || map->padding)
+ if (map->flags || map->ops_mask & ~FUSE_BACKING_MAP_VALID_OPS)
+ goto out;
+
+ /* For now passthrough inode operations requires FUSE_PASSTHROUGH_INO */
+ if (!fc->passthrough_ino && map->ops_mask & FUSE_PASSTHROUGH_INODE_OPS)
goto out;
file = fget_raw(map->fd);
@@ -104,7 +109,8 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)
/* read/write/splice/mmap passthrough only relevant for regular files */
res = d_is_dir(file->f_path.dentry) ? -EISDIR : -EINVAL;
- if (!d_is_reg(file->f_path.dentry))
+ if (!(map->ops_mask & ~FUSE_PASSTHROUGH_RW_OPS) &&
+ !d_is_reg(file->f_path.dentry))
goto out_fput;
backing_sb = file_inode(file)->i_sb;
@@ -119,6 +125,7 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)
fb->file = file;
fb->cred = prepare_creds();
+ fb->ops_mask = map->ops_mask;
refcount_set(&fb->count, 1);
res = fuse_backing_id_alloc(fc, fb);
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 86fdf873d639..eb974739dd5e 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -107,6 +107,7 @@ struct fuse_submount_lookup {
struct fuse_backing {
struct file *file;
struct cred *cred;
+ u64 ops_mask;
/** refcount */
refcount_t count;
@@ -244,6 +245,8 @@ enum {
* or the fuse server has an exclusive "lease" on distributed fs
*/
FUSE_I_EXCLUSIVE,
+ /* Has backing file for inode ops passthrough */
+ FUSE_I_PASSTHROUGH,
};
struct fuse_conn;
@@ -1550,6 +1553,25 @@ struct fuse_file *fuse_file_open(struct fuse_mount *fm, u64 nodeid,
void fuse_file_release(struct inode *inode, struct fuse_file *ff,
unsigned int open_flags, fl_owner_t id, bool isdir);
+/* passthrough.c */
+
+/* READ/WRITE are implied by FOPEN_PASSTHROUGH, but defined for completeness */
+#define FUSE_PASSTHROUGH_RW_OPS \
+ (FUSE_PASSTHROUGH_OP_READ | FUSE_PASSTHROUGH_OP_WRITE)
+
+/* File passthrough operations require a file opened with FOPEN_PASSTHROUGH */
+#define FUSE_PASSTHROUGH_FILE_OPS \
+ (FUSE_PASSTHROUGH_RW_OPS)
+
+/* Inode passthrough operations for backing file attached to inode */
+#define FUSE_PASSTHROUGH_INODE_OPS (0)
+
+#define FUSE_BACKING_MAP_OP(map, op) \
+ ((map)->ops_mask & FUSE_PASSTHROUGH_OP(op))
+
+#define FUSE_BACKING_MAP_VALID_OPS \
+ (FUSE_PASSTHROUGH_FILE_OPS | FUSE_PASSTHROUGH_INODE_OPS)
+
/* backing.c */
#ifdef CONFIG_FUSE_PASSTHROUGH
struct fuse_backing *fuse_backing_get(struct fuse_backing *fb);
@@ -1619,6 +1641,24 @@ ssize_t fuse_passthrough_splice_write(struct pipe_inode_info *pipe,
size_t len, unsigned int flags);
ssize_t fuse_passthrough_mmap(struct file *file, struct vm_area_struct *vma);
+static inline struct fuse_backing *fuse_inode_passthrough(struct fuse_inode *fi)
+{
+#ifdef CONFIG_FUSE_PASSTHROUGH
+ if (test_bit(FUSE_I_PASSTHROUGH, &fi->state))
+ return fuse_inode_backing(fi);
+#endif
+ return NULL;
+}
+
+static inline bool fuse_inode_passthrough_op(struct inode *inode,
+ enum fuse_opcode op)
+{
+ struct fuse_inode *fi = get_fuse_inode(inode);
+ struct fuse_backing *fb = fuse_inode_passthrough(fi);
+
+ return fb && fb->ops_mask & FUSE_PASSTHROUGH_OP(op);
+}
+
#ifdef CONFIG_SYSCTL
extern int fuse_sysctl_register(void);
extern void fuse_sysctl_unregister(void);
diff --git a/fs/fuse/iomode.c b/fs/fuse/iomode.c
index ca3b28597722..6815b4506007 100644
--- a/fs/fuse/iomode.c
+++ b/fs/fuse/iomode.c
@@ -96,6 +96,11 @@ int fuse_inode_uncached_io_start(struct inode *inode, struct fuse_backing *fb)
err = -EBUSY;
goto unlock;
}
+ /* fuse and backing file types must match */
+ if (fb && ((fb->file->f_inode->i_mode ^ inode->i_mode) & S_IFMT)) {
+ err = -EIO;
+ goto unlock;
+ }
/* With FUSE_PASSTHROUGH_INO, fuse and backing ino must match */
if (fb && fc->passthrough_ino &&
fb->file->f_inode->i_ino != inode->i_ino) {
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 4be9ccc5b3ff..0f1e1c1ec367 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -243,6 +243,7 @@
*
* 7.46
* - add FUSE_PASSTHROUGH_INO
+ * - add ops_mask field to struct fuse_backing_map
*/
#ifndef _LINUX_FUSE_H
@@ -1133,9 +1134,15 @@ struct fuse_notify_prune_out {
struct fuse_backing_map {
int32_t fd;
uint32_t flags;
- uint64_t padding;
+ uint64_t ops_mask;
};
+#define FUSE_PASSTHROUGH_OP(op) (1ULL << ((op) - 1))
+
+/* 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)
+
/* Device ioctls: */
#define FUSE_DEV_IOC_MAGIC 229
#define FUSE_DEV_IOC_CLONE _IOR(FUSE_DEV_IOC_MAGIC, 0, uint32_t)
--
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 ` Joanne Koong [this message]
2026-04-21 21:16 ` [PATCH v1 02/17] fuse: prepare for passthrough of inode operations 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 ` [PATCH v1 04/17] fuse: implement passthrough for readdir Joanne Koong
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-3-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