@@ -134,8 +134,9 @@ typedef __u8 rds_tos_t;
#define RDS6_INFO_SOCKETS 10015
#define RDS6_INFO_TCP_SOCKETS 10016
#define RDS6_INFO_IB_CONNECTIONS 10017
+#define RDS_INFO_MRS 10018
-#define RDS_INFO_LAST 10017
+#define RDS_INFO_LAST 10018
struct rds_info_counter {
__u8 name[32];
@@ -270,6 +271,16 @@ struct rds6_info_rdma_connection {
__u32 cache_allocs;
};
+struct rds_info_mr {
+ __u32 pid;
+ __u8 comm[TASK_COMM_LEN];
+ __u64 gets;
+ __u64 puts;
+ struct in6_addr laddr;
+ __be16 lport;
+ __u8 tos;
+} __attribute__((packed));
+
/* RDS message Receive Path Latency points */
enum rds_message_rxpath_latency {
RDS_MSG_RX_HDR_TO_DGRAM_START = 0,
@@ -486,6 +486,7 @@ static int rds_getsockopt(struct socket *sock, int level, int optname,
char __user *optval, int __user *optlen)
{
struct rds_sock *rs = rds_sk_to_rs(sock->sk);
+ struct net *net = sock_net(sock->sk);
int ret = -ENOPROTOOPT, len;
int trans;
@@ -499,6 +500,11 @@ static int rds_getsockopt(struct socket *sock, int level, int optname,
switch (optname) {
case RDS_INFO_FIRST ... RDS_INFO_LAST:
+ if (optname == RDS_INFO_MRS &&
+ !ns_capable(net->user_ns, CAP_NET_ADMIN)) {
+ ret = -EACCES;
+ break;
+ }
ret = rds_info_getsockopt(sock, optname, optval,
optlen);
break;
@@ -878,6 +884,38 @@ static void rds6_sock_info(struct socket *sock, unsigned int len,
}
#endif
+void rds_info_mrs(struct socket *sock, unsigned int len,
+ struct rds_info_iterator *iter,
+ struct rds_info_lengths *lens)
+{
+ struct rds_sock *rs;
+ struct rds_info_mr mr_info;
+ unsigned int total = 0;
+
+ len /= sizeof(mr_info);
+
+ spin_lock_bh(&rds_sock_lock);
+ list_for_each_entry(rs, &rds_sock_list, rs_item) {
+ total++;
+ if (total <= len) {
+ memset(&mr_info, 0, sizeof(mr_info));
+ mr_info.pid = rs->rs_pid;
+ strncpy(mr_info.comm, rs->rs_comm, TASK_COMM_LEN);
+ mr_info.gets = atomic64_read(&rs->rs_mr_gets);
+ mr_info.puts = atomic64_read(&rs->rs_mr_puts);
+ mr_info.laddr = rs->rs_bound_addr;
+ mr_info.lport = rs->rs_bound_port;
+ mr_info.tos = rs->rs_tos;
+ rds_info_copy(iter, &mr_info, sizeof(mr_info));
+ }
+ }
+ spin_unlock_bh(&rds_sock_lock);
+
+ lens->nr = total;
+ lens->each = sizeof(mr_info);
+}
+EXPORT_SYMBOL_GPL(rds_info_mrs);
+
static void rds_exit(void)
{
sock_unregister(rds_family_ops.family);
@@ -599,6 +599,7 @@ int rds_ib_init(void)
rds_trans_register(&rds_ib_transport);
rds_info_register_func(RDS_INFO_IB_CONNECTIONS, rds_ib_ic_info);
+ rds_info_register_func(RDS_INFO_MRS, rds_info_mrs);
#if IS_ENABLED(CONFIG_IPV6)
rds_info_register_func(RDS6_INFO_IB_CONNECTIONS, rds6_ib_ic_info);
#endif
@@ -746,7 +746,9 @@ static inline void __rds_wake_sk_sleep(struct sock *sk)
wake_up(waitq);
}
extern wait_queue_head_t rds_poll_waitq;
-
+void rds_info_mrs(struct socket *sock, unsigned int len,
+ struct rds_info_iterator *iter,
+ struct rds_info_lengths *lens);
/* bind.c */
int rds_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len);