[PATCH 06/10] fuse_trace: invalidate iomap cache after file updates

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

Add tracepoints for the previous patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
fs/fuse/fuse_trace.h | 37 +++++++++++++++++++++++++++++++++++++
fs/fuse/file_iomap.c | 4 ++++
fs/fuse/iomap_cache.c | 2 ++
3 files changed, 43 insertions(+)

diff --git a/fs/fuse/fuse_trace.h b/fs/fuse/fuse_trace.h
index 5f399b1604a2ac..1cfcc64de08817 100644
--- a/fs/fuse/fuse_trace.h
+++ b/fs/fuse/fuse_trace.h
@@ -1073,6 +1073,7 @@ DEFINE_FUSE_IOMAP_FILE_RANGE_EVENT(fuse_iomap_truncate_down);
DEFINE_FUSE_IOMAP_FILE_RANGE_EVENT(fuse_iomap_punch_range);
DEFINE_FUSE_IOMAP_FILE_RANGE_EVENT(fuse_iomap_setsize);
DEFINE_FUSE_IOMAP_FILE_RANGE_EVENT(fuse_iomap_flush_unmap_range);
+DEFINE_FUSE_IOMAP_FILE_RANGE_EVENT(fuse_iomap_cache_invalidate_range);

TRACE_EVENT(fuse_iomap_fallocate,
TP_PROTO(const struct inode *inode, int mode, loff_t offset,
@@ -1210,6 +1211,42 @@ DEFINE_FUSE_IOMAP_INLINE_EVENT(fuse_iomap_inline_write);
DEFINE_FUSE_IOMAP_INLINE_EVENT(fuse_iomap_set_inline_iomap);
DEFINE_FUSE_IOMAP_INLINE_EVENT(fuse_iomap_set_inline_srcmap);

+TRACE_EVENT(fuse_iomap_open_truncate,
+ TP_PROTO(const struct inode *inode),
+
+ TP_ARGS(inode),
+
+ TP_STRUCT__entry(
+ FUSE_INODE_FIELDS
+ ),
+
+ TP_fast_assign(
+ FUSE_INODE_ASSIGN(inode, fi, fm);
+ ),
+
+ TP_printk(FUSE_INODE_FMT,
+ FUSE_INODE_PRINTK_ARGS)
+);
+
+TRACE_EVENT(fuse_iomap_copied_file_range,
+ TP_PROTO(const struct inode *inode, loff_t offset,
+ size_t written),
+ TP_ARGS(inode, offset, written),
+
+ TP_STRUCT__entry(
+ FUSE_IO_RANGE_FIELDS()
+ ),
+
+ TP_fast_assign(
+ FUSE_INODE_ASSIGN(inode, fi, fm);
+ __entry->offset = offset;
+ __entry->length = written;
+ ),
+
+ TP_printk(FUSE_IO_RANGE_FMT(),
+ FUSE_IO_RANGE_PRINTK_ARGS())
+);
+
DECLARE_EVENT_CLASS(fuse_iext_class,
TP_PROTO(const struct inode *inode, const struct fuse_iext_cursor *cur,
int state, unsigned long caller_ip),
diff --git a/fs/fuse/file_iomap.c b/fs/fuse/file_iomap.c
index b410cae0dec5dd..c7b0026bff75f3 100644
--- a/fs/fuse/file_iomap.c
+++ b/fs/fuse/file_iomap.c
@@ -2433,6 +2433,8 @@ void fuse_iomap_open_truncate(struct inode *inode)
{
ASSERT(fuse_inode_has_iomap(inode));

+ trace_fuse_iomap_open_truncate(inode);
+
fuse_iomap_cache_invalidate(inode, 0);
}

@@ -2441,5 +2443,7 @@ void fuse_iomap_copied_file_range(struct inode *inode, loff_t offset,
{
ASSERT(fuse_inode_has_iomap(inode));

+ trace_fuse_iomap_copied_file_range(inode, offset, written);
+
fuse_iomap_cache_invalidate_range(inode, offset, written);
}
diff --git a/fs/fuse/iomap_cache.c b/fs/fuse/iomap_cache.c
index f1be73da571440..a13eb5eec72415 100644
--- a/fs/fuse/iomap_cache.c
+++ b/fs/fuse/iomap_cache.c
@@ -1422,6 +1422,8 @@ int fuse_iomap_cache_invalidate_range(struct inode *inode, loff_t offset,
if (!fuse_inode_caches_iomaps(inode))
return 0;

+ trace_fuse_iomap_cache_invalidate_range(inode, offset, length);
+
aligned_offset = round_down(offset, blocksize);
if (length != FUSE_IOMAP_INVAL_TO_EOF) {
length += offset - aligned_offset;