#!/usr/bin/stap -vg %{ #include %} function xprt_connected:long(xprt:long) %{ struct rpc_xprt *_xprt = (struct rpc_xprt *)(long)THIS->xprt; THIS->__retvalue = (long)xprt_connected(_xprt); %} function xprt_connecting:long(xprt:long) %{ struct rpc_xprt *_xprt = (struct rpc_xprt *)(long)THIS->xprt; THIS->__retvalue = (long)xprt_connecting(_xprt); %} function sk_state:string(sk:long) { state = @cast(sk, "sock_common")->skc_state if (state == 1) { return "ESTABLISHED" } else if (state == 2) { return "SYN_SENT" } else if (state == 3) { return "SYN_RECV" } else if (state == 4) { return "FIN_WAIT1" } else if (state == 5) { return "FIN_WAIT2" } else if (state == 6) { return "TIME_WAIT" } else if (state == 7) { return "CLOSE" } else if (state == 8) { return "CLOSE_WAIT" } else if (state == 9) { return "LAST_ACK" } else if (state == 10) { return "LISTEN" } else if (state == 11) { return "CLOSING" } return sprintf("%d", state) } function strerr:string(e:long) { if (e == -99) { return "-EADDRNOTAVAILE" } else if (e == -111) { return "-ECONNREFUSED" } else if (e == -104) { return "-ECONNRESET" } else if (e == -101) { return "-ENETUNREACH" } else if (e == -115) { return "-EINPROGRESS" } else if (e == -114) { return "-EALREADY" } else if (e == -22) { return "-EINVAL" } return sprintf("%d", e) } function addrfam:string(f:long) { if (f == 0) { return "AF_UNSPEC" } else if (f == 2) { return "AF_INET" } return sprintf("%u", f) } probe begin { printf("%s Trace start\n", ctime(gettimeofday_s())) } probe module("sunrpc").function("xprt_connect") { if ($task->tk_client->cl_xprt->prot == 6) { printf("%s --> %s() tk_pid=%u xprt=%p (%s)\n", ctime(gettimeofday_s()), probefunc(), $task->tk_pid, $task->tk_client->cl_xprt, xprt_connected($task->tk_client->cl_xprt) ? "connected" : "not connected") } } probe module("sunrpc").function("xprt_connect").return { if ($task->tk_client->cl_xprt->prot == 6) { printf("%s <-- %s() tk_pid=%u\n\n", ctime(gettimeofday_s()), probefunc(), $task->tk_pid) } } probe module("sunrpc").function("xs_connect") { if ($task->tk_client->cl_xprt->prot == 6) { connecting = xprt_connecting($task->tk_client->cl_xprt) if (connecting) { printf("%s --> %s() tk_pid=%u socket=%p (connecting, do nothing)\n", ctime(gettimeofday_s()), probefunc(), $task->tk_pid, $task->tk_client->cl_xprt->sock) } else if ($task->tk_client->cl_xprt->sock == 0) { printf("%s --> %s() tk_pid=%u socket=%p (not connecting, queue work)\n", ctime(gettimeofday_s()), probefunc(), $task->tk_pid, $task->tk_client->cl_xprt->sock) } else { printf("%s --> %s() tk_pid=%u socket=%p (not connecting, queue delayed work) reestablish_timeout=%d\n", ctime(gettimeofday_s()), probefunc(), $task->tk_pid, $task->tk_client->cl_xprt->sock, $task->tk_client->cl_xprt->reestablish_timeout) } } } probe module("sunrpc").function("xs_connect").return { if ($task->tk_client->cl_xprt->prot == 6) { printf("%s <-- %s() tk_pid=%u\n", ctime(gettimeofday_s()), probefunc(), $task->tk_pid) } } probe module("sunrpc").function("xs_tcp_connect_worker") { if (@cast($args, "rpc_xprt")->sock == 0) { printf("%s --> %s() xprt=%p socket=%p\n", ctime(gettimeofday_s()), probefunc(), $args, @cast($args, "rpc_xprt")->sock) } else { printf("%s --> %s() xprt=%p socket=%p sk_state=%s\n", ctime(gettimeofday_s()), probefunc(), $args, @cast($args, "rpc_xprt")->sock, sk_state(@cast($args, "rpc_xprt")->sock->sk)) } } probe module("sunrpc").function("xs_tcp_connect_worker").return { printf("%s <-- %s()\n\n", ctime(gettimeofday_s()), probefunc()) } probe module("sunrpc").function("xs_tcp_reuse_connection") { printf("%s --> %s()\n", ctime(gettimeofday_s()), probefunc()) } probe kernel.function("kernel_connect") { printf("%s --> %s() socket=%p sock=%p family=%s\n", ctime(gettimeofday_s()), probefunc(), $sock, $sock->sk, addrfam($addr->sa_family)) } probe kernel.function("kernel_connect").return { printf("%s <-- %s() return=%s\n", ctime(gettimeofday_s()), probefunc(), strerr($return)) } probe module("sunrpc").function("xs_tcp_state_change") { printf("%s --> %s() sock=%p sk_state=%s\n", ctime(gettimeofday_s()), probefunc(), $sk, sk_state($sk)) } probe module("sunrpc").function("xs_tcp_state_change").return { printf("%s <-- %s()\n\n", ctime(gettimeofday_s()), probefunc()) } probe module("sunrpc").function("__rpc_default_timer") { printf("%s --> %s(): tk_pid=%u Timed out\n", ctime(gettimeofday_s()), probefunc(), $task->tk_pid) } probe module("sunrpc").function("__rpc_default_timer").return { printf("%s <-- %s()\n\n", ctime(gettimeofday_s()), probefunc()) }