[ofa-general] [PATCH] rdma_cm: Add proc entry to monitor rdma_cm connections
Moni Shoua
monis at Voltaire.COM
Tue Mar 31 09:14:53 PDT 2009
For each rdma_cm_id that is attached to a device print a set of fields
that describe the connection that this id represents.
Below is an example of the output of 'cat /proc/rdma_cm'
This example is for a host with that runs a rping server and a rping client.
TP DEV PO NDEV SRC DST PS ST QPN
0 mthca0 0 0.0.0.0:7174 262 8 0
1 mthca0 1 ib0 192.30.3.249:34478 192.30.3.248:7174 262 5 328710
1 mthca0 1 ib0 192.30.3.249:7174 192.30.3.248:47625 262 5 328711
Signed-off-by: Moni Shoua <monis at voltaire.com>
--
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index 2a2e508..5e5d4f2 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -50,6 +50,9 @@
#include <rdma/ib_cm.h>
#include <rdma/ib_sa.h>
#include <rdma/iw_cm.h>
+#ifdef CONFIG_PROC_FS
+#include <linux/proc_fs.h>
+#endif
MODULE_AUTHOR("Sean Hefty");
MODULE_DESCRIPTION("Generic RDMA CM Agent");
@@ -2943,10 +2946,93 @@ static void cma_remove_one(struct ib_device *device)
kfree(cma_dev);
}
+
+#ifdef CONFIG_PROC_FS
+static void proc_format_addr(struct sockaddr *sa, char* buf)
+{
+ switch (sa->sa_family) {
+ case AF_INET: {
+ struct sockaddr_in *sin = (struct sockaddr_in *)sa;
+ sprintf(buf, "%pI4:%u", &sin->sin_addr.s_addr,
+ be16_to_cpu(cma_port(sa)));
+ break;
+ }
+ case AF_INET6: {
+ struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
+ sprintf(buf, "%pI6:%u", &sin6->sin6_addr,
+ be16_to_cpu(cma_port(sa)));
+ break;
+ }
+ default:
+ buf[0] = 0;
+ }
+}
+
+static int rdma_read_proc(char *page, char **start, off_t off, int count,
+ int *eof, void *data)
+{
+ int cc = 0;
+ char *cp = page;
+ struct rdma_id_private *id_priv;
+ char local_addr[64], remote_addr[64];
+
+ struct cma_device *cma_dev;
+ *cp = 0;
+ cc = sprintf(cp,
+ "%-3s"
+ "%-8s"
+ "%-3s"
+ "%-5s"
+ "%-52s"
+ "%-52s"
+ "%-5s"
+ "%-3s"
+ "%-8s"
+ "\n",
+ "TP", "DEV", "PO", "NDEV", "SRC", "DST", "PS", "ST", "QPN");
+ cp += cc;
+
+ mutex_lock(&lock);
+ list_for_each_entry(cma_dev, &dev_list, list)
+ list_for_each_entry(id_priv, &cma_dev->id_list, list) {
+ proc_format_addr((struct sockaddr *)&id_priv->id.route.addr.src_addr,
+ local_addr);
+ proc_format_addr((struct sockaddr *)&id_priv->id.route.addr.dst_addr,
+ remote_addr);
+ cc = sprintf(cp,
+ "%-3d"
+ "%-8s"
+ "%-3d"
+ "%-5s"
+ "%-52s"
+ "%-52s"
+ "%-5d"
+ "%-3d"
+ "%-8d"
+ "\n",
+ id_priv->id.route.addr.dev_addr.dev_type,
+ (id_priv->id.device) ? id_priv->id.device->name : "",
+ id_priv->id.port_num,
+ (id_priv->id.route.addr.dev_addr.src_dev) ? id_priv->id.route.addr.dev_addr.src_dev->name : "",
+ local_addr,
+ remote_addr,
+ id_priv->id.ps,
+ id_priv->state,
+ id_priv->qp_num);
+ cp += cc;
+ }
+ mutex_unlock(&lock);
+ *eof = 1;
+ return strlen(page);
+}
+#endif
static int cma_init(void)
{
int ret, low, high, remaining;
+#ifdef CONFIG_PROC_FS
+ struct proc_dir_entry *rdma_proc;
+#endif
get_random_bytes(&next_port, sizeof next_port);
inet_get_local_port_range(&low, &high);
remaining = (high - low) + 1;
@@ -2963,6 +3049,15 @@ static int cma_init(void)
ret = ib_register_client(&cma_client);
if (ret)
goto err;
+#ifdef CONFIG_PROC_FS
+ rdma_proc = create_proc_entry("rdma_cm", 0444, NULL);
+ if (rdma_proc == NULL) {
+ printk(KERN_DEBUG "cannot create /proc/rdma_cm\n");
+ } else {
+ rdma_proc->owner = THIS_MODULE;
+ rdma_proc->read_proc = rdma_read_proc;
+ }
+#endif
return 0;
err:
@@ -2984,6 +3079,9 @@ static void cma_cleanup(void)
idr_destroy(&tcp_ps);
idr_destroy(&udp_ps);
idr_destroy(&ipoib_ps);
+#ifdef CONFIG_PROC_FS
+ remove_proc_entry("rdma_cm", NULL);
+#endif
}
module_init(cma_init);
More information about the general
mailing list