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 07/21] fuse: prepare to setup backing inode passthrough on lookup
Date: Fri, 15 May 2026 17:39:50 -0700 [thread overview]
Message-ID: <20260516004004.1455526-8-joannelkoong@gmail.com> (raw)
In-Reply-To: <20260516004004.1455526-1-joannelkoong@gmail.com>
From: Amir Goldstein <amir73il@gmail.com>
Add a helper for requesting to associate a backing inode for inode
passthrough operations.
This helper is expected to be used to setup backing inode on lookup
response.
The minimal requirement for the backing inode is to support the
GETATTR passthrough op.
Unlike setting of passthrough from open, this mapping is created for
the entire lifetime of the inode and cannot be changed later.
Reviewed-by: Joanne Koong <joannelkoong@gmail.com>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/fuse/backing.c | 32 ++++++++++++++++++++------------
fs/fuse/fuse_i.h | 6 ++++--
fs/fuse/iomode.c | 43 +++++++++++++++++++++++++++++++++++++++++++
fs/fuse/passthrough.c | 12 +++++-------
4 files changed, 72 insertions(+), 21 deletions(-)
diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c
index 52fccb9ff283..2234ab47406a 100644
--- a/fs/fuse/backing.c
+++ b/fs/fuse/backing.c
@@ -17,6 +17,26 @@ struct fuse_backing *fuse_backing_get(struct fuse_backing *fb)
return NULL;
}
+/*
+ * Get fuse backing object by backing id.
+ *
+ * Returns an fb object with elevated refcount to be stored in fuse inode.
+ */
+struct fuse_backing *fuse_backing_id_get(struct fuse_conn *fc, int backing_id)
+{
+ struct fuse_backing *fb;
+
+ if (backing_id <= 0)
+ return ERR_PTR(-EINVAL);
+
+ rcu_read_lock();
+ fb = idr_find(&fc->backing_files_map, backing_id);
+ fb = fuse_backing_get(fb);
+ rcu_read_unlock();
+
+ return fb;
+}
+
static void fuse_backing_free(struct fuse_backing *fb)
{
pr_debug("%s: fb=0x%p\n", __func__, fb);
@@ -178,15 +198,3 @@ int fuse_backing_close(struct fuse_conn *fc, int backing_id)
return err;
}
-
-struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc, int backing_id)
-{
- struct fuse_backing *fb;
-
- rcu_read_lock();
- fb = idr_find(&fc->backing_files_map, backing_id);
- fb = fuse_backing_get(fb);
- rcu_read_unlock();
-
- return fb;
-}
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 389e28497dc7..9e5142a94a09 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1289,7 +1289,7 @@ void fuse_file_release(struct inode *inode, struct fuse_file *ff,
#ifdef CONFIG_FUSE_PASSTHROUGH
struct fuse_backing *fuse_backing_get(struct fuse_backing *fb);
void fuse_backing_put(struct fuse_backing *fb);
-struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc, int backing_id);
+struct fuse_backing *fuse_backing_id_get(struct fuse_conn *fc, int backing_id);
#else
static inline struct fuse_backing *fuse_backing_get(struct fuse_backing *fb)
@@ -1300,7 +1300,7 @@ static inline struct fuse_backing *fuse_backing_get(struct fuse_backing *fb)
static inline void fuse_backing_put(struct fuse_backing *fb)
{
}
-static inline struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc,
+static inline struct fuse_backing *fuse_backing_id_get(struct fuse_conn *fc,
int backing_id)
{
return NULL;
@@ -1353,6 +1353,8 @@ ssize_t fuse_passthrough_splice_write(struct pipe_inode_info *pipe,
ssize_t fuse_passthrough_mmap(struct file *file, struct vm_area_struct *vma);
int fuse_passthrough_readdir(struct file *file, struct dir_context *ctx);
+int fuse_inode_set_passthrough(struct inode *inode, int backing_id);
+
static inline bool fuse_passthrough_op(struct inode *inode, enum fuse_opcode op)
{
struct fuse_inode *fi = get_fuse_inode(inode);
diff --git a/fs/fuse/iomode.c b/fs/fuse/iomode.c
index 6e2ddfe384b3..3483aaec698e 100644
--- a/fs/fuse/iomode.c
+++ b/fs/fuse/iomode.c
@@ -181,6 +181,49 @@ static void fuse_file_uncached_io_release(struct fuse_file *ff,
fuse_inode_uncached_io_end(inode);
}
+/* Setup passthrough for inode operations without an open file */
+int fuse_inode_set_passthrough(struct inode *inode, int backing_id)
+{
+ struct fuse_conn *fc = get_fuse_conn(inode);
+ struct fuse_inode *fi = get_fuse_inode(inode);
+ struct fuse_backing *current_fb, *fb;
+ int err;
+
+ if (!IS_ENABLED(CONFIG_FUSE_PASSTHROUGH) || !fc->passthrough_ino)
+ return 0;
+
+ fb = fuse_backing_id_get(fc, backing_id);
+ if (IS_ERR_OR_NULL(fb)) {
+ err = fb ? PTR_ERR(fb) : -ENOENT;
+ fb = NULL;
+ goto fail;
+ }
+
+ current_fb = fuse_inode_backing(fi);
+ if (current_fb) {
+ /* Different backing file on same inode is not allowed */
+ err = current_fb == fb ? 0 : -EBUSY;
+ fuse_backing_put(fb);
+ return err;
+ }
+
+ /* Backing inode requires at least GETATTR op passthrough */
+ err = -EOPNOTSUPP;
+ if (!(fb->ops_mask & FUSE_PASSTHROUGH_OP_GETATTR))
+ goto fail;
+
+ err = fuse_inode_uncached_io_start(inode, NULL, fb);
+ if (err)
+ goto fail;
+
+ return 0;
+fail:
+ fuse_backing_put(fb);
+ pr_debug("failed to setup backing inode (ino=%lu, backing_id=%d, err=%i).\n",
+ inode->i_ino, backing_id, err);
+ return err;
+}
+
/*
* Open flags that are allowed in combination with FOPEN_PASSTHROUGH.
* A combination of FOPEN_PASSTHROUGH and FOPEN_DIRECT_IO means that read/write
diff --git a/fs/fuse/passthrough.c b/fs/fuse/passthrough.c
index 7de038960b2f..f2025772c9c1 100644
--- a/fs/fuse/passthrough.c
+++ b/fs/fuse/passthrough.c
@@ -181,14 +181,12 @@ struct fuse_backing *fuse_passthrough_open(struct file *file, int backing_id)
struct file *backing_file;
int err;
- err = -EINVAL;
- if (backing_id <= 0)
- goto out;
-
- err = -ENOENT;
- fb = fuse_backing_lookup(fc, backing_id);
- if (!fb)
+ fb = fuse_backing_id_get(fc, backing_id);
+ if (IS_ERR_OR_NULL(fb)) {
+ err = fb ? PTR_ERR(fb) : -ENOENT;
+ fb = NULL;
goto out;
+ }
/* Allocate backing file per fuse file to store fuse path */
backing_file = backing_file_open(&file->f_path, file->f_flags,
--
2.52.0
next prev parent reply other threads:[~2026-05-16 0:52 UTC|newest]
Thread overview: 25+ 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 ` [PATCH v2 04/21] fuse: implement passthrough for readdir Joanne Koong
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 0:39 ` Joanne Koong [this message]
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-8-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox