netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masatake YAMATO <yamato@redhat.com>
To: netdev@vger.kernel.org
Cc: yamato@redhat.com
Subject: [PATCH] net: show protocol type in sockprotoname of fdinfo
Date: Mon, 16 Dec 2013 16:19:41 +0900	[thread overview]
Message-ID: <1387178381-30289-1-git-send-email-yamato@redhat.com> (raw)

In 600e177920df936d03b807780ca92c662af98990 "system.sockprotoname"
xattrs is added to sockets enumerated under /proc/$PID/fd.
It is intended mainly to be used from lsof.

The patch was accepted. However, I think using xattrs under procfs is
special hack for lsof. Normally the user of procfs may want to use cat
command(or write syscall) to retrieve informations from the fs.

This patch introduces "sockprotoname" field to /proc/PID/fdinfo of socket.
So the user can use cat command to retrieve the protocol information.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
 net/socket.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/net/socket.c b/net/socket.c
index 879933a..5e27715 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -132,6 +132,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 int 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
@@ -155,6 +158,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
 };
 
 /*
@@ -882,6 +888,20 @@ 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 int sock_show_fdinfo(struct seq_file *m, struct file *file)
+{
+	struct socket *sock;
+	int ret;
+
+	sock = file->private_data;
+	ret = seq_printf(m, "%s: %s\n",
+			 XATTR_SOCKPROTONAME_SUFFIX,
+			 sock->sk ? sock->sk->sk_prot_creator->name : "-");
+	return ret;
+}
+#endif
+
 static struct sock_iocb *alloc_sock_iocb(struct kiocb *iocb,
 					 struct sock_iocb *siocb)
 {
-- 
1.8.3.1

             reply	other threads:[~2013-12-16  7:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-16  7:19 Masatake YAMATO [this message]
2013-12-17 21:38 ` [PATCH] net: show protocol type in sockprotoname of fdinfo David Miller

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=1387178381-30289-1-git-send-email-yamato@redhat.com \
    --to=yamato@redhat.com \
    --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).