[PATCH 26/28] fuse: allow more statx fields

Darrick J. Wong
2025-09-16T00:34:45Z

Allow the fuse server to supply us with the more recently added fields
of struct statx.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
fs/fuse/fuse_i.h | 8 +++++
include/uapi/linux/fuse.h | 15 ++++++++-
fs/fuse/dir.c | 75 ++++++++++++++++++++++++++++++++++++++-------
3 files changed, 86 insertions(+), 12 deletions(-)

diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 4aa7199dd0cd9f..02af28f49cdfe5 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1733,6 +1733,14 @@ void fuse_iomap_sysfs_cleanup(struct kobject *kobj);

sector_t fuse_bmap(struct address_space *mapping, sector_t block);

+#if IS_ENABLED(CONFIG_FUSE_IOMAP_DEBUG)
+int fuse_iomap_sysfs_init(struct kobject *kobj);
+void fuse_iomap_sysfs_cleanup(struct kobject *kobj);
+#else
+# define fuse_iomap_sysfs_init(...) (0)
+# define fuse_iomap_sysfs_cleanup(...) ((void)0)
+#endif
+
#if IS_ENABLED(CONFIG_FUSE_IOMAP)
bool fuse_iomap_enabled(void);

diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index b63fba0a2c52c9..e0139fb43f82ea 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -334,7 +334,20 @@ struct fuse_statx {
uint32_t rdev_minor;
uint32_t dev_major;
uint32_t dev_minor;
- uint64_t __spare2[14];
+
+ uint64_t mnt_id;
+ uint32_t dio_mem_align;
+ uint32_t dio_offset_align;
+ uint64_t subvol;
+
+ uint32_t atomic_write_unit_min;
+ uint32_t atomic_write_unit_max;
+ uint32_t atomic_write_segments_max;
+ uint32_t dio_read_offset_align;
+ uint32_t atomic_write_unit_max_opt;
+ uint32_t __spare2[1];
+
+ uint64_t __spare3[8];
};

struct fuse_kstatfs {
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index d62ceadbc05fb2..b5e3536f1d53c1 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -1274,6 +1274,50 @@ static void fuse_statx_to_attr(struct fuse_statx *sx, struct fuse_attr *attr)
attr->blksize = sx->blksize;
}

+#define FUSE_SUPPORTED_STATX_MASK (STATX_BASIC_STATS | \
+ STATX_BTIME | \
+ STATX_DIOALIGN | \
+ STATX_SUBVOL | \
+ STATX_WRITE_ATOMIC)
+
+#define FUSE_UNCACHED_STATX_MASK (STATX_DIOALIGN | \
+ STATX_SUBVOL | \
+ STATX_WRITE_ATOMIC)
+
+static void kstat_from_fuse_statx(const struct fuse_conn *fc,
+ struct kstat *stat,
+ const struct fuse_statx *sx)
+{
+ stat->result_mask = sx->mask & FUSE_SUPPORTED_STATX_MASK;
+
+ stat->attributes |= fuse_statx_attributes(fc, sx);
+ stat->attributes_mask |= fuse_statx_attributes_mask(fc, sx);
+
+ if (sx->mask & STATX_BTIME) {
+ stat->btime.tv_sec = sx->btime.tv_sec;
+ stat->btime.tv_nsec = min_t(u32, sx->btime.tv_nsec,
+ NSEC_PER_SEC - 1);
+ }
+
+ if (sx->mask & STATX_DIOALIGN) {
+ stat->dio_mem_align = sx->dio_mem_align;
+ stat->dio_offset_align = sx->dio_offset_align;
+ }
+
+ if (sx->mask & STATX_SUBVOL)
+ stat->subvol = sx->subvol;
+
+ if (sx->mask & STATX_WRITE_ATOMIC) {
+ stat->atomic_write_unit_min = sx->atomic_write_unit_min;
+ stat->atomic_write_unit_max = sx->atomic_write_unit_max;
+ stat->atomic_write_unit_max_opt = sx->atomic_write_unit_max_opt;
+ stat->atomic_write_segments_max = sx->atomic_write_segments_max;
+ }
+
+ if (sx->mask & STATX_DIO_READ_ALIGN)
+ stat->dio_read_offset_align = sx->dio_read_offset_align;
+}
+
static int fuse_do_statx(struct mnt_idmap *idmap, struct inode *inode,
struct file *file, struct kstat *stat)
{
@@ -1297,7 +1341,7 @@ static int fuse_do_statx(struct mnt_idmap *idmap, struct inode *inode,
}
/* For now leave sync hints as the default, request all stats. */
inarg.sx_flags = 0;
- inarg.sx_mask = STATX_BASIC_STATS | STATX_BTIME;
+ inarg.sx_mask = FUSE_SUPPORTED_STATX_MASK;
args.opcode = FUSE_STATX;
args.nodeid = get_node_id(inode);
args.in_numargs = 1;
@@ -1325,11 +1369,7 @@ static int fuse_do_statx(struct mnt_idmap *idmap, struct inode *inode,
}

if (stat) {
- stat->result_mask = sx->mask & (STATX_BASIC_STATS | STATX_BTIME);
- stat->btime.tv_sec = sx->btime.tv_sec;
- stat->btime.tv_nsec = min_t(u32, sx->btime.tv_nsec, NSEC_PER_SEC - 1);
- stat->attributes |= fuse_statx_attributes(fm->fc, sx);
- stat->attributes_mask |= fuse_statx_attributes_mask(fm->fc, sx);
+ kstat_from_fuse_statx(fm->fc, stat, sx);
fuse_fillattr(idmap, inode, &attr, stat);
stat->result_mask |= STATX_TYPE;
}
@@ -1394,16 +1434,29 @@ static int fuse_update_get_attr(struct mnt_idmap *idmap, struct inode *inode,
u32 inval_mask = READ_ONCE(fi->inval_mask);
u32 cache_mask = fuse_get_cache_mask(inode);

-
- /* FUSE only supports basic stats and possibly btime */
- request_mask &= STATX_BASIC_STATS | STATX_BTIME;
+ /* Only ask for supported stats */
+ request_mask &= FUSE_SUPPORTED_STATX_MASK;
retry:
if (fc->no_statx)
request_mask &= STATX_BASIC_STATS;

if (!request_mask)
sync = false;
- else if (flags & AT_STATX_FORCE_SYNC)
+ else if (request_mask & FUSE_UNCACHED_STATX_MASK) {
+ switch (flags & AT_STATX_SYNC_TYPE) {
+ case AT_STATX_DONT_SYNC:
+ request_mask &= ~FUSE_UNCACHED_STATX_MASK;
+ sync = false;
+ break;
+ case AT_STATX_FORCE_SYNC:
+ case AT_STATX_SYNC_AS_STAT:
+ sync = true;
+ break;
+ default:
+ WARN_ON(1);
+ break;
+ }
+ } else if (flags & AT_STATX_FORCE_SYNC)
sync = true;
else if (flags & AT_STATX_DONT_SYNC)
sync = false;
@@ -1414,7 +1467,7 @@ static int fuse_update_get_attr(struct mnt_idmap *idmap, struct inode *inode,

if (sync) {
forget_all_cached_acls(inode);
- /* Try statx if BTIME is requested */
+ /* Try statx if a field not covered by regular stat is wanted */
if (!fc->no_statx && (request_mask & ~STATX_BASIC_STATS)) {
err = fuse_do_statx(idmap, inode, file, stat);
if (err == -ENOSYS) {