xref: /openbmc/linux/include/trace/events/filelock.h (revision 82e6fdd6)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Events for filesystem locks
4  *
5  * Copyright 2013 Jeff Layton <jlayton@poochiereds.net>
6  */
7 #undef TRACE_SYSTEM
8 #define TRACE_SYSTEM filelock
9 
10 #if !defined(_TRACE_FILELOCK_H) || defined(TRACE_HEADER_MULTI_READ)
11 #define _TRACE_FILELOCK_H
12 
13 #include <linux/tracepoint.h>
14 #include <linux/fs.h>
15 #include <linux/device.h>
16 #include <linux/kdev_t.h>
17 
18 #define show_fl_flags(val)						\
19 	__print_flags(val, "|", 					\
20 		{ FL_POSIX,		"FL_POSIX" },			\
21 		{ FL_FLOCK,		"FL_FLOCK" },			\
22 		{ FL_DELEG,		"FL_DELEG" },			\
23 		{ FL_ACCESS,		"FL_ACCESS" },			\
24 		{ FL_EXISTS,		"FL_EXISTS" },			\
25 		{ FL_LEASE,		"FL_LEASE" },			\
26 		{ FL_CLOSE,		"FL_CLOSE" },			\
27 		{ FL_SLEEP,		"FL_SLEEP" },			\
28 		{ FL_DOWNGRADE_PENDING,	"FL_DOWNGRADE_PENDING" },	\
29 		{ FL_UNLOCK_PENDING,	"FL_UNLOCK_PENDING" },		\
30 		{ FL_OFDLCK,		"FL_OFDLCK" })
31 
32 #define show_fl_type(val)				\
33 	__print_symbolic(val,				\
34 			{ F_RDLCK, "F_RDLCK" },		\
35 			{ F_WRLCK, "F_WRLCK" },		\
36 			{ F_UNLCK, "F_UNLCK" })
37 
38 TRACE_EVENT(locks_get_lock_context,
39 	TP_PROTO(struct inode *inode, int type, struct file_lock_context *ctx),
40 
41 	TP_ARGS(inode, type, ctx),
42 
43 	TP_STRUCT__entry(
44 		__field(unsigned long, i_ino)
45 		__field(dev_t, s_dev)
46 		__field(unsigned char, type)
47 		__field(struct file_lock_context *, ctx)
48 	),
49 
50 	TP_fast_assign(
51 		__entry->s_dev = inode->i_sb->s_dev;
52 		__entry->i_ino = inode->i_ino;
53 		__entry->type = type;
54 		__entry->ctx = ctx;
55 	),
56 
57 	TP_printk("dev=0x%x:0x%x ino=0x%lx type=%s ctx=%p",
58 		  MAJOR(__entry->s_dev), MINOR(__entry->s_dev),
59 		  __entry->i_ino, show_fl_type(__entry->type), __entry->ctx)
60 );
61 
62 DECLARE_EVENT_CLASS(filelock_lock,
63 	TP_PROTO(struct inode *inode, struct file_lock *fl, int ret),
64 
65 	TP_ARGS(inode, fl, ret),
66 
67 	TP_STRUCT__entry(
68 		__field(struct file_lock *, fl)
69 		__field(unsigned long, i_ino)
70 		__field(dev_t, s_dev)
71 		__field(struct file_lock *, fl_next)
72 		__field(fl_owner_t, fl_owner)
73 		__field(unsigned int, fl_pid)
74 		__field(unsigned int, fl_flags)
75 		__field(unsigned char, fl_type)
76 		__field(loff_t, fl_start)
77 		__field(loff_t, fl_end)
78 		__field(int, ret)
79 	),
80 
81 	TP_fast_assign(
82 		__entry->fl = fl ? fl : NULL;
83 		__entry->s_dev = inode->i_sb->s_dev;
84 		__entry->i_ino = inode->i_ino;
85 		__entry->fl_next = fl ? fl->fl_next : NULL;
86 		__entry->fl_owner = fl ? fl->fl_owner : NULL;
87 		__entry->fl_pid = fl ? fl->fl_pid : 0;
88 		__entry->fl_flags = fl ? fl->fl_flags : 0;
89 		__entry->fl_type = fl ? fl->fl_type : 0;
90 		__entry->fl_start = fl ? fl->fl_start : 0;
91 		__entry->fl_end = fl ? fl->fl_end : 0;
92 		__entry->ret = ret;
93 	),
94 
95 	TP_printk("fl=0x%p dev=0x%x:0x%x ino=0x%lx fl_next=0x%p fl_owner=0x%p fl_pid=%u fl_flags=%s fl_type=%s fl_start=%lld fl_end=%lld ret=%d",
96 		__entry->fl, MAJOR(__entry->s_dev), MINOR(__entry->s_dev),
97 		__entry->i_ino, __entry->fl_next, __entry->fl_owner,
98 		__entry->fl_pid, show_fl_flags(__entry->fl_flags),
99 		show_fl_type(__entry->fl_type),
100 		__entry->fl_start, __entry->fl_end, __entry->ret)
101 );
102 
103 DEFINE_EVENT(filelock_lock, posix_lock_inode,
104 		TP_PROTO(struct inode *inode, struct file_lock *fl, int ret),
105 		TP_ARGS(inode, fl, ret));
106 
107 DEFINE_EVENT(filelock_lock, fcntl_setlk,
108 		TP_PROTO(struct inode *inode, struct file_lock *fl, int ret),
109 		TP_ARGS(inode, fl, ret));
110 
111 DEFINE_EVENT(filelock_lock, locks_remove_posix,
112 		TP_PROTO(struct inode *inode, struct file_lock *fl, int ret),
113 		TP_ARGS(inode, fl, ret));
114 
115 DECLARE_EVENT_CLASS(filelock_lease,
116 
117 	TP_PROTO(struct inode *inode, struct file_lock *fl),
118 
119 	TP_ARGS(inode, fl),
120 
121 	TP_STRUCT__entry(
122 		__field(struct file_lock *, fl)
123 		__field(unsigned long, i_ino)
124 		__field(dev_t, s_dev)
125 		__field(struct file_lock *, fl_next)
126 		__field(fl_owner_t, fl_owner)
127 		__field(unsigned int, fl_flags)
128 		__field(unsigned char, fl_type)
129 		__field(unsigned long, fl_break_time)
130 		__field(unsigned long, fl_downgrade_time)
131 	),
132 
133 	TP_fast_assign(
134 		__entry->fl = fl ? fl : NULL;
135 		__entry->s_dev = inode->i_sb->s_dev;
136 		__entry->i_ino = inode->i_ino;
137 		__entry->fl_next = fl ? fl->fl_next : NULL;
138 		__entry->fl_owner = fl ? fl->fl_owner : NULL;
139 		__entry->fl_flags = fl ? fl->fl_flags : 0;
140 		__entry->fl_type = fl ? fl->fl_type : 0;
141 		__entry->fl_break_time = fl ? fl->fl_break_time : 0;
142 		__entry->fl_downgrade_time = fl ? fl->fl_downgrade_time : 0;
143 	),
144 
145 	TP_printk("fl=0x%p dev=0x%x:0x%x ino=0x%lx fl_next=0x%p fl_owner=0x%p fl_flags=%s fl_type=%s fl_break_time=%lu fl_downgrade_time=%lu",
146 		__entry->fl, MAJOR(__entry->s_dev), MINOR(__entry->s_dev),
147 		__entry->i_ino, __entry->fl_next, __entry->fl_owner,
148 		show_fl_flags(__entry->fl_flags),
149 		show_fl_type(__entry->fl_type),
150 		__entry->fl_break_time, __entry->fl_downgrade_time)
151 );
152 
153 DEFINE_EVENT(filelock_lease, break_lease_noblock, TP_PROTO(struct inode *inode, struct file_lock *fl),
154 		TP_ARGS(inode, fl));
155 
156 DEFINE_EVENT(filelock_lease, break_lease_block, TP_PROTO(struct inode *inode, struct file_lock *fl),
157 		TP_ARGS(inode, fl));
158 
159 DEFINE_EVENT(filelock_lease, break_lease_unblock, TP_PROTO(struct inode *inode, struct file_lock *fl),
160 		TP_ARGS(inode, fl));
161 
162 DEFINE_EVENT(filelock_lease, generic_delete_lease, TP_PROTO(struct inode *inode, struct file_lock *fl),
163 		TP_ARGS(inode, fl));
164 
165 DEFINE_EVENT(filelock_lease, time_out_leases, TP_PROTO(struct inode *inode, struct file_lock *fl),
166 		TP_ARGS(inode, fl));
167 
168 TRACE_EVENT(generic_add_lease,
169 	TP_PROTO(struct inode *inode, struct file_lock *fl),
170 
171 	TP_ARGS(inode, fl),
172 
173 	TP_STRUCT__entry(
174 		__field(unsigned long, i_ino)
175 		__field(int, wcount)
176 		__field(int, dcount)
177 		__field(int, icount)
178 		__field(dev_t, s_dev)
179 		__field(fl_owner_t, fl_owner)
180 		__field(unsigned int, fl_flags)
181 		__field(unsigned char, fl_type)
182 	),
183 
184 	TP_fast_assign(
185 		__entry->s_dev = inode->i_sb->s_dev;
186 		__entry->i_ino = inode->i_ino;
187 		__entry->wcount = atomic_read(&inode->i_writecount);
188 		__entry->dcount = d_count(fl->fl_file->f_path.dentry);
189 		__entry->icount = atomic_read(&inode->i_count);
190 		__entry->fl_owner = fl ? fl->fl_owner : NULL;
191 		__entry->fl_flags = fl ? fl->fl_flags : 0;
192 		__entry->fl_type = fl ? fl->fl_type : 0;
193 	),
194 
195 	TP_printk("dev=0x%x:0x%x ino=0x%lx wcount=%d dcount=%d icount=%d fl_owner=0x%p fl_flags=%s fl_type=%s",
196 		MAJOR(__entry->s_dev), MINOR(__entry->s_dev),
197 		__entry->i_ino, __entry->wcount, __entry->dcount,
198 		__entry->icount, __entry->fl_owner,
199 		show_fl_flags(__entry->fl_flags),
200 		show_fl_type(__entry->fl_type))
201 );
202 
203 #endif /* _TRACE_FILELOCK_H */
204 
205 /* This part must be outside protection */
206 #include <trace/define_trace.h>
207