diff mbox

librdmacm/mckey: add notifications on events

Message ID Pine.LNX.4.64.0911111814350.6979@zuben.voltaire.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Or Gerlitz Nov. 11, 2009, 4:15 p.m. UTC
None
diff mbox

Patch

Index: librdmacm/examples/mckey.c
===================================================================
--- librdmacm.orig/examples/mckey.c
+++ librdmacm/examples/mckey.c
@@ -62,6 +62,7 @@  struct cmatest_node {

 struct cmatest {
 	struct rdma_event_channel *channel;
+	pthread_t 		cmathread;
 	struct cmatest_node	*nodes;
 	int			conn_index;
 	int			connects_left;
@@ -319,6 +320,30 @@  static int cma_handler(struct rdma_cm_id
 	return ret;
 }

+static void *cma_thread(void *arg)
+{
+	struct rdma_cm_event *event;
+	int ret;
+
+	while (1) {
+		ret = rdma_get_cm_event(test.channel, &event);
+		if (ret) {
+			perror("rdma_get_cm_event");
+			exit(ret);
+		}
+		switch (event->event) {
+		case RDMA_CM_EVENT_MULTICAST_ERROR:
+		case RDMA_CM_EVENT_ADDR_CHANGE:
+			printf("mckey: event: %s, status: %d\n",
+			       rdma_event_str(event->event), event->status);
+			break;
+		default:
+			break;
+		}
+		rdma_ack_cm_event(event);
+	}
+}
+
 static void destroy_node(struct cmatest_node *node)
 {
 	if (!node->cma_id)
@@ -475,6 +500,7 @@  static int run(void)
 	if (ret)
 		goto out;

+	pthread_create(&test.cmathread, NULL, cma_thread, NULL);
 	/*
 	 * Pause to give SM chance to configure switches.  We don't want to
 	 * handle reliability issue in this simple test program.