cachefiles: Add a couple of tracepoints for logging errors
authorDavid Howells <dhowells@redhat.com>
Thu, 21 Oct 2021 07:42:18 +0000 (08:42 +0100)
committerDavid Howells <dhowells@redhat.com>
Fri, 7 Jan 2022 13:41:01 +0000 (13:41 +0000)
Add two trace points to log errors, one for vfs operations like mkdir or
create, and one for I/O operations, like read, write or truncate.

Also add the beginnings of a struct that is going to represent a data file
and place a debugging ID in it for the tracepoints to record.

Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
cc: linux-cachefs@redhat.com
Link: https://lore.kernel.org/r/163819625632.215744.17907340966178411033.stgit@warthog.procyon.org.uk/
Link: https://lore.kernel.org/r/163906926297.143852.18267924605548658911.stgit@warthog.procyon.org.uk/
Link: https://lore.kernel.org/r/163967135390.1823006.2512120406360156424.stgit@warthog.procyon.org.uk/
Link: https://lore.kernel.org/r/164021534029.640689.1875723624947577095.stgit@warthog.procyon.org.uk/
fs/cachefiles/internal.h
include/trace/events/cachefiles.h

index 1f2fea9..b51146a 100644 (file)
@@ -62,6 +62,7 @@ struct cachefiles_cache {
        char                            *tag;           /* cache binding tag */
 };
 
+#include <trace/events/cachefiles.h>
 
 /*
  * error_inject.c
index 5ee0aab..9bd5a8a 100644 (file)
 #ifndef __CACHEFILES_DECLARE_TRACE_ENUMS_ONCE_ONLY
 #define __CACHEFILES_DECLARE_TRACE_ENUMS_ONCE_ONLY
 
+enum cachefiles_error_trace {
+       cachefiles_trace_fallocate_error,
+       cachefiles_trace_getxattr_error,
+       cachefiles_trace_link_error,
+       cachefiles_trace_lookup_error,
+       cachefiles_trace_mkdir_error,
+       cachefiles_trace_notify_change_error,
+       cachefiles_trace_open_error,
+       cachefiles_trace_read_error,
+       cachefiles_trace_remxattr_error,
+       cachefiles_trace_rename_error,
+       cachefiles_trace_seek_error,
+       cachefiles_trace_setxattr_error,
+       cachefiles_trace_statfs_error,
+       cachefiles_trace_tmpfile_error,
+       cachefiles_trace_trunc_error,
+       cachefiles_trace_unlink_error,
+       cachefiles_trace_write_error,
+};
+
 #endif
 
 /*
  * Define enum -> string mappings for display.
  */
+#define cachefiles_error_traces                                                \
+       EM(cachefiles_trace_fallocate_error,    "fallocate")            \
+       EM(cachefiles_trace_getxattr_error,     "getxattr")             \
+       EM(cachefiles_trace_link_error,         "link")                 \
+       EM(cachefiles_trace_lookup_error,       "lookup")               \
+       EM(cachefiles_trace_mkdir_error,        "mkdir")                \
+       EM(cachefiles_trace_notify_change_error, "notify_change")       \
+       EM(cachefiles_trace_open_error,         "open")                 \
+       EM(cachefiles_trace_read_error,         "read")                 \
+       EM(cachefiles_trace_remxattr_error,     "remxattr")             \
+       EM(cachefiles_trace_rename_error,       "rename")               \
+       EM(cachefiles_trace_seek_error,         "seek")                 \
+       EM(cachefiles_trace_setxattr_error,     "setxattr")             \
+       EM(cachefiles_trace_statfs_error,       "statfs")               \
+       EM(cachefiles_trace_tmpfile_error,      "tmpfile")              \
+       EM(cachefiles_trace_trunc_error,        "trunc")                \
+       EM(cachefiles_trace_unlink_error,       "unlink")               \
+       E_(cachefiles_trace_write_error,        "write")
 
 
 /*
@@ -33,6 +71,8 @@
 #define EM(a, b) TRACE_DEFINE_ENUM(a);
 #define E_(a, b) TRACE_DEFINE_ENUM(a);
 
+cachefiles_error_traces;
+
 /*
  * Now redefine the EM() and E_() macros to map the enums to the strings that
  * will be printed in the output.
 #define E_(a, b)       { a, b }
 
 
+TRACE_EVENT(cachefiles_vfs_error,
+           TP_PROTO(struct cachefiles_object *obj, struct inode *backer,
+                    int error, enum cachefiles_error_trace where),
+
+           TP_ARGS(obj, backer, error, where),
+
+           TP_STRUCT__entry(
+                   __field(unsigned int,                       obj     )
+                   __field(unsigned int,                       backer  )
+                   __field(enum cachefiles_error_trace,        where   )
+                   __field(short,                              error   )
+                            ),
+
+           TP_fast_assign(
+                   __entry->obj        = obj ? obj->debug_id : 0;
+                   __entry->backer     = backer->i_ino;
+                   __entry->error      = error;
+                   __entry->where      = where;
+                          ),
+
+           TP_printk("o=%08x b=%08x %s e=%d",
+                     __entry->obj,
+                     __entry->backer,
+                     __print_symbolic(__entry->where, cachefiles_error_traces),
+                     __entry->error)
+           );
+
+TRACE_EVENT(cachefiles_io_error,
+           TP_PROTO(struct cachefiles_object *obj, struct inode *backer,
+                    int error, enum cachefiles_error_trace where),
+
+           TP_ARGS(obj, backer, error, where),
+
+           TP_STRUCT__entry(
+                   __field(unsigned int,                       obj     )
+                   __field(unsigned int,                       backer  )
+                   __field(enum cachefiles_error_trace,        where   )
+                   __field(short,                              error   )
+                            ),
+
+           TP_fast_assign(
+                   __entry->obj        = obj ? obj->debug_id : 0;
+                   __entry->backer     = backer->i_ino;
+                   __entry->error      = error;
+                   __entry->where      = where;
+                          ),
+
+           TP_printk("o=%08x b=%08x %s e=%d",
+                     __entry->obj,
+                     __entry->backer,
+                     __print_symbolic(__entry->where, cachefiles_error_traces),
+                     __entry->error)
+           );
+
 #endif /* _TRACE_CACHEFILES_H */
 
 /* This part must be outside protection */