[Devel] [PATCH rh7 1/2] net: Allow to show socket-specific information in /proc/[pid]/fdinfo/[fd]

Kirill Tkhai ktkhai at virtuozzo.com
Thu Dec 26 16:23:48 MSK 2019


This adds .show_fdinfo to socket_file_ops, so protocols will be able
to print their specific data in fdinfo.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
Signed-off-by: David S. Miller <davem at davemloft.net>
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 include/linux/net.h |    1 +
 net/socket.c        |   13 +++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/include/linux/net.h b/include/linux/net.h
index d1c264888975..168925acfb65 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -164,6 +164,7 @@ struct proto_ops {
 	int		(*compat_getsockopt)(struct socket *sock, int level,
 				      int optname, char __user *optval, int __user *optlen);
 #endif
+	void		(*show_fdinfo)(struct seq_file *m, struct socket *sock);
 	int		(*sendmsg)   (struct kiocb *iocb, struct socket *sock,
 				      struct msghdr *m, size_t total_len);
 	/* Notes for implementing recvmsg:
diff --git a/net/socket.c b/net/socket.c
index 3a5390725433..fb6e5a296337 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -135,6 +135,7 @@ 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);
+static int sock_show_fdinfo(struct seq_file *m, struct file *f);
 
 /*
  *	Socket files have a set of 'special' operations as well as the generic file ones. These don't appear
@@ -157,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
 };
 
 /*
@@ -1018,6 +1022,15 @@ static ssize_t sock_aio_write(struct kiocb *iocb, const struct iovec *iov,
 	return do_sock_write(&x->async_msg, iocb, iocb->ki_filp, iov, nr_segs);
 }
 
+static int sock_show_fdinfo(struct seq_file *m, struct file *f)
+{
+	struct socket *sock = f->private_data;
+
+	if (sock->ops->show_fdinfo)
+		sock->ops->show_fdinfo(m, sock);
+	return 0;
+}
+
 /*
  * Atomic setting of ioctl hooks to avoid race
  * with module unload.




More information about the Devel mailing list