[PATCH 08/10] fuse_trace: enable iomap cache management

Darrick J. Wong
2025-09-16T00:40:29Z

Add tracepoints for the previous patch.

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

diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index 1cfcc64de08817..202fc32f6b02e1 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -401,6 +401,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_NOCACHE, "nocache" }, \
{ FUSE_IOMAP_TYPE_HOLE, "hole" }, \
{ FUSE_IOMAP_TYPE_DELALLOC, "delalloc" }, \
{ FUSE_IOMAP_TYPE_MAPPED, "mapped" }, \
@@ -742,6 +743,7 @@ DEFINE_EVENT(fuse_inode_state_class, name, \
TP_ARGS(inode))
DEFINE_FUSE_INODE_STATE_EVENT(fuse_iomap_init_inode);
DEFINE_FUSE_INODE_STATE_EVENT(fuse_iomap_evict_inode);
+DEFINE_FUSE_INODE_STATE_EVENT(fuse_iomap_cache_enable);

TRACE_EVENT(fuse_iomap_fiemap,
TP_PROTO(const struct inode *inode, u64 start, u64 count,
@@ -1542,6 +1544,72 @@ TRACE_EVENT(fuse_iomap_invalid,
__entry->old_validity_cookie,
__entry->validity_cookie)
);
+
+TRACE_EVENT(fuse_iomap_upsert,
+ TP_PROTO(const struct inode *inode,
+ const struct fuse_iomap_upsert_out *outarg),
+ TP_ARGS(inode, outarg),
+
+ TP_STRUCT__entry(
+ FUSE_INODE_FIELDS
+ __field(uint64_t, attr_ino)
+
+ FUSE_IOMAP_MAP_FIELDS(read)
+ FUSE_IOMAP_MAP_FIELDS(write)
+ ),
+
+ TP_fast_assign(
+ FUSE_INODE_ASSIGN(inode, fi, fm);
+ __entry->attr_ino = outarg->attr_ino;
+ __entry->readoffset = outarg->read.offset;
+ __entry->readlength = outarg->read.length;
+ __entry->readaddr = outarg->read.addr;
+ __entry->readtype = outarg->read.type;
+ __entry->readflags = outarg->read.flags;
+ __entry->readdev = outarg->read.dev;
+ __entry->writeoffset = outarg->write.offset;
+ __entry->writelength = outarg->write.length;
+ __entry->writeaddr = outarg->write.addr;
+ __entry->writetype = outarg->write.type;
+ __entry->writeflags = outarg->write.flags;
+ __entry->writedev = outarg->write.dev;
+ ),
+
+ TP_printk(FUSE_INODE_FMT " attr_ino 0x%llx" FUSE_IOMAP_MAP_FMT("read") FUSE_IOMAP_MAP_FMT("write"),
+ FUSE_INODE_PRINTK_ARGS,
+ __entry->attr_ino,
+ FUSE_IOMAP_MAP_PRINTK_ARGS(read),
+ FUSE_IOMAP_MAP_PRINTK_ARGS(write))
+);
+
+TRACE_EVENT(fuse_iomap_inval,
+ TP_PROTO(const struct inode *inode,
+ const struct fuse_iomap_inval_out *outarg),
+ TP_ARGS(inode, outarg),
+
+ TP_STRUCT__entry(
+ FUSE_INODE_FIELDS
+ __field(uint64_t, attr_ino)
+
+ FUSE_FILE_RANGE_FIELDS(read)
+ FUSE_FILE_RANGE_FIELDS(write)
+ ),
+
+ TP_fast_assign(
+ FUSE_INODE_ASSIGN(inode, fi, fm);
+ __entry->attr_ino = outarg->attr_ino;
+ __entry->readoffset = outarg->read_offset;
+ __entry->readlength = outarg->read_length;
+ __entry->writeoffset = outarg->write_offset;
+ __entry->writelength = outarg->write_length;
+ ),
+
+ TP_printk(FUSE_INODE_FMT " attr_ino 0x%llx" FUSE_FILE_RANGE_FMT("read") FUSE_FILE_RANGE_FMT("write"),
+ FUSE_INODE_PRINTK_ARGS,
+ __entry->attr_ino,
+ FUSE_FILE_RANGE_PRINTK_ARGS(read),
+ FUSE_FILE_RANGE_PRINTK_ARGS(write))
+);
#endif /* CONFIG_FUSE_IOMAP */

#endif /* _TRACE_FUSE_H */
diff --git a/fs/fuse/file_iomap.c b/fs/fuse/file_iomap.c
index ff79a30f6ff8d2..c82434674fb52b 100644
--- a/fs/fuse/file_iomap.c
+++ b/fs/fuse/file_iomap.c
@@ -2557,6 +2557,8 @@ int fuse_iomap_upsert(struct fuse_conn *fc,
goto out_sb;
}

+ trace_fuse_iomap_upsert(inode, outarg);
+
fi = get_fuse_inode(inode);
if (BAD_DATA(fi->orig_ino != outarg->attr_ino)) {
ret = -EINVAL;
@@ -2574,7 +2576,8 @@ int fuse_iomap_upsert(struct fuse_conn *fc,

fuse_iomap_cache_lock(inode);

- set_bit(FUSE_I_IOMAP_CACHE, &fi->state);
+ if (!test_and_set_bit(FUSE_I_IOMAP_CACHE, &fi->state))
+ trace_fuse_iomap_cache_enable(inode);

if (outarg->read.type != FUSE_IOMAP_TYPE_NOCACHE) {
ret = fuse_iomap_cache_upsert(inode, READ_MAPPING,
@@ -2638,6 +2641,8 @@ int fuse_iomap_inval(struct fuse_conn *fc,
goto out_sb;
}

+ trace_fuse_iomap_inval(inode, outarg);
+
fi = get_fuse_inode(inode);
if (BAD_DATA(fi->orig_ino != outarg->attr_ino)) {
ret = -EINVAL;