From: Josh Hunt <johunt@akamai.com>
To: davem@davemloft.net, netdev@vger.kernel.org
Cc: Josh Hunt <johunt@akamai.com>
Subject: [RFC] show socket info in fdinfo
Date: Wed, 15 Jul 2015 22:50:19 -0400 [thread overview]
Message-ID: <1437015019-311-1-git-send-email-johunt@akamai.com> (raw)
When sockets are unhashed they are no longer visible through the normal
methods. Provide a way to see all sockets in the system by dumping some
basic socket information in fdinfo.
Signed-off-by: Josh Hunt <johunt@akamai.com>
---
When trying to debug an application issue which wound up not closing sockets
properly we found there was no easy way through existing tools to show sockets
which have been unhashed. In order to get some basic information about all
allocated sockets on the system we'd like to dump this info into fdinfo.
net/socket.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/net/socket.c b/net/socket.c
index 9963a0b..eced913 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -131,6 +131,9 @@ static ssize_t sock_sendpage(struct file *file, struct page *page,
static ssize_t sock_splice_read(struct file *file, loff_t *ppos,
struct pipe_inode_info *pipe, size_t len,
unsigned int flags);
+#ifdef CONFIG_PROC_FS
+static void sock_show_fdinfo(struct seq_file *m, struct file *file);
+#endif
/*
* Socket files have a set of 'special' operations as well as the generic file ones. These don't appear
@@ -153,6 +156,9 @@ static const struct file_operations socket_file_ops = {
.sendpage = sock_sendpage,
.splice_write = generic_splice_sendpage,
.splice_read = sock_splice_read,
+#ifdef CONFIG_PROC_FS
+ .show_fdinfo = sock_show_fdinfo,
+#endif
};
/*
@@ -777,6 +783,52 @@ static ssize_t sock_splice_read(struct file *file, loff_t *ppos,
return sock->ops->splice_read(sock, ppos, pipe, len, flags);
}
+#ifdef CONFIG_PROC_FS
+static void sock_show_fdinfo(struct seq_file *m, struct file *file)
+{
+ struct socket *sock = NULL;
+ struct sock *sk = NULL;
+ int err;
+
+ sock = sock_from_file(file, &err);
+ if (sock) {
+ sk = sock->sk;
+ sock_hold(sk);
+ seq_printf(m, "state:\t%d\n"
+ "type:\t0x%x\n"
+ "flags\t%lu\n"
+ "sk_rcvbuf:\t%d\n"
+ "sk_sndbuf:\t%d\n"
+ "sk_forward_alloc:\t%d\n"
+ "sk_rmem_alloc:\t%d\n"
+ "sk_wmem_alloc:\t%d\n"
+ "sk_wmem_queued:\t%d\n"
+ "sk_err:\t%d\n"
+ "sk_state:\t0x%x\n"
+ "sk_flags:\t0x%lx\n"
+ "sk_unhashed:\t%d\n"
+ "sk_protocol:\t0x%x\n"
+ "sk_family:\t0x%x\n",
+ sock->state,
+ sock->type,
+ sock->flags,
+ sk->sk_rcvbuf,
+ sk->sk_sndbuf,
+ sk->sk_forward_alloc,
+ atomic_read(&sk->sk_rmem_alloc),
+ atomic_read(&sk->sk_wmem_alloc),
+ sk->sk_wmem_queued,
+ sk->sk_err,
+ sk->sk_state,
+ sk->sk_flags,
+ sk_unhashed(sk),
+ sk->sk_protocol,
+ sk->sk_family);
+ sock_put(sk);
+ }
+}
+#endif
+
static ssize_t sock_read_iter(struct kiocb *iocb, struct iov_iter *to)
{
struct file *file = iocb->ki_filp;
--
1.7.9.5
reply other threads:[~2015-07-16 2:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1437015019-311-1-git-send-email-johunt@akamai.com \
--to=johunt@akamai.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).