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 06/21] fuse: implement passthrough for getattr/statx
Date: Fri, 15 May 2026 17:39:49 -0700 [thread overview]
Message-ID: <20260516004004.1455526-7-joannelkoong@gmail.com> (raw)
In-Reply-To: <20260516004004.1455526-1-joannelkoong@gmail.com>
From: Amir Goldstein <amir73il@gmail.com>
Call vfs_getattr() on backing inode to respond to a user statx(2)
request and update the fuse inode attributes with the response.
For now, we assume that calling vfs_getattr() on backing inode is cheap,
so we never use cached attributed and always update fuse inode
attributes from backing attributes in fuse_permission() and
fuse_update_attributes().
Reviewed-by: Joanne Koong <joannelkoong@gmail.com>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/fuse/dir.c | 32 ++++++++++++++++++++++++++++++++
fs/fuse/fuse_i.h | 8 +++++++-
fs/fuse/passthrough.c | 36 ++++++++++++++++++++++++++++++++++++
include/uapi/linux/fuse.h | 1 +
4 files changed, 76 insertions(+), 1 deletion(-)
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 05f69b8fa4c4..9a8e525f4d2b 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -1414,6 +1414,28 @@ static void fuse_statx_to_attr(struct fuse_statx *sx, struct fuse_attr *attr)
attr->blksize = sx->blksize;
}
+void fuse_kstat_to_attr(struct fuse_conn *fc, const struct kstat *stat,
+ struct fuse_attr *attr)
+{
+ memset(attr, 0, sizeof(*attr));
+
+ attr->ino = stat->ino;
+ attr->size = stat->size;
+ attr->blocks = stat->blocks;
+ attr->atime = stat->atime.tv_sec;
+ attr->mtime = stat->mtime.tv_sec;
+ attr->ctime = stat->ctime.tv_sec;
+ attr->atimensec = stat->atime.tv_nsec;
+ attr->mtimensec = stat->mtime.tv_nsec;
+ attr->ctimensec = stat->ctime.tv_nsec;
+ attr->mode = stat->mode;
+ attr->nlink = stat->nlink;
+ attr->uid = from_kuid(fc->user_ns, stat->uid);
+ attr->gid = from_kgid(fc->user_ns, stat->gid);
+ attr->rdev = new_encode_dev(MKDEV(MAJOR(stat->rdev), MINOR(stat->rdev)));
+ attr->blksize = stat->blksize;
+}
+
static int fuse_do_statx(struct mnt_idmap *idmap, struct inode *inode,
struct file *file, struct kstat *stat)
{
@@ -1539,6 +1561,12 @@ static int fuse_update_get_attr(struct mnt_idmap *idmap, struct inode *inode,
if (fc->no_statx)
request_mask &= STATX_BASIC_STATS;
+ if (fuse_passthrough_op(inode, FUSE_GETATTR)) {
+ forget_all_cached_acls(inode);
+ return fuse_passthrough_getattr(inode, stat, request_mask,
+ flags);
+ }
+
if (!request_mask)
sync = false;
else if (flags & AT_STATX_FORCE_SYNC)
@@ -1737,6 +1765,10 @@ static int fuse_perm_getattr(struct inode *inode, int mask)
return -ECHILD;
forget_all_cached_acls(inode);
+ if (fuse_passthrough_op(inode, FUSE_GETATTR))
+ return fuse_passthrough_getattr(inode, NULL,
+ STATX_BASIC_STATS, 0);
+
return fuse_do_getattr(&nop_mnt_idmap, inode, NULL, NULL);
}
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 502b3b3f7e89..389e28497dc7 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -991,6 +991,8 @@ void fuse_init_symlink(struct inode *inode);
/*
* Change attributes of an inode
*/
+void fuse_kstat_to_attr(struct fuse_conn *fc, const struct kstat *stat,
+ struct fuse_attr *attr);
void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
struct fuse_statx *sx,
u64 attr_valid, u64 attr_version);
@@ -1274,7 +1276,8 @@ void fuse_file_release(struct inode *inode, struct fuse_file *ff,
(FUSE_PASSTHROUGH_RW_OPS | FUSE_PASSTHROUGH_OP_READDIR)
/* Inode passthrough operations for backing file attached to inode */
-#define FUSE_PASSTHROUGH_INODE_OPS (0)
+#define FUSE_PASSTHROUGH_INODE_OPS \
+ (FUSE_PASSTHROUGH_OP_GETATTR)
#define FUSE_BACKING_MAP_OP(map, op) \
((map)->ops_mask & FUSE_PASSTHROUGH_OP(op))
@@ -1358,6 +1361,9 @@ static inline bool fuse_passthrough_op(struct inode *inode, enum fuse_opcode op)
return fb && fb->ops_mask & FUSE_PASSTHROUGH_OP(op);
}
+int fuse_passthrough_getattr(struct inode *inode, struct kstat *stat,
+ u32 request_mask, unsigned int flags);
+
#ifdef CONFIG_SYSCTL
extern int fuse_sysctl_register(void);
extern void fuse_sysctl_unregister(void);
diff --git a/fs/fuse/passthrough.c b/fs/fuse/passthrough.c
index a1d87ed51a94..7de038960b2f 100644
--- a/fs/fuse/passthrough.c
+++ b/fs/fuse/passthrough.c
@@ -219,3 +219,39 @@ void fuse_passthrough_release(struct fuse_file *ff, struct fuse_backing *fb)
put_cred(ff->cred);
ff->cred = NULL;
}
+
+/*
+ * Inode passthrough operations for backing file attached on lookup.
+ */
+int fuse_passthrough_getattr(struct inode *inode, struct kstat *stat,
+ u32 request_mask, unsigned int flags)
+{
+ struct fuse_conn *fc = get_fuse_conn(inode);
+ struct fuse_inode *fi = get_fuse_inode(inode);
+ struct fuse_backing *fb = fuse_inode_backing(fi);
+ u64 attr_version = fuse_get_attr_version(fc);
+ const struct path *fb_path = &fb->file->f_path;
+ const struct cred *old_cred;
+ struct kstat backing_stat;
+ struct fuse_attr attr;
+ int err;
+
+ if (!stat)
+ stat = &backing_stat;
+
+ old_cred = override_creds(fb->cred);
+ err = vfs_getattr(fb_path, stat, request_mask, flags);
+ revert_creds(old_cred);
+ if (err)
+ return err;
+
+ /* Always override st_dev and st_ino with FUSE dev and ino */
+ stat->dev = inode->i_sb->s_dev;
+ stat->ino = inode->i_ino;
+
+ /* Fill fuse inode attrs from backing inode stat */
+ fuse_kstat_to_attr(fc, stat, &attr);
+ fuse_change_attributes(inode, &attr, NULL, 0, attr_version);
+
+ return 0;
+}
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index df366e390f0c..6404ed95c758 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -1143,6 +1143,7 @@ struct fuse_backing_map {
#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)
+#define FUSE_PASSTHROUGH_OP_GETATTR FUSE_PASSTHROUGH_OP(FUSE_GETATTR)
/* 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: 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 ` Joanne Koong [this message]
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-7-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