From fb3b52a7346202fea1905ed680a3256d372a7b03 Mon Sep 17 00:00:00 2001 From: Wenji Huang Date: Fri, 6 Mar 2009 00:16:50 -0500 Subject: PR9871: use @cast in tapset Rewrite some functions using type casting to get rid of embedded C code in nfs, scsi, signal, socket, rpc, task and vfs tapset. Signed-off-by: Wenji Huang --- tapset/rpc.stp | 94 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 42 insertions(+), 52 deletions(-) (limited to 'tapset/rpc.stp') diff --git a/tapset/rpc.stp b/tapset/rpc.stp index f97117b5..e6eaed46 100644 --- a/tapset/rpc.stp +++ b/tapset/rpc.stp @@ -877,60 +877,52 @@ probe sunrpc.sched.delay.return = kernel.function("rpc_delay").return !, *****************************************************************/ function xid_from_clnt:long(clnt:long) -%{ /* pure */ - struct rpc_clnt *clnt = (struct rpc_clnt *)(long)THIS->clnt; - if (clnt == NULL) - THIS->__retvalue = 0; +{ + if (clnt == 0) + return 0 else { - struct rpc_xprt *cl_xprt = kread(&(clnt->cl_xprt)); - THIS->__retvalue = kread(&(cl_xprt->xid)); + cl_xprt = @cast(clnt, "rpc_clnt", "kernel")->cl_xprt + return @cast(cl_xprt, "rpc_xprt", "kernel")->xid } - CATCH_DEREF_FAULT(); -%} +} function prog_from_clnt:long(clnt:long) -%{ /* pure */ - struct rpc_clnt *clnt = (struct rpc_clnt *)(long)THIS->clnt; - if (clnt == NULL) - THIS->__retvalue = 0; +{ + if (clnt == 0) + return 0 else { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19) - THIS->__retvalue = kread(&(clnt->cl_prog)); -#else - struct rpc_portmap *cl_pmap = kread(&(clnt->cl_pmap)); - THIS->__retvalue = kread(&(cl_pmap->pm_prog)); -#endif +%(kernel_v >= "2.6.19" %? + return @cast(clnt, "rpc_clnt", "kernel")->cl_prog +%: + cl_pmap = @cast(clnt, "rpc_clnt", "kernel")->cl_pmap + return @cast(cl_pmap, "rpc_portmap", "kernel")->pm_prog +%) } - CATCH_DEREF_FAULT(); -%} +} function vers_from_clnt:long(clnt:long) -%{ /* pure */ - struct rpc_clnt *clnt = (struct rpc_clnt *)(long)THIS->clnt; - if (clnt == NULL) - THIS->__retvalue = 0; - else { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19) - THIS->__retvalue = kread(&(clnt->cl_vers)); -#else - struct rpc_portmap *cl_pmap = kread(&(clnt->cl_pmap)); - THIS->__retvalue = kread(&(cl_pmap->pm_vers)); -#endif - } - CATCH_DEREF_FAULT(); -%} +{ + if (clnt == 0) + return 0 + else { +%(kernel_v >= "2.6.19" %? + return @cast(clnt, "rpc_clnt", "kernel")->cl_vers +%: + cl_pmap = @cast(clnt, "rpc_clnt", "kernel")->cl_pmap + return @cast(cl_pmap, "rpc_portmap", "kernel")->pm_vers +%) + } +} function prot_from_clnt:long(clnt:long) -%{ /* pure */ - struct rpc_clnt *clnt = (struct rpc_clnt *)(long)THIS->clnt; - if (clnt == NULL) - THIS->__retvalue = 0; - else { - struct rpc_xprt *cl_xprt = kread(&(clnt->cl_xprt)); - THIS->__retvalue = kread(&(cl_xprt->prot)); - } - CATCH_DEREF_FAULT(); -%} +{ + if (clnt == 0) + return 0 + else { + cl_xprt = @cast(clnt, "rpc_clnt", "kernel")->cl_xprt + return @cast(cl_xprt, "rpc_xprt", "kernel")->prot + } +} function port_from_clnt:long(clnt:long) %{ /* pure */ @@ -975,16 +967,14 @@ function tasks_from_clnt:long(clnt:long) %} function proc_from_msg:long(msg:long) -%{ /* pure */ - struct rpc_message *msg = (struct rpc_message *)(long)THIS->msg; - if (msg == NULL) - THIS->__retvalue = 0; +{ + if (msg == 0) + return 0 else { - struct rpc_procinfo *rpc_proc = kread(&(msg->rpc_proc)); - THIS->__retvalue = kread(&(rpc_proc->p_proc)); + rpc_proc = @cast(msg, "rpc_message", "kernel")->rpc_proc + return @cast(rpc_proc, "rpc_procinfo", "kernel")->p_proc } - CATCH_DEREF_FAULT(); -%} +} function vers_from_prog:long(program:long, vers:long) %{ /* pure */ -- cgit From 6351f32433edb111b28362963c97d1cd0d1d8561 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 10 Mar 2009 15:46:21 -0700 Subject: PR9932: use @cast module search path The nfs, rpc, and scsi tapsets use @cast on types that may be compiled into a kernel module or into the main kernel binary. The @cast search path separated with colons lets us search both the kernel and the module. For a couple of cases, I also merged sequential @casts that work just fine as a single cast with a multiple-level dereference. --- tapset/rpc.stp | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) (limited to 'tapset/rpc.stp') diff --git a/tapset/rpc.stp b/tapset/rpc.stp index e6eaed46..1d47daed 100644 --- a/tapset/rpc.stp +++ b/tapset/rpc.stp @@ -880,48 +880,36 @@ function xid_from_clnt:long(clnt:long) { if (clnt == 0) return 0 - else { - cl_xprt = @cast(clnt, "rpc_clnt", "kernel")->cl_xprt - return @cast(cl_xprt, "rpc_xprt", "kernel")->xid - } + return @cast(clnt, "rpc_clnt", "kernel:sunrpc")->cl_xprt->xid } function prog_from_clnt:long(clnt:long) { if (clnt == 0) return 0 - else { %(kernel_v >= "2.6.19" %? - return @cast(clnt, "rpc_clnt", "kernel")->cl_prog + return @cast(clnt, "rpc_clnt", "kernel:sunrpc")->cl_prog %: - cl_pmap = @cast(clnt, "rpc_clnt", "kernel")->cl_pmap - return @cast(cl_pmap, "rpc_portmap", "kernel")->pm_prog + return @cast(clnt, "rpc_clnt", "kernel:sunrpc")->cl_pmap->pm_prog %) - } } function vers_from_clnt:long(clnt:long) { - if (clnt == 0) - return 0 - else { + if (clnt == 0) + return 0 %(kernel_v >= "2.6.19" %? - return @cast(clnt, "rpc_clnt", "kernel")->cl_vers + return @cast(clnt, "rpc_clnt", "kernel:sunrpc")->cl_vers %: - cl_pmap = @cast(clnt, "rpc_clnt", "kernel")->cl_pmap - return @cast(cl_pmap, "rpc_portmap", "kernel")->pm_vers + return @cast(clnt, "rpc_clnt", "kernel:sunrpc")->cl_pmap->pm_vers %) - } } function prot_from_clnt:long(clnt:long) { - if (clnt == 0) - return 0 - else { - cl_xprt = @cast(clnt, "rpc_clnt", "kernel")->cl_xprt - return @cast(cl_xprt, "rpc_xprt", "kernel")->prot - } + if (clnt == 0) + return 0 + return @cast(clnt, "rpc_clnt", "kernel:sunrpc")->cl_xprt->prot } function port_from_clnt:long(clnt:long) @@ -934,12 +922,14 @@ function port_from_clnt:long(clnt:long) struct sockaddr_in *sap = (struct sockaddr_in *) &cl_xprt->addr; THIS->__retvalue = ntohs(kread(&(sap->sin_port))); + } #else if (cl_xprt && kread(&(cl_xprt->addr.sin_family)) == AF_INET) { /* Now consider ipv4 only */ THIS->__retvalue = ntohs(kread(&(cl_xprt->addr.sin_port))); + } #endif - } else + else THIS->__retvalue = 0; CATCH_DEREF_FAULT(); %} @@ -970,10 +960,7 @@ function proc_from_msg:long(msg:long) { if (msg == 0) return 0 - else { - rpc_proc = @cast(msg, "rpc_message", "kernel")->rpc_proc - return @cast(rpc_proc, "rpc_procinfo", "kernel")->p_proc - } + return @cast(msg, "rpc_message", "kernel:sunrpc")->rpc_proc->p_proc } function vers_from_prog:long(program:long, vers:long) -- cgit