Debian Codegraph @

tapset/linux/rpc.stp

raw
1 // rpc tapset
2 // Copyright (C) 2006 IBM Corp.
3 // Copyright (C) 2007 Bull S.A.S
4 // Copyright (C) 2008, 2010-2014 Red Hat
5 //
6 // This file is part of systemtap, and is free software. You can
7 // redistribute it and/or modify it under the terms of the GNU General
8 // Public License (GPL); either version 2, or (at your option) any
9 // later version.
10
11 %{
12 // Includes everything needed for __rpc_prot_from_protocol().
13 #include <linux/sunrpc/clnt.h>
14 %}
15
16 probe sunrpc.entry =
17 sunrpc.clnt.entry,
18 sunrpc.svc.entry,
19 sunrpc.sched.entry
20 {}
21
22 probe sunrpc.return =
23 sunrpc.clnt.return,
24 sunrpc.svc.return,
25 sunrpc.sched.return
26 {}
27
28 /******************************************************************
29 * Probe points on RPC client functions *
30 ******************************************************************/
31
32 probe sunrpc.clnt.entry =
33 sunrpc.clnt.create_client,
34 sunrpc.clnt.clone_client,
35 sunrpc.clnt.bind_new_program,
36 sunrpc.clnt.shutdown_client,
37 sunrpc.clnt.call_sync,
38 sunrpc.clnt.call_async,
39 sunrpc.clnt.restart_call
40 {}
41
42 probe sunrpc.clnt.return =
43 sunrpc.clnt.create_client.return,
44 sunrpc.clnt.clone_client.return,
45 sunrpc.clnt.bind_new_program.return,
46 sunrpc.clnt.shutdown_client.return,
47 sunrpc.clnt.call_sync.return,
48 sunrpc.clnt.call_async.return,
49 sunrpc.clnt.restart_call.return
50 {}
51
52 /*
53 * Fires when an RPC client is to be created
54 *
55 * kernels > 2.6.18
56 *
57 * struct rpc_clnt *
58 * rpc_create(struct rpc_create_args *args)
59 * The rpc_create() function is used to create an RPC client. It
60 * calculates some arguments (such as args->servername), then
61 * calls rpc_new_client(). We need the calculated arguments, so
62 * we'll probe rpc_new_client(). But, see discussion of
63 * sunrpc.clnt.create_client.return below.
64 *
65 * static struct rpc_clnt *
66 * rpc_new_client(const struct rpc_create_args *args, struct rpc_xprt *xprt)
67 *
68 * kernels <= 2.6.18
69 *
70 * static struct rpc_clnt *
71 * rpc_new_client(struct rpc_xprt *xprt, char *servname,
72 * struct rpc_program *program, u32 vers,
73 * rpc_authflavor_t flavor)
74 *
75 * struct rpc_clnt *
76 * rpc_create_client(struct rpc_xprt *xprt, char *servname,
77 * struct rpc_program *info, u32 version,
78 * rpc_authflavor_t authflavor)
79 */
80
81 /**
82 * probe sunrpc.clnt.create_client - Create an RPC client
83 *
84 * @servername: the server machine name
85 * @progname: the RPC program name
86 * @prog: the RPC program number
87 * @vers: the RPC program version number
88 * @prot: the IP protocol number
89 * @port: the port number
90 * @authflavor: the authentication flavor
91 */
92 probe sunrpc.clnt.create_client =
93 _sunrpc.clnt.create_client.rpc_new_client_inline !,
94 _sunrpc.clnt.create_client.rpc_new_client ?,
95 _sunrpc.clnt.create_client.rpc_create_client ?
96 {
97 name = "sunrpc.clnt.create_client"
98 argstr = sprintf("%s %s %d %d %d %d %d", servername, progname,
99 prog, vers, prot, port, authflavor)
100 }
101
102 /*
103 * Newer kernels (> 2.6.18) compiled with gcc less than version
104 * 4.4.3-16, tend to have debuginfo that doesn't include location
105 * information for inline function arguments. This is a problem, since
106 * we need the arguments to rpc_new_client(), which is inline. Since
107 * we can't get them for those kernels, we stash (and delete) the value
108 * of the 'args' parameter of rpc_create(). We then use this value
109 * when probing the inline version of rpc_new_client() (if we don't
110 * have the real arguments to that inline function).
111 */
112
113 @__private30 global __rpc_create_args
114
115 probe kernel.function("rpc_create").call !,
116 module("sunrpc").function("rpc_create").call ?
117 {
118 __rpc_create_args[tid()] = $args
119 }
120
121 probe kernel.function("rpc_create").return !,
122 module("sunrpc").function("rpc_create").return ?
123 {
124 delete __rpc_create_args[tid()]
125 }
126
127
128 /*
129 * This function could be written in script language, but we'd need
130 * embedded-C functions for XPRT_TRANSPORT_{UDP,TCP,BC_TCP} and
131 * IPPROTO_{UDP,TCP}. So, do it all in embedded-C.
132 */
133
134 @__private30 function __rpc_prot_from_protocol:long(protocol:long)
135 %{
136 switch (STAP_ARG_protocol) {
137 #ifdef XPRT_TRANSPORT_BC
138 case XPRT_TRANSPORT_UDP:
139 STAP_RETVALUE = IPPROTO_UDP;
140 break;
141 case XPRT_TRANSPORT_TCP:
142 case XPRT_TRANSPORT_BC_TCP:
143 STAP_RETVALUE = IPPROTO_TCP;
144 break;
145 #endif
146 default:
147 STAP_RETVALUE = -1;
148 break;
149 }
150 %}
151
152 /*
153 * The probe for the inline version of "rpc_new_client" (kernels >
154 * 2.6.18) and the non-inline version of "rpc_new_client" (kernels <=
155 * 2.6.18) could be combined. However, the optimizer isn't smart
156 * enough to optimize away the '__rpc_create_args' global then.
157 */
158
159 probe _sunrpc.clnt.create_client.rpc_new_client_inline =
160 kernel.function("rpc_new_client").inline !,
161 module("sunrpc").function("rpc_new_client").inline
162 {
163 if (@defined($args)) { # kernel > 2.6.18 (with good debuginfo)
164 %(systemtap_v <= "1.7" %?
165 args = $args
166 %)
167 __args = $args
168 servername = __rpc_format_servername($args->servername,
169 $args->address)
170 progname = kernel_string($args->program->name)
171 prog = $args->prognumber
172 vers = vers_from_prog($args->program, $args->version)
173 authflavor = $args->authflavor
174
175 prot = $xprt->prot
176 port = @choose_defined($xprt->port, port_from_xprt($xprt))
177 }
178 else { # kernel > 2.6.18 (with bad debuginfo)
179 %(systemtap_v <= "1.7" %?
180 args = __rpc_create_args[tid()]
181 %)
182 __args = __rpc_create_args[tid()]
183 servername = __rpc_format_servername(@cast(__args, "rpc_create_args", "kernel:sunrpc")->servername,
184 @cast(__args, "rpc_create_args", "kernel:sunrpc")->address)
185
186 progname = kernel_string(@cast(__args, "rpc_create_args", "kernel:sunrpc")->program->name)
187 prog = @cast(__args, "rpc_create_args", "kernel:sunrpc")->prognumber
188 vers = vers_from_prog(@cast(__args, "rpc_create_args", "kernel:sunrpc")->program, @cast(__args, "rpc_create_args", "kernel:sunrpc")->version)
189 authflavor = @cast(__args, "rpc_create_args", "kernel:sunrpc")->authflavor
190
191 prot = __rpc_prot_from_protocol(@cast(__args, "rpc_create_args", "kernel:sunrpc")->protocol)
192 # Since we can't find $xprt, we can't know the port
193 port = -1
194 }
195 }
196
197 probe _sunrpc.clnt.create_client.rpc_new_client =
198 kernel.function("rpc_new_client").call !,
199 module("sunrpc").function("rpc_new_client").call ?
200 {
201 if (@defined($args)) {
202 # kernel > 2.6.18
203 servername = __rpc_format_servername($args->servername,
204 $args->address)
205 progname = kernel_string($args->program->name)
206 prog = $args->prognumber
207 vers = vers_from_prog($args->program, $args->version)
208 authflavor = $args->authflavor
209 }
210 else {
211 # kernel <= 2.6.18
212 servername = __rpc_format_servername($servname, &$xprt->addr)
213 progname = kernel_string($program->name)
214 prog = $program->number
215 vers = vers_from_prog($program, $vers)
216 authflavor = $flavor
217 }
218
219 prot = $xprt->prot
220 port = @choose_defined($xprt->port, port_from_xprt($xprt))
221 }
222
223 probe _sunrpc.clnt.create_client.rpc_create_client =
224 kernel.function("rpc_create_client") !,
225 module("sunrpc").function("rpc_create_client") ?
226 {
227 servername = __rpc_format_servername($servname, &$xprt->addr)
228 if (@defined($info)) {
229 progname = kernel_string($info->name)
230 prog = $info->number
231 vers = vers_from_prog($info, $version)
232 authflavor = $authflavor
233 }
234 else {
235 progname = kernel_string($program->name)
236 prog = $program->number
237 vers = vers_from_prog($program, $vers)
238 authflavor = $flavor
239 }
240
241 prot = $xprt->prot
242 port = @choose_defined($xprt->port, port_from_xprt($xprt))
243 }
244
245 /*
246 * On newer kernels, we want to probe the return of rpc_new_client()
247 * here. But because of problems with return probes on inline
248 * functions (PR 4413), we have to probe the return of rpc_create()
249 * instead. So, if we find the return of rpc_create() (the only
250 * caller of rpc_new_client()), we're done.
251 */
252 probe sunrpc.clnt.create_client.return =
253 _sunrpc.clnt.create_client.return.rpc_create !,
254 _sunrpc.clnt.create_client.return.rpc_new_client ?,
255 _sunrpc.clnt.create_client.return.rpc_create_client ?
256 {
257 name = "sunrpc.clnt.create_client.return"
258 retstr = return_str(2, $return)
259 }
260
261 probe _sunrpc.clnt.create_client.return.rpc_create =
262 kernel.function("rpc_create").return !,
263 module("sunrpc").function("rpc_create").return
264 {
265 }
266
267 probe _sunrpc.clnt.create_client.return.rpc_new_client =
268 kernel.function("rpc_new_client").return !,
269 module("sunrpc").function("rpc_new_client").return ?
270 {
271 }
272
273 probe _sunrpc.clnt.create_client.return.rpc_create_client =
274 kernel.function("rpc_create_client").return !,
275 module("sunrpc").function("rpc_create_client").return ?
276 {
277 }
278
279 /**
280 * probe sunrpc.clnt.clone_client - Clone an RPC client structure
281 *
282 * @servername: the server machine name
283 * @progname: the RPC program name
284 * @prog: the RPC program number
285 * @vers: the RPC program version number
286 * @prot: the IP protocol number
287 * @port: the port number
288 * @authflavor: the authentication flavor
289 */
290 probe sunrpc.clnt.clone_client = kernel.function("rpc_clone_client") !,
291 module("sunrpc").function("rpc_clone_client")
292 {
293 if (@defined($clnt->cl_server))
294 servername = __rpc_format_servername($clnt->cl_server,
295 &$clnt->cl_xprt->addr)
296 else {
297 __xprt = rcu_dereference($clnt->cl_xprt)
298 servername = __rpc_format_servername(@cast(__xprt, "rpc_xprt")->servername,
299 &@cast(__xprt, "rpc_xprt")->addr)
300 }
301 progname = kernel_string(@choose_defined($clnt->cl_program->name,
302 $clnt->cl_protname))
303 prog = prog_from_clnt($clnt)
304 vers = vers_from_clnt($clnt)
305 prot = prot_from_clnt($clnt)
306 port = port_from_clnt($clnt)
307 authflavor = $clnt->cl_auth->au_flavor
308
309 name = "sunrpc.clnt.clone_client"
310 argstr = sprintf("%s %s %d %d %d %d %d", servername, progname,
311 prog, vers, prot, port, authflavor)
312 }
313
314 probe sunrpc.clnt.clone_client.return =
315 kernel.function("rpc_clone_client").return !,
316 module("sunrpc").function("rpc_clone_client").return
317 {
318 name = "sunrpc.clnt.clone_client.return"
319 retstr = return_str(2, $return)
320 }
321
322 /**
323 * probe sunrpc.clnt.shutdown_client - Shutdown an RPC client
324 *
325 * @servername: the server machine name
326 * @progname: the RPC program name
327 * @prog: the RPC program number
328 * @vers: the RPC program version number
329 * @prot: the IP protocol number
330 * @port: the port number
331 * @authflavor: the authentication flavor
332 * @clones: the number of clones
333 * @tasks: the number of references
334 * @netreconn: the count of reconnections
335 * @rpccnt: the count of RPC calls
336 * @om_ops: the count of operations
337 * @om_ntrans: the count of RPC transmissions
338 * @om_bytes_sent: the count of bytes out
339 * @om_bytes_recv: the count of bytes in
340 * @om_queue: the jiffies queued for xmit
341 * @om_rtt: the RPC RTT jiffies
342 * @om_execute: the RPC execution jiffies
343 */
344 probe sunrpc.clnt.shutdown_client = kernel.function("rpc_shutdown_client") !,
345 module("sunrpc").function("rpc_shutdown_client")
346 {
347 if (@defined($clnt->cl_server))
348 servername = __rpc_format_servername($clnt->cl_server,
349 &$clnt->cl_xprt->addr)
350 else {
351 __xprt = rcu_dereference($clnt->cl_xprt)
352 servername = __rpc_format_servername(@cast(__xprt, "rpc_xprt")->servername,
353 &@cast(__xprt, "rpc_xprt")->addr)
354 }
355 progname = kernel_string(@choose_defined($clnt->cl_program->name,
356 $clnt->cl_protname))
357 prog = prog_from_clnt($clnt)
358 vers = vers_from_clnt($clnt)
359 prot = prot_from_clnt($clnt)
360 port = port_from_clnt($clnt)
361 authflavor = $clnt->cl_auth->au_flavor
362 clones = clones_from_clnt($clnt)
363 tasks = tasks_from_clnt($clnt)
364
365 /* per-program statistics */
366 netreconn = $clnt->cl_stats->netreconn
367 rpccnt = $clnt->cl_stats->rpccnt
368
369 /* per-client statistics */
370 if (@defined($clnt->cl_metrics)) {
371 om_ops = $clnt->cl_metrics->om_ops
372 om_ntrans = $clnt->cl_metrics->om_ntrans
373 om_bytes_sent = $clnt->cl_metrics->om_bytes_sent
374 om_bytes_recv = $clnt->cl_metrics->om_bytes_recv
375 if (@defined($clnt->cl_metrics->om_queue->tv64)) {
376 om_queue = $clnt->cl_metrics->om_queue->tv64
377 om_rtt = $clnt->cl_metrics->om_rtt->tv64
378 om_execute = $clnt->cl_metrics->om_execute->tv64
379 }
380 else
381 {
382 om_queue = $clnt->cl_metrics->om_queue
383 om_rtt = $clnt->cl_metrics->om_rtt
384 om_execute = $clnt->cl_metrics->om_execute
385 }
386 }
387 else {
388 om_ops = -1
389 om_ntrans = -1
390 om_bytes_sent = -1
391 om_bytes_recv = -1
392 om_queue = -1
393 om_rtt = -1
394 om_execute = -1
395 }
396
397 name = "sunrpc.clnt.shutdown_client"
398 argstr = sprintf("%s %s %d %d %d %d %d %d %d", servername, progname,
399 prog, vers, prot, port, authflavor, clones, tasks)
400 }
401
402 probe sunrpc.clnt.shutdown_client.return =
403 kernel.function("rpc_shutdown_client").return !,
404 module("sunrpc").function("rpc_shutdown_client").return
405 {
406 name = "sunrpc.clnt.shutdown_client.return"
407 retstr = (@defined($return) ? return_str(1, $return) : "N/A")
408 }
409
410 /**
411 * probe sunrpc.clnt.bind_new_program - Bind a new RPC program to an existing client
412 *
413 * @servername: the server machine name
414 * @old_progname: the name of old RPC program
415 * @old_prog: the number of old RPC program
416 * @old_vers: the version of old RPC program
417 * @progname: the name of new RPC program
418 * @prog: the number of new RPC program
419 * @vers: the version of new RPC program
420 */
421 probe sunrpc.clnt.bind_new_program =
422 kernel.function("rpc_bind_new_program") !,
423 module("sunrpc").function("rpc_bind_new_program")
424 {
425 if (@defined($old->cl_server))
426 servername = __rpc_format_servername($old->cl_server,
427 &$old->cl_xprt->addr)
428 else {
429 __xprt = rcu_dereference($old->cl_xprt)
430 servername = __rpc_format_servername(@cast(__xprt, "rpc_xprt")->servername,
431 &@cast(__xprt, "rpc_xprt")->addr)
432 }
433 old_progname = kernel_string(@choose_defined($old->cl_program->name,
434 $old->cl_protname))
435 old_prog = prog_from_clnt($old)
436 old_vers = vers_from_clnt($old)
437 progname = kernel_string($program->name)
438 prog = $program->number
439 vers = vers_from_prog($program, $vers)
440
441 name = "sunrpc.clnt.bind_new_program"
442 argstr = sprintf("%s %s %d %s %d", servername, old_progname,
443 old_vers, progname, vers)
444 }
445
446 probe sunrpc.clnt.bind_new_program.return =
447 kernel.function("rpc_bind_new_program").return !,
448 module("sunrpc").function("rpc_bind_new_program").return
449 {
450 name = "sunrpc.clnt.bind_new_program.return"
451 retstr = return_str(2, $return)
452 }
453
454 /**
455 * probe sunrpc.clnt.call_sync - Make a synchronous RPC call
456 *
457 * @servername: the server machine name
458 * @progname: the RPC program name
459 * @prog: the RPC program number
460 * @vers: the RPC program version number
461 * @prot: the IP protocol number
462 * @port: the port number
463 * @xid: current transmission id
464 * @dead: whether this client is abandoned
465 * @procname: the procedure name in this RPC call
466 * @proc: the procedure number in this RPC call
467 * @flags: flags
468 */
469 probe sunrpc.clnt.call_sync = kernel.function("rpc_call_sync") !,
470 module("sunrpc").function("rpc_call_sync")
471 {
472 if (@defined($clnt->cl_server))
473 servername = __rpc_format_servername($clnt->cl_server,
474 &$clnt->cl_xprt->addr)
475 else {
476 __xprt = rcu_dereference($clnt->cl_xprt)
477 servername = __rpc_format_servername(@cast(__xprt, "rpc_xprt")->servername,
478 &@cast(__xprt, "rpc_xprt")->addr)
479 }
480 progname = kernel_string(@choose_defined($clnt->cl_program->name,
481 $clnt->cl_protname))
482 prog = prog_from_clnt($clnt)
483 vers = vers_from_clnt($clnt)
484 prot = prot_from_clnt($clnt)
485 port = port_from_clnt($clnt)
486 xid = xid_from_clnt($clnt)
487 dead = @choose_defined($clnt->cl_dead,
488 atomic_read(@choose_defined(&$clnt->cl_kref->refcount,
489 &$clnt->cl_count)) == 0)
490
491 proc = proc_from_msg($msg)
492 procname = kernel_string(@choose_defined($msg->rpc_proc->p_name, 0), "NULL")
493 flags = $flags
494
495 name = "sunrpc.clnt.call_sync"
496 argstr = sprintf("%s %d %s %d %s %d", servername, xid, progname,
497 vers, procname, flags)
498 }
499
500 probe sunrpc.clnt.call_sync.return = kernel.function("rpc_call_sync").return !,
501 module("sunrpc").function("rpc_call_sync").return
502 {
503 name = "sunrpc.clnt.call_sync.return"
504 retstr = return_str(1, $return)
505 }
506
507 /**
508 * probe sunrpc.clnt.call_async - Make an asynchronous RPC call
509 *
510 * @servername: the server machine name
511 * @progname: the RPC program name
512 * @prog: the RPC program number
513 * @vers: the RPC program version number
514 * @prot: the IP protocol number
515 * @port: the port number
516 * @xid: current transmission id
517 * @dead: whether this client is abandoned
518 * @procname: the procedure name in this RPC call
519 * @proc: the procedure number in this RPC call
520 * @flags: flags
521 */
522 probe sunrpc.clnt.call_async = kernel.function("rpc_call_async") !,
523 module("sunrpc").function("rpc_call_async")
524 {
525 if (@defined($clnt->cl_server))
526 servername = __rpc_format_servername($clnt->cl_server,
527 &$clnt->cl_xprt->addr)
528 else {
529 __xprt = rcu_dereference($clnt->cl_xprt)
530 servername = __rpc_format_servername(@cast(__xprt, "rpc_xprt")->servername,
531 &@cast(__xprt, "rpc_xprt")->addr)
532 }
533 progname = kernel_string(@choose_defined($clnt->cl_program->name,
534 $clnt->cl_protname))
535 prog = prog_from_clnt($clnt)
536 vers = vers_from_clnt($clnt)
537 prot = prot_from_clnt($clnt)
538 port = port_from_clnt($clnt)
539 xid = xid_from_clnt($clnt)
540 dead = @choose_defined($clnt->cl_dead,
541 atomic_read(@choose_defined(&$clnt->cl_kref->refcount,
542 &$clnt->cl_count)) == 0)
543
544 proc = proc_from_msg($msg)
545 procname = kernel_string(@choose_defined($msg->rpc_proc->p_name, 0), "NULL")
546 flags = $flags
547
548 name = "sunrpc.clnt.call_async"
549 argstr = sprintf("%s %d %s %d %s %d", servername, xid, progname,
550 vers, procname, flags)
551 }
552
553 probe sunrpc.clnt.call_async.return =
554 kernel.function("rpc_call_async").return !,
555 module("sunrpc").function("rpc_call_async").return
556 {
557 name = "sunrpc.clnt.call_async.return"
558 retstr = return_str(1, $return)
559 }
560
561 /**
562 * probe sunrpc.clnt.restart_call - Restart an asynchronous RPC call
563 *
564 * @servername: the server machine name
565 * @prog: the RPC program number
566 * @xid: the transmission id
567 * @tk_pid: the debugging aid of task
568 * @tk_flags: the task flags
569 * @tk_priority: the task priority
570 * @tk_runstate: the task run status
571 */
572 probe sunrpc.clnt.restart_call = kernel.function("rpc_restart_call") !,
573 module("sunrpc").function("rpc_restart_call")
574 {
575 if (@defined($task->tk_client->cl_server))
576 servername = __rpc_format_servername($task->tk_client->cl_server,
577 &$task->tk_client->cl_xprt->addr)
578 else {
579 __xprt = rcu_dereference($task->tk_client->cl_xprt)
580 servername = __rpc_format_servername(@cast(__xprt, "rpc_xprt")->servername,
581 &@cast(__xprt, "rpc_xprt")->addr)
582 }
583 prog = prog_from_clnt($task->tk_client)
584 xid = $task->tk_rqstp->rq_xid
585 tk_pid = $task->tk_pid
586 tk_flags = $task->tk_flags
587 tk_priority = $task->tk_priority
588 tk_runstate = $task->tk_runstate
589
590 name = "sunrpc.clnt.restart_call"
591 argstr = sprintf("%s %d %d %d %d %d %d", servername, prog, xid, tk_pid,
592 tk_flags, tk_priority, tk_runstate)
593 }
594
595 probe sunrpc.clnt.restart_call.return =
596 kernel.function("rpc_restart_call").return !,
597 module("sunrpc").function("rpc_restart_call").return
598 {
599 name = "sunrpc.clnt.restart_call.return"
600 retstr = "N/A"
601 }
602
603 /*********************************************
604 * Probe points on RPC server interface *
605 ********************************************/
606 probe sunrpc.svc.entry =
607 sunrpc.svc.register,
608 sunrpc.svc.create,
609 sunrpc.svc.destroy,
610 sunrpc.svc.process,
611 sunrpc.svc.authorise,
612 sunrpc.svc.recv,
613 sunrpc.svc.send,
614 sunrpc.svc.drop
615 {}
616
617 probe sunrpc.svc.return =
618 sunrpc.svc.register.return,
619 sunrpc.svc.create.return,
620 sunrpc.svc.destroy.return,
621 sunrpc.svc.process.return,
622 sunrpc.svc.authorise.return,
623 sunrpc.svc.recv.return,
624 sunrpc.svc.send.return,
625 sunrpc.svc.drop.return
626 {}
627
628 /**
629 * probe sunrpc.svc.register - Register an RPC service with the local portmapper
630 *
631 * @sv_name: the service name
632 * @progname: the name of the program
633 * @prog: the number of the program
634 * @prot: the IP protocol number
635 * @port: the port number
636 *
637 * If @proto and @port are both 0, then unregister a service.
638 */
639 probe sunrpc.svc.register = kernel.function("svc_register") !,
640 module("sunrpc").function("svc_register")
641 {
642 sv_name = kernel_string($serv->sv_name)
643 progname = kernel_string($serv->sv_program->pg_name)
644 prog = $serv->sv_program->pg_prog
645 prot = $proto
646 port = $port
647
648 name = "sunrpc.svc.register"
649 argstr = sprintf("%s %s %d %d", sv_name, progname, prot, port)
650 }
651
652 probe sunrpc.svc.register.return = kernel.function("svc_register").return !,
653 module("sunrpc").function("svc_register").return
654 {
655 name = "sunrpc.svc.register.return"
656 retstr = return_str(1, $return)
657 }
658
659 /**
660 * probe sunrpc.svc.create - Create an RPC service
661 *
662 * @progname: the name of the program
663 * @prog: the number of the program
664 * @pg_nvers: the number of supported versions
665 * @bufsize: the buffer size
666 */
667 probe sunrpc.svc.create = kernel.function("svc_create") !,
668 module("sunrpc").function("svc_create")
669 {
670 progname = kernel_string($prog->pg_name)
671 prog = $prog->pg_prog
672 pg_nvers = $prog->pg_nvers
673 bufsize = $bufsize
674
675 name = "sunrpc.svc.create"
676 argstr = sprintf("%s %d %d %d", progname, prog, pg_nvers, bufsize)
677 }
678
679 probe sunrpc.svc.create.return = kernel.function("svc_create").return !,
680 module("sunrpc").function("svc_create").return
681 {
682 name = "sunrpc.svc.create.return"
683 retstr = return_str(2, $return)
684 }
685
686 /**
687 * probe sunrpc.svc.destroy - Destroy an RPC service
688 *
689 * @sv_name: the service name
690 * @sv_progname: the name of the program
691 * @sv_prog: the number of the program
692 * @sv_nrthreads:the number of concurrent threads
693 * @netcnt: the count of received RPC requests
694 * @nettcpconn: the count of accepted TCP connections
695 * @rpccnt: the count of valid RPC requests
696 * @rpcbadfmt: the count of requests dropped for bad formats
697 * @rpcbadauth: the count of requests drooped for authentication failure
698 */
699 probe sunrpc.svc.destroy = kernel.function("svc_destroy") !,
700 module("sunrpc").function("svc_destroy")
701 {
702 serv = (@defined($servp) ? $servp : $serv)
703 sv_name = kernel_string(serv->sv_name) /* service name */
704 sv_progname = kernel_string(serv->sv_program->pg_name)
705 sv_prog = serv->sv_program->pg_prog
706 sv_nrthreads = serv->sv_nrthreads
707
708 /* RPC statistics */
709 netcnt = serv->sv_stats->netcnt
710 netcpconn = serv->sv_stats->nettcpconn
711 rpccnt = serv->sv_stats->rpccnt
712 rpcbadfmt = serv->sv_stats->rpcbadfmt
713 rpcbadauth = serv->sv_stats->rpcbadauth
714
715 name = "sunrpc.svc.destroy"
716 argstr = sprintf("%s %d %d", sv_name, sv_prog, sv_nrthreads)
717 }
718
719 probe sunrpc.svc.destroy.return = kernel.function("svc_destroy").return !,
720 module("sunrpc").function("svc_destroy").return
721 {
722 name = "sunrpc.svc.destroy.return"
723 retstr = "N/A"
724 }
725
726 /**
727 * probe sunrpc.svc.process - Process an RPC request
728 *
729 * @sv_name: the service name
730 * @sv_prog: the number of the program
731 * @sv_nrthreads:the number of concurrent threads
732 * @peer_ip: the peer address where the request is from
733 * @rq_xid: the transmission id in the request
734 * @rq_prog: the program number in the request
735 * @rq_vers: the program version in the request
736 * @rq_proc: the procedure number in the request
737 * @rq_prot: the IP protocol of the reqeust
738 */
739 probe sunrpc.svc.process = kernel.function("svc_process") !,
740 module("sunrpc").function("svc_process")
741 {
742 if (! @defined($serv)) {
743 sv_name = kernel_string($rqstp->rq_server->sv_name)
744 sv_prog = $rqstp->rq_server->sv_program->pg_prog
745 sv_nrthreads = $rqstp->rq_server->sv_nrthreads
746 }
747 else {
748 sv_name = kernel_string($serv->sv_name) /* service name */
749 sv_prog = $serv->sv_program->pg_prog
750 sv_nrthreads = $serv->sv_nrthreads
751 }
752 peer_ip = addr_from_rqst($rqstp)
753 rq_xid = $rqstp->rq_xid
754 rq_prog = $rqstp->rq_prog
755 rq_vers = $rqstp->rq_vers
756 rq_proc = $rqstp->rq_proc
757 rq_prot = $rqstp->rq_prot
758
759 name = "sunrpc.svc.process"
760 argstr = sprintf("%s %d %d %d %d %d %d", sv_name, sv_prog, peer_ip,
761 rq_xid, rq_prog, rq_vers, rq_proc)
762 }
763
764 probe sunrpc.svc.process.return = kernel.function("svc_process").return !,
765 module("sunrpc").function("svc_process").return
766 {
767 name = "sunrpc.svc.process.return"
768 retstr = (@defined($return) ? return_str(1, $return) : "<NA>")
769 }
770
771 /*
772 * probe sunrpc.svc.authorise - An RPC request is to be authorised
773 *
774 * @sv_name: the service name
775 * @peer_ip: the peer address where the request is from
776 * @rq_xid: the transmission id in the request
777 * @rq_prog: the program number in the request
778 * @rq_vers: the program version in the request
779 * @rq_proc: the procedure number in the request
780 * @rq_prot: the IP protocol of the reqeust
781 */
782 probe sunrpc.svc.authorise = kernel.function("svc_authorise") !,
783 module("sunrpc").function("svc_authorise")
784 {
785 sv_name = kernel_string($rqstp->rq_server->sv_name)
786 peer_ip = addr_from_rqst($rqstp)
787 rq_xid = $rqstp->rq_xid
788 rq_prog = $rqstp->rq_prog
789 rq_vers = $rqstp->rq_vers
790 rq_proc = $rqstp->rq_proc
791 rq_prot = $rqstp->rq_prot
792
793 name = "sunrpc.svc.authorise"
794 argstr = sprintf("%d %d %d %d %d %d", peer_ip, rq_xid, rq_prog,
795 rq_vers, rq_proc, rq_prot)
796 }
797
798 probe sunrpc.svc.authorise.return = kernel.function("svc_authorise").return !,
799 module("sunrpc").function("svc_authorise").return
800 {
801 name = "sunrpc.svc.authorise.return"
802 retstr = return_str(1, $return)
803 }
804
805 /**
806 * probe sunrpc.svc.recv - Listen for the next RPC request on any socket
807 *
808 * @sv_name: the service name
809 * @sv_prog: the number of the program
810 * @sv_nrthreads:the number of concurrent threads
811 * @timeout: the timeout of waiting for data
812 */
813 probe sunrpc.svc.recv = kernel.function("svc_recv") !,
814 module("sunrpc").function("svc_recv")
815 {
816 if (! @defined($serv)) {
817 sv_name = kernel_string($rqstp->rq_server->sv_name)
818 sv_prog = $rqstp->rq_server->sv_program->pg_prog
819 sv_nrthreads = $rqstp->rq_server->sv_nrthreads
820 }
821 else {
822 sv_name = kernel_string($serv->sv_name)
823 sv_prog = $serv->sv_program->pg_prog
824 sv_nrthreads = $serv->sv_nrthreads
825 }
826 timeout = @choose_defined($timeout,0)
827
828 name = "sunrpc.svc.recv"
829 argstr = sprintf("%s %d", sv_name, timeout)
830 }
831
832 probe sunrpc.svc.recv.return = kernel.function("svc_recv").return !,
833 module("sunrpc").function("svc_recv").return
834 {
835 name = "sunrpc.svc.recv.return"
836 retstr = (@defined($return) ? return_str(1, $return) : "<NA>")
837 }
838
839 /**
840 * probe sunrpc.svc.send - Return reply to RPC client
841 *
842 * @sv_name: the service name
843 * @peer_ip: the peer address where the request is from
844 * @rq_xid: the transmission id in the request
845 * @rq_prog: the program number in the request
846 * @rq_vers: the program version in the request
847 * @rq_proc: the procedure number in the request
848 * @rq_prot: the IP protocol of the reqeust
849 */
850 probe sunrpc.svc.send = kernel.function("svc_send") !,
851 module("sunrpc").function("svc_send")
852 {
853 sv_name = kernel_string($rqstp->rq_server->sv_name)
854 peer_ip = addr_from_rqst($rqstp)
855 rq_xid = $rqstp->rq_xid
856 rq_prog = $rqstp->rq_prog
857 rq_vers = $rqstp->rq_vers
858 rq_proc = $rqstp->rq_proc
859 rq_prot = $rqstp->rq_prot
860
861 name = "sunrpc.svc.send"
862 argstr = sprintf("%s %d %d %d %d %d %d", sv_name, peer_ip,
863 rq_xid, rq_prog, rq_vers, rq_proc, rq_prot)
864 }
865
866 probe sunrpc.svc.send.return = kernel.function("svc_send").return !,
867 module("sunrpc").function("svc_send").return
868 {
869 name = "sunrpc.svc.send.return"
870 retstr = (@defined($return) ? return_str(1, $return) : "<NA>")
871 }
872
873 /**
874 * probe sunrpc.svc.drop - Drop RPC request
875 *
876 * @sv_name: the service name
877 * @peer_ip: the peer address where the request is from
878 * @rq_xid: the transmission id in the request
879 * @rq_prog: the program number in the request
880 * @rq_vers: the program version in the request
881 * @rq_proc: the procedure number in the request
882 * @rq_prot: the IP protocol of the reqeust
883 */
884 probe sunrpc.svc.drop = kernel.function("svc_drop") !,
885 module("sunrpc").function("svc_drop")
886 {
887 sv_name = kernel_string($rqstp->rq_server->sv_name)
888 peer_ip = addr_from_rqst($rqstp)
889 rq_xid = $rqstp->rq_xid
890 rq_prog = $rqstp->rq_prog
891 rq_vers = $rqstp->rq_vers
892 rq_proc = $rqstp->rq_proc
893 rq_prot = $rqstp->rq_prot
894
895 name = "sunrpc.svc.drop"
896 argstr = sprintf("%s %d %d %d %d %d %d", sv_name, peer_ip,
897 rq_xid, rq_prog, rq_vers, rq_proc, rq_prot)
898 }
899
900 probe sunrpc.svc.drop.return = kernel.function("svc_drop").return !,
901 module("sunrpc").function("svc_drop").return
902 {
903 name = "sunrpc.svc.drop.return"
904 retstr = "N/A"
905 }
906
907 /*******************************************************************
908 * Probe points on RPC scheduler *
909 ******************************************************************/
910 probe sunrpc.sched.entry =
911 sunrpc.sched.new_task,
912 sunrpc.sched.release_task ?,
913 sunrpc.sched.execute,
914 sunrpc.sched.delay
915 {}
916
917 probe sunrpc.sched.return =
918 sunrpc.sched.new_task.return,
919 sunrpc.sched.release_task.return ?,
920 sunrpc.sched.execute.return,
921 sunrpc.sched.delay.return
922 {}
923
924 /**
925 * probe sunrpc.sched.new_task - Create new task for the specified client
926 *
927 * @xid: the transmission id in the RPC call
928 * @prog: the program number in the RPC call
929 * @vers: the program version in the RPC call
930 * @prot: the IP protocol in the RPC call
931 * @tk_flags: the flags of the task
932 */
933 probe sunrpc.sched.new_task = kernel.function("rpc_new_task") !,
934 module("sunrpc").function("rpc_new_task")
935 {
936 if (@defined($setup_data)) {
937 xid = xid_from_clnt($setup_data->rpc_client)
938 prog = prog_from_clnt($setup_data->rpc_client)
939 vers = vers_from_clnt($setup_data->rpc_client)
940 prot = prot_from_clnt($setup_data->rpc_client)
941 flags = $setup_data->flags
942 }
943 else {
944 xid = xid_from_clnt($clnt)
945 prog = prog_from_clnt($clnt)
946 vers = vers_from_clnt($clnt)
947 prot = prot_from_clnt($clnt)
948 flags = $flags
949 }
950
951 name = "sunrpc.sched.new_task"
952 argstr = sprintf("%d %d %d %d %d", xid, prog, vers, prot, flags)
953 }
954
955 probe sunrpc.sched.new_task.return = kernel.function("rpc_new_task").return !,
956 module("sunrpc").function("rpc_new_task").return
957 {
958 name = "sunrpc.sched.new_task.return"
959 retstr = return_str(2, $return)
960 }
961
962 /**
963 * probe sunrpc.sched.release_task - Release all resources associated with a task
964 *
965 * @xid: the transmission id in the RPC call
966 * @prog: the program number in the RPC call
967 * @vers: the program version in the RPC call
968 * @prot: the IP protocol in the RPC call
969 * @tk_flags: the flags of the task
970 *
971 * rpc_release_task() function might not be found for a particular kernel.
972 * So, if we can't find it, just return '-1' for everything.
973 */
974 /*
975 * The '.call' here is so that we're sure to grab the non-inline
976 * version of rpc_release_task() (assuming it exists). We can't find
977 * the return of rpc_release_task() if it is inline (PR 4413).
978 */
979 probe sunrpc.sched.release_task = kernel.function("rpc_release_task").call !,
980 module("sunrpc").function("rpc_release_task").call !,
981 never
982 {
983 if (@defined($task)) {
984 xid = xid_from_clnt($task->tk_client)
985 prog = prog_from_clnt($task->tk_client)
986 vers = vers_from_clnt($task->tk_client)
987 prot = prot_from_clnt($task->tk_client)
988 tk_flags = $task->tk_flags
989 }
990 else {
991 xid = -1
992 prog = -1
993 vers = -1
994 prot = -1
995 tk_flags = -1
996 }
997 name = "sunrpc.sched.release_task"
998 argstr = sprintf("%d %d %d %d %d", xid, prog, vers, prot, tk_flags)
999 }
1000
1001 probe sunrpc.sched.release_task.return =
1002 kernel.function("rpc_release_task").return !,
1003 module("sunrpc").function("rpc_release_task").return ?
1004 {
1005 name = "sunrpc.sched.release_task.return"
1006 retstr = "N/A"
1007 }
1008
1009 /**
1010 * probe sunrpc.sched.execute - Execute the RPC `scheduler'
1011 *
1012 * @xid: the transmission id in the RPC call
1013 * @prog: the program number in the RPC call
1014 * @vers: the program version in the RPC call
1015 * @prot: the IP protocol in the RPC call
1016 * @tk_pid: the debugging id of the task
1017 * @tk_flags: the flags of the task
1018 */
1019 probe sunrpc.sched.execute = kernel.function("__rpc_execute") !,
1020 module("sunrpc").function("__rpc_execute")
1021 {
1022 xid = xid_from_clnt($task->tk_client)
1023 prog = prog_from_clnt($task->tk_client)
1024 vers = vers_from_clnt($task->tk_client)
1025 prot = prot_from_clnt($task->tk_client)
1026 tk_pid = $task->tk_pid
1027 tk_flags = $task->tk_flags
1028
1029 name = "sunrpc.sched.execute"
1030 argstr = sprintf("%d %d %d %d %d %d", xid, prog, vers, prot,
1031 tk_pid, tk_flags)
1032 }
1033
1034 probe sunrpc.sched.execute.return = kernel.function("__rpc_execute").return !,
1035 module("sunrpc").function("__rpc_execute").return
1036 {
1037 name = "sunrpc.sched.execute.return"
1038
1039 # On kernels > 2.6.20, __rpc_execute() is a void function.
1040 if (@defined($return)) {
1041 retstr = return_str(1, $return)
1042 }
1043 else {
1044 retstr = "N/A"
1045 }
1046 }
1047
1048 /**
1049 * probe sunrpc.sched.delay - Delay an RPC task
1050 *
1051 * @xid: the transmission id in the RPC call
1052 * @prog: the program number in the RPC call
1053 * @vers: the program version in the RPC call
1054 * @prot: the IP protocol in the RPC call
1055 * @tk_pid: the debugging id of the task
1056 * @tk_flags: the flags of the task
1057 * @delay: the time delayed
1058 */
1059 probe sunrpc.sched.delay = kernel.function("rpc_delay") !,
1060 module("sunrpc").function("rpc_delay")
1061 {
1062 xid = xid_from_clnt($task->tk_client)
1063 prog = prog_from_clnt($task->tk_client)
1064 vers = vers_from_clnt($task->tk_client)
1065 prot = prot_from_clnt($task->tk_client)
1066 tk_pid = $task->tk_pid
1067 tk_flags = $task->tk_flags
1068 delay = $delay
1069
1070 name = "sunrpc.sched.delay"
1071 argstr = sprintf("%d %d %d %d %d %d %d", xid, prog, vers,
1072 prot, tk_pid, tk_flags, delay)
1073 }
1074
1075 probe sunrpc.sched.delay.return = kernel.function("rpc_delay").return !,
1076 module("sunrpc").function("rpc_delay").return
1077 {
1078 name = "sunrpc.sched.delay.return"
1079 retstr = "N/A"
1080 }
1081
1082 /******************************************************************
1083 * Helper functions *
1084 *****************************************************************/
1085
1086 function xid_from_clnt:long(clnt:long)
1087 {
1088 if (clnt == 0)
1089 return 0
1090 return @cast(clnt, "rpc_clnt", "kernel:sunrpc")->cl_xprt->xid
1091 }
1092
1093 function prog_from_clnt:long(clnt:long)
1094 {
1095 if (clnt == 0)
1096 return 0
1097 return @choose_defined(@cast(clnt, "rpc_clnt", "kernel:sunrpc")->cl_prog,
1098 @cast(clnt, "rpc_clnt", "kernel:sunrpc")->cl_pmap->pm_prog)
1099 }
1100
1101 function vers_from_clnt:long(clnt:long)
1102 {
1103 if (clnt == 0)
1104 return 0
1105 return @choose_defined(@cast(clnt, "rpc_clnt", "kernel:sunrpc")->cl_vers,
1106 @cast(clnt, "rpc_clnt", "kernel:sunrpc")->cl_pmap->pm_vers)
1107 }
1108
1109 function prot_from_clnt:long(clnt:long)
1110 {
1111 if (clnt == 0)
1112 return 0
1113 return @cast(clnt, "rpc_clnt", "kernel:sunrpc")->cl_xprt->prot
1114 }
1115
1116 function port_from_xprt:long(cl_xprt:long)
1117 {
1118 if (cl_xprt == 0)
1119 return 0
1120
1121 addr = &@cast(cl_xprt, "rpc_xprt", "kernel:sunrpc")->addr
1122 if (addr == 0)
1123 return 0
1124
1125 /* In reality, 'cl_xprt->addr' is of 'sockaddr_storage' type
1126 * (since 2.6.19). But when used, you cast it to what is
1127 * inside that buffer. The 'struct sockaddr', 'struct
1128 * sockaddr_in', and 'sockaddr_in6' structures all have a
1129 * family type as their 1st member. */
1130 if (@cast(addr, "sockaddr")->sa_family
1131 == @const("AF_INET")) {
1132 return ntohs(@cast(addr, "sockaddr_in")->sin_port)
1133 }
1134 else if (@cast(addr, "sockaddr")->sa_family
1135 == @const("AF_INET6")) {
1136 return ntohs(@cast(addr, "sockaddr_in6")->sin6_port)
1137 }
1138 return 0
1139 }
1140
1141 function port_from_clnt:long(clnt:long)
1142 {
1143 if (clnt == 0)
1144 return 0
1145
1146 cl_xprt = @cast(clnt, "rpc_clnt", "kernel:sunrpc")->cl_xprt
1147 return port_from_xprt(cl_xprt)
1148 }
1149
1150 function clones_from_clnt:long(clnt:long)
1151 {
1152 return (@defined(@cast(clnt, "rpc_clnt", "kernel:sunrpc")->cl_count)
1153 ? atomic_read(&@cast(clnt, "rpc_clnt", "kernel:sunrpc")->cl_count)
1154 : -1)
1155 }
1156
1157 function tasks_from_clnt:long(clnt:long)
1158 {
1159 return (@defined(@cast(clnt, "rpc_clnt", "kernel:sunrpc")->cl_users)
1160 ? atomic_read(&@cast(clnt, "rpc_clnt", "kernel:sunrpc")->cl_users)
1161 : -1)
1162 }
1163
1164 function proc_from_msg:long(msg:long)
1165 {
1166 if (msg == 0)
1167 return 0
1168 return @cast(msg, "rpc_message", "kernel:sunrpc")->rpc_proc->p_proc
1169 }
1170
1171 function vers_from_prog:long(program:long, vers:long)
1172 {
1173 if (program
1174 && vers < @cast(program, "rpc_program", "kernel:sunrpc")->nrvers)
1175 return @cast(program, "rpc_program", "kernel:sunrpc")->version[vers]->number
1176 return 0
1177 }
1178
1179 function addr_from_rqst:long(rqstp:long)
1180 {
1181 if (rqstp) {
1182 addr = &@cast(rqstp, "svc_rqst", "kernel:nfs")->rq_addr
1183 if (addr == 0)
1184 return 0
1185
1186 /* In reality, 'rq_addr' is of 'sockaddr_storage' type
1187 * (since 2.6.19). But when used, you cast it to what is
1188 * inside that buffer. The 'struct sockaddr', 'struct
1189 * sockaddr_in', and 'sockaddr_in6' structures all have a
1190 * family type as their 1st member. */
1191 if (@cast(addr, "sockaddr")->sa_family
1192 == @const("AF_INET")) {
1193 return @cast(addr, "sockaddr_in")->sin_addr->s_addr
1194 }
1195 else if (@cast(addr, "sockaddr")->sa_family
1196 == @const("AF_INET6")) {
1197 return &@cast(addr, "sockaddr_in6")->sin6_addr
1198 }
1199 }
1200 return 0
1201 }
1202
1203 function addr_from_rqst_str:string(rqstp:long)
1204 {
1205 if (rqstp == 0)
1206 return "Null"
1207
1208 addr = &@cast(rqstp, "svc_rqst", "kernel:nfs")->rq_addr
1209 if (addr == 0)
1210 return "Null"
1211
1212 s_addr = addr_from_rqst(rqstp)
1213 if (s_addr == 0)
1214 return "Unsupported Address Family"
1215 if (@cast(addr, "sockaddr_in")->sin_family
1216 == @const("AF_INET")) {
1217 return sprintf("%s:%d",
1218 format_ipaddr(s_addr,
1219 @const("AF_INET")),
1220 @cast(addr, "sockaddr_in")->sin_port)
1221 }
1222 return sprintf("[%s]:%d",
1223 format_ipaddr(s_addr,
1224 @const("AF_INET6")),
1225 @cast(addr, "sockaddr_in6")->sin6_port)
1226 }
1227
1228 %{
1229 #include <linux/un.h>
1230 #include <linux/in.h>
1231 #include <linux/in6.h>
1232 %}
1233
1234 @__private30 function __rpc_format_servername:string(servername:long, address:long)
1235 {
1236 printf("__rpc_format_servername: %p\n", servername)
1237 if (servername != 0)
1238 return kernel_string(servername)
1239
1240 // If 'servername' is NULL, create a string representation of
1241 // the passed-in address.
1242 //
1243 // Note that 'address' is a generic 'struct sockaddr'. When
1244 // you use it you have to cast it to the more specific
1245 // structure based on the family type.
1246 if (@cast(address, "sockaddr")->sa_family == @const("AF_LOCAL")) {
1247 return kernel_string(@cast(address, "sockaddr_un")->sun_path)
1248 }
1249 else if (@cast(address, "sockaddr")->sa_family == @const("AF_INET")) {
1250 return format_ipaddr(&@cast(address, "sockaddr_in")->sin_addr->s_addr, @const("AF_INET"))
1251 }
1252 else if (@cast(address, "sockaddr")->sa_family == @const("AF_INET6")) {
1253 return format_ipaddr(&@cast(address, "sockaddr_in6")->sin6_addr,
1254 @const("AF_INET6"))
1255 }
1256 return "*unknown address family*"
1257 }