[PATCH 28/67] cachefiles: Trace truncations

From: David Howells
Date: Mon Oct 18 2021 - 10:58:05 EST


Add a tracepoint to trace truncation operations.

Signed-off-by: David Howells <dhowells@xxxxxxxxxx>
---

fs/cachefiles/interface.c | 9 +++++++-
include/trace/events/cachefiles.h | 40 +++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c
index 4edb3a09932a..8f98e5c27d66 100644
--- a/fs/cachefiles/interface.c
+++ b/fs/cachefiles/interface.c
@@ -341,9 +341,16 @@ static void cachefiles_invalidate_object(struct cachefiles_object *object)
ASSERT(d_is_reg(file->f_path.dentry));

cachefiles_begin_secure(cache, &saved_cred);
+ trace_cachefiles_trunc(object, file_inode(file),
+ i_size_read(file_inode(file)), 0,
+ cachefiles_trunc_invalidate);
ret = vfs_truncate(&file->f_path, 0);
- if (ret == 0)
+ if (ret == 0) {
+ trace_cachefiles_trunc(object, file_inode(file),
+ 0, ni_size,
+ cachefiles_trunc_set_size);
ret = vfs_truncate(&file->f_path, ni_size);
+ }
cachefiles_end_secure(cache, saved_cred);

if (ret != 0) {
diff --git a/include/trace/events/cachefiles.h b/include/trace/events/cachefiles.h
index 6e9f6462833d..09d76c160451 100644
--- a/include/trace/events/cachefiles.h
+++ b/include/trace/events/cachefiles.h
@@ -37,6 +37,11 @@ enum cachefiles_coherency_trace {
cachefiles_coherency_set_ok,
};

+enum cachefiles_trunc_trace {
+ cachefiles_trunc_invalidate,
+ cachefiles_trunc_set_size,
+};
+
#endif

/*
@@ -72,6 +77,10 @@ enum cachefiles_coherency_trace {
EM(cachefiles_coherency_set_fail, "SET fail") \
E_(cachefiles_coherency_set_ok, "SET ok ")

+#define cachefiles_trunc_traces \
+ EM(cachefiles_trunc_invalidate, "INVAL ") \
+ E_(cachefiles_trunc_set_size, "SETSIZ")
+
/*
* Export enum symbols via userspace.
*/
@@ -83,6 +92,7 @@ enum cachefiles_coherency_trace {
cachefiles_obj_kill_traces;
cachefiles_obj_ref_traces;
cachefiles_coherency_traces;
+cachefiles_trunc_traces;

/*
* Now redefine the EM() and E_() macros to map the enums to the strings that
@@ -292,6 +302,36 @@ TRACE_EVENT(cachefiles_coherency,
__entry->content)
);

+TRACE_EVENT(cachefiles_trunc,
+ TP_PROTO(struct cachefiles_object *obj, struct inode *backer,
+ loff_t from, loff_t to, enum cachefiles_trunc_trace why),
+
+ TP_ARGS(obj, backer, from, to, why),
+
+ TP_STRUCT__entry(
+ __field(unsigned int, obj )
+ __field(unsigned int, backer )
+ __field(enum cachefiles_trunc_trace, why )
+ __field(loff_t, from )
+ __field(loff_t, to )
+ ),
+
+ TP_fast_assign(
+ __entry->obj = obj->debug_id;
+ __entry->backer = backer->i_ino;
+ __entry->from = from;
+ __entry->to = to;
+ __entry->why = why;
+ ),
+
+ TP_printk("o=%08x b=%08x %s l=%llx->%llx",
+ __entry->obj,
+ __entry->backer,
+ __print_symbolic(__entry->why, cachefiles_trunc_traces),
+ __entry->from,
+ __entry->to)
+ );
+
#endif /* _TRACE_CACHEFILES_H */

/* This part must be outside protection */