[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <176169810917.1424854.10390527171483697608.stgit@frogsfrogsfrogs>
Date: Tue, 28 Oct 2025 17:51:43 -0700
From: "Darrick J. Wong" <djwong@...nel.org>
To: djwong@...nel.org, miklos@...redi.hu
Cc: joannelkoong@...il.com, bernd@...ernd.com, neal@...pa.dev,
linux-ext4@...r.kernel.org, linux-fsdevel@...r.kernel.org
Subject: [PATCH 26/31] fuse: allow more statx fields
From: Darrick J. Wong <djwong@...nel.org>
Allow the fuse server to supply us with the more recently added fields
of struct statx.
Signed-off-by: "Darrick J. Wong" <djwong@...nel.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 e937add0ea7baf..f6b6944fad553c 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1735,6 +1735,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 976773bb6295ff..838d925d2947e0 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -339,7 +339,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 5e7e7d4c2c5085..c35ddd5070225c 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -1267,6 +1267,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 inode *inode,
+ struct kstat *stat,
+ const struct fuse_statx *sx)
+{
+ stat->result_mask = sx->mask & FUSE_SUPPORTED_STATX_MASK;
+
+ stat->attributes |= fuse_statx_attributes(inode, sx);
+ stat->attributes_mask |= fuse_statx_attributes_mask(inode, 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)
{
@@ -1290,7 +1334,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;
@@ -1318,11 +1362,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(inode, sx);
- stat->attributes_mask |= fuse_statx_attributes_mask(inode, sx);
+ kstat_from_fuse_statx(inode, stat, sx);
fuse_fillattr(idmap, inode, &attr, stat);
stat->result_mask |= STATX_TYPE;
}
@@ -1387,16 +1427,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;
@@ -1407,7 +1460,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) {
Powered by blists - more mailing lists