[PATCH 04/10] fuse_trace: use the iomap cache for iomap_begin

Darrick J. Wong
2025-09-16T00:39:27Z

Add tracepoints for the previous patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
fs/fuse/fuse_trace.h | 34 ++++++++++++++++++++++++++++++++++
fs/fuse/file_iomap.c | 7 ++++++-
2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index 6072ef187f9215..5f399b1604a2ac 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -400,6 +400,7 @@ struct fuse_iomap_lookup;

#define FUSE_IOMAP_TYPE_STRINGS \
{ FUSE_IOMAP_TYPE_PURE_OVERWRITE, "overwrite" }, \
+ { FUSE_IOMAP_TYPE_RETRY_CACHE, "retry" }, \
{ FUSE_IOMAP_TYPE_HOLE, "hole" }, \
{ FUSE_IOMAP_TYPE_DELALLOC, "delalloc" }, \
{ FUSE_IOMAP_TYPE_MAPPED, "mapped" }, \
@@ -1471,6 +1472,39 @@ TRACE_EVENT(fuse_iomap_cache_lookup_result,
FUSE_IOMAP_MAP_PRINTK_ARGS(got),
__entry->validity_cookie)
);
+
+TRACE_EVENT(fuse_iomap_invalid,
+ TP_PROTO(const struct inode *inode, const struct iomap *map,
+ uint64_t validity_cookie),
+ TP_ARGS(inode, map, validity_cookie),
+
+ TP_STRUCT__entry(
+ FUSE_INODE_FIELDS
+ FUSE_IOMAP_MAP_FIELDS(map)
+ __field(uint64_t, old_validity_cookie)
+ __field(uint64_t, validity_cookie)
+ ),
+
+ TP_fast_assign(
+ FUSE_INODE_ASSIGN(inode, fi, fm);
+
+ __entry->mapoffset = map->offset;
+ __entry->maplength = map->length;
+ __entry->maptype = map->type;
+ __entry->mapflags = map->flags;
+ __entry->mapaddr = map->addr;
+ __entry->mapdev = FUSE_IOMAP_DEV_NULL;
+
+ __entry->old_validity_cookie= map->validity_cookie;
+ __entry->validity_cookie= validity_cookie;
+ ),
+
+ TP_printk(FUSE_INODE_FMT FUSE_IOMAP_MAP_FMT() " old_cookie 0x%llx new_cookie 0x%llx",
+ FUSE_INODE_PRINTK_ARGS,
+ FUSE_IOMAP_MAP_PRINTK_ARGS(map),
+ __entry->old_validity_cookie,
+ __entry->validity_cookie)
+);
#endif /* CONFIG_FUSE_IOMAP */

#endif /* _TRACE_FUSE_H */
diff --git a/fs/fuse/file_iomap.c b/fs/fuse/file_iomap.c
index 47c82ec29238e3..b568a862f120ff 100644
--- a/fs/fuse/file_iomap.c
+++ b/fs/fuse/file_iomap.c
@@ -1540,7 +1540,12 @@ static bool fuse_iomap_revalidate(struct inode *inode,
return true;

validity_cookie = fuse_iext_read_seq(&fi->cache);
- return iomap->validity_cookie == validity_cookie;
+ if (unlikely(iomap->validity_cookie != validity_cookie)) {
+ trace_fuse_iomap_invalid(inode, iomap, validity_cookie);
+ return false;
+ }
+
+ return true;
}

static const struct iomap_write_ops fuse_iomap_write_ops = {