From 30dae5653f72fefb28351b7dece29a0d9e412267 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 16 Mar 2011 19:05:06 -0400 Subject: lttng-instrumentation-separate-socketcall-tracepoint Now lttng trace only sys_socket_call for sys_socket, sys_bind and others. But on some arch(for ex, ia64) which lacks of sys_socket_call, we can't get those syscall traced. This patch add separate socketcall tracers to sys_socket, sys_bind, etc. So people who using ia64(and other arch without sys_socket_call) can trace each socket calls. Another benefit is that we can get detail information for those socket calls now.(we can see only arg1 before this patch) Signed-off-by: Zhao Lei Signed-off-by: Mathieu Desnoyers --- net/socket.c | 63 ++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 17 deletions(-) (limited to 'net') diff --git a/net/socket.c b/net/socket.c index 319a3b8f241..7b97ffee5c2 100644 --- a/net/socket.c +++ b/net/socket.c @@ -165,9 +165,19 @@ static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly; static DEFINE_PER_CPU(int, sockets_in_use); +DEFINE_TRACE(socket_create); +DEFINE_TRACE(socket_bind); +DEFINE_TRACE(socket_connect); +DEFINE_TRACE(socket_listen); +DEFINE_TRACE(socket_accept); +DEFINE_TRACE(socket_getsockname); +DEFINE_TRACE(socket_getpeername); +DEFINE_TRACE(socket_socketpair); DEFINE_TRACE(socket_sendmsg); DEFINE_TRACE(socket_recvmsg); -DEFINE_TRACE(socket_create); +DEFINE_TRACE(socket_setsockopt); +DEFINE_TRACE(socket_getsockopt); +DEFINE_TRACE(socket_shutdown); DEFINE_TRACE(socket_call); /* @@ -1307,8 +1317,10 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol) BUILD_BUG_ON(SOCK_NONBLOCK & SOCK_TYPE_MASK); flags = type & ~SOCK_TYPE_MASK; - if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK)) - return -EINVAL; + if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK)) { + retval = -EINVAL; + goto out; + } type &= SOCK_TYPE_MASK; if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK)) @@ -1322,13 +1334,12 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol) if (retval < 0) goto out_release; - trace_socket_create(sock, retval); -out: - /* It may be already another descriptor 8) Not kernel problem. */ - return retval; - + goto out; out_release: sock_release(sock); +out: + trace_socket_create(family, type, protocol, sock, retval); + /* It may be already another descriptor 8) Not kernel problem. */ return retval; } @@ -1345,8 +1356,10 @@ SYSCALL_DEFINE4(socketpair, int, family, int, type, int, protocol, int flags; flags = type & ~SOCK_TYPE_MASK; - if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK)) - return -EINVAL; + if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK)) { + err = -EINVAL; + goto out; + } type &= SOCK_TYPE_MASK; if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK)) @@ -1395,17 +1408,18 @@ SYSCALL_DEFINE4(socketpair, int, family, int, type, int, protocol, if (!err) err = put_user(fd2, &usockvec[1]); if (!err) - return 0; + goto out; sys_close(fd2); sys_close(fd1); - return err; + goto out; out_release_both: sock_release(sock2); out_release_1: sock_release(sock1); out: + trace_socket_socketpair(family, type, protocol, usockvec, err); return err; } @@ -1437,6 +1451,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen) } fput_light(sock->file, fput_needed); } + trace_socket_bind(fd, umyaddr, addrlen, err); return err; } @@ -1464,6 +1479,7 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog) fput_light(sock->file, fput_needed); } + trace_socket_listen(fd, backlog, err); return err; } @@ -1487,8 +1503,10 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr, int err, len, newfd, fput_needed; struct sockaddr_storage address; - if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK)) - return -EINVAL; + if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK)) { + err = -EINVAL; + goto out; + } if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK)) flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK; @@ -1546,6 +1564,7 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr, out_put: fput_light(sock->file, fput_needed); out: + trace_socket_accept(fd, upeer_sockaddr, upeer_addrlen, flags, err); return err; out_fd: fput(newfile); @@ -1595,6 +1614,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr, out_put: fput_light(sock->file, fput_needed); out: + trace_socket_connect(fd, uservaddr, addrlen, err); return err; } @@ -1626,6 +1646,7 @@ SYSCALL_DEFINE3(getsockname, int, fd, struct sockaddr __user *, usockaddr, out_put: fput_light(sock->file, fput_needed); out: + trace_socket_getsockname(fd, usockaddr, usockaddr_len, err); return err; } @@ -1646,7 +1667,7 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr, err = security_socket_getpeername(sock); if (err) { fput_light(sock->file, fput_needed); - return err; + goto out; } err = @@ -1657,6 +1678,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr, usockaddr_len); fput_light(sock->file, fput_needed); } +out: + trace_socket_getpeername(fd, usockaddr, usockaddr_len, err); return err; } @@ -1787,8 +1810,10 @@ SYSCALL_DEFINE5(setsockopt, int, fd, int, level, int, optname, int err, fput_needed; struct socket *sock; - if (optlen < 0) - return -EINVAL; + if (optlen < 0) { + err = -EINVAL; + goto out; + } sock = sockfd_lookup_light(fd, &err, &fput_needed); if (sock != NULL) { @@ -1807,6 +1832,8 @@ SYSCALL_DEFINE5(setsockopt, int, fd, int, level, int, optname, out_put: fput_light(sock->file, fput_needed); } +out: + trace_socket_setsockopt(fd, level, optname, optval, optlen, err); return err; } @@ -1838,6 +1865,7 @@ SYSCALL_DEFINE5(getsockopt, int, fd, int, level, int, optname, out_put: fput_light(sock->file, fput_needed); } + trace_socket_getsockopt(fd, level, optname, optval, optlen, err); return err; } @@ -1857,6 +1885,7 @@ SYSCALL_DEFINE2(shutdown, int, fd, int, how) err = sock->ops->shutdown(sock, how); fput_light(sock->file, fput_needed); } + trace_socket_shutdown(fd, how, err); return err; } -- cgit v1.2.3