[ofa-general] Stringify ibv_event_type

Sean Hefty sean.hefty at intel.com
Thu Jun 21 15:21:40 PDT 2007


>/me nudges sean...

How's this?  Does anything else need to be done with the build (beyond a new
release at some point)?

Signed-off-by: Sean Hefty <sean.hefty at intel.com>

diff --git a/include/rdma/rdma_cma.h b/include/rdma/rdma_cma.h
index f920ae0..43c71d5 100644
--- a/include/rdma/rdma_cma.h
+++ b/include/rdma/rdma_cma.h
@@ -463,7 +463,7 @@ int rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr);
  *   Destruction of an rdma_cm_id will block until related events have been
  *   acknowledged.
  * See also:
- *   rdma_ack_cm_event, rdma_create_event_channel
+ *   rdma_ack_cm_event, rdma_create_event_channel, rdma_event_str
  */
 int rdma_get_cm_event(struct rdma_event_channel *channel,
 		      struct rdma_cm_event **event);
@@ -519,6 +519,16 @@ struct ibv_context **rdma_get_devices(int *num_devices);
  */
 void rdma_free_devices(struct ibv_context **list);
 
+/**
+ * rdma_event_str - Returns a string representation of an rdma cm event.
+ * @event: Asynchronous event.
+ * Description:
+ *   Returns a string representation of an asynchronous event.
+ * See also:
+ *   rdma_get_cm_event
+ */
+const char *rdma_event_str(enum rdma_cm_event_type event);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/man/rdma_event_str.3 b/man/rdma_event_str.3
new file mode 100644
index 0000000..a6ee3e5
--- /dev/null
+++ b/man/rdma_event_str.3
@@ -0,0 +1,15 @@
+.TH "RDMA_EVENT_STR" 3 "2007-05-15" "librdmacm" "Librdmacm Programmer's Manual" librdmacm
+.SH NAME
+rdma_event_str \- Returns a string representation of an rdma cm event.
+.SH SYNOPSIS
+.B "#include <rdma/rdma_cma.h>"
+.P
+.B "char *" rdma_event_str
+.BI "("enum ibv_event_type " event ");"
+.SH ARGUMENTS
+.IP "event" 12
+Asynchronous event.
+.SH "DESCRIPTION"
+Returns a string representation of an asynchronous event.
+.SH "SEE ALSO"
+rdma_get_cm_event(3)
diff --git a/man/rdma_get_cm_event.3 b/man/rdma_get_cm_event.3
index a260092..252a7ab 100644
--- a/man/rdma_get_cm_event.3
+++ b/man/rdma_get_cm_event.3
@@ -62,4 +62,4 @@ no longer accessible and should be rejoined, if desired.
 .SH "SEE ALSO"
 rdma_ack_cm_event(3), rdma_create_event_channel(3), rdma_resolve_addr(3),
 rdma_resolve_route(3), rdma_connect(3), rdma_listen(3), rdma_join_multicast(3),
-rdma_destroy_id(3)
+rdma_destroy_id(3), rdma_event_str(3)
diff --git a/src/cma.c b/src/cma.c
index fdadb69..3579530 100644
--- a/src/cma.c
+++ b/src/cma.c
@@ -1359,3 +1359,39 @@ retry:
 	*event = &evt->event;
 	return 0;
 }
+
+const char *rdma_event_str(enum rdma_cm_event_type event)
+{
+	switch (event) {
+	case RDMA_CM_EVENT_ADDR_RESOLVED:
+		return "RDMA_CM_EVENT_ADDR_RESOLVED";
+	case RDMA_CM_EVENT_ADDR_ERROR:
+		return "RDMA_CM_EVENT_ADDR_ERROR";
+	case RDMA_CM_EVENT_ROUTE_RESOLVED:
+		return "RDMA_CM_EVENT_ROUTE_RESOLVED";
+	case RDMA_CM_EVENT_ROUTE_ERROR:
+		return "RDMA_CM_EVENT_ROUTE_ERROR";
+	case RDMA_CM_EVENT_CONNECT_REQUEST:
+		return "RDMA_CM_EVENT_CONNECT_REQUEST";
+	case RDMA_CM_EVENT_CONNECT_RESPONSE:
+		return "RDMA_CM_EVENT_CONNECT_RESPONSE";
+	case RDMA_CM_EVENT_CONNECT_ERROR:
+		return "RDMA_CM_EVENT_CONNECT_ERROR";
+	case RDMA_CM_EVENT_UNREACHABLE:
+		return "RDMA_CM_EVENT_UNREACHABLE";
+	case RDMA_CM_EVENT_REJECTED:
+		return "RDMA_CM_EVENT_REJECTED";
+	case RDMA_CM_EVENT_ESTABLISHED:
+		return "RDMA_CM_EVENT_ESTABLISHED";
+	case RDMA_CM_EVENT_DISCONNECTED:
+		return "RDMA_CM_EVENT_DISCONNECTED";
+	case RDMA_CM_EVENT_DEVICE_REMOVAL:
+		return "RDMA_CM_EVENT_DEVICE_REMOVAL";
+	case RDMA_CM_EVENT_MULTICAST_JOIN:
+		return "RDMA_CM_EVENT_MULTICAST_JOIN";
+	case RDMA_CM_EVENT_MULTICAST_ERROR:
+		return "RDMA_CM_EVENT_MULTICAST_ERROR";
+	default:
+		return "UNKNOWN EVENT";
+	}
+}
diff --git a/src/librdmacm.map b/src/librdmacm.map
index 06e9765..eafeae4 100644
--- a/src/librdmacm.map
+++ b/src/librdmacm.map
@@ -23,5 +23,6 @@ RDMACM_1.0 {
 		rdma_leave_multicast;
 		rdma_get_devices;
 		rdma_free_devices;
+		rdma_event_str;
 	local: *;
 };

===

diff --git a/examples/cmatose.c b/examples/cmatose.c
index 4479fd4..0daaab0 100644
--- a/examples/cmatose.c
+++ b/examples/cmatose.c
@@ -320,8 +320,8 @@ static int cma_handler(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
 	case RDMA_CM_EVENT_CONNECT_ERROR:
 	case RDMA_CM_EVENT_UNREACHABLE:
 	case RDMA_CM_EVENT_REJECTED:
-		printf("cmatose: event: %d, error: %d\n", event->event,
-			event->status);
+		printf("cmatose: event: %s, error: %d\n",
+		       rdma_event_str(event->event), event->status);
 		connect_error();
 		break;
 	case RDMA_CM_EVENT_DISCONNECTED:
diff --git a/examples/mckey.c b/examples/mckey.c
index 24514a4..15371b6 100644
--- a/examples/mckey.c
+++ b/examples/mckey.c
@@ -305,8 +305,8 @@ static int cma_handler(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
 	case RDMA_CM_EVENT_ADDR_ERROR:
 	case RDMA_CM_EVENT_ROUTE_ERROR:
 	case RDMA_CM_EVENT_MULTICAST_ERROR:
-		printf("mckey: event: %d, error: %d\n", event->event,
-			event->status);
+		printf("mckey: event: %s, error: %d\n",
+		       rdma_event_str(event->event), event->status);
 		connect_error();
 		ret = event->status;
 		break;
diff --git a/examples/rping.c b/examples/rping.c
index 2dd1cef..c03d3b5 100644
--- a/examples/rping.c
+++ b/examples/rping.c
@@ -164,7 +164,8 @@ static int rping_cma_event_handler(struct rdma_cm_id *cma_id,
 	int ret = 0;
 	struct rping_cb *cb = cma_id->context;
 
-	DEBUG_LOG("cma_event type %d cma_id %p (%s)\n", event->event, cma_id,
+	DEBUG_LOG("cma_event type %s cma_id %p (%s)\n",
+		  rdma_event_str(event->event), cma_id,
 		  (cma_id == cb->cm_id) ? "parent" : "child");
 
 	switch (event->event) {
@@ -207,14 +208,15 @@ static int rping_cma_event_handler(struct rdma_cm_id *cma_id,
 	case RDMA_CM_EVENT_CONNECT_ERROR:
 	case RDMA_CM_EVENT_UNREACHABLE:
 	case RDMA_CM_EVENT_REJECTED:
-		fprintf(stderr, "cma event %d, error %d\n", event->event,
-		       event->status);
+		fprintf(stderr, "cma event %s, error %d\n",
+			rdma_event_str(event->event), event->status);
 		sem_post(&cb->sem);
 		ret = -1;
 		break;
 
 	case RDMA_CM_EVENT_DISCONNECTED:
-		fprintf(stderr, "%s DISCONNECT EVENT...\n", cb->server ? "server" : "client");
+		fprintf(stderr, "%s DISCONNECT EVENT...\n",
+			cb->server ? "server" : "client");
 		sem_post(&cb->sem);
 		break;
 
diff --git a/examples/udaddy.c b/examples/udaddy.c
index 12e6297..1b6a732 100644
--- a/examples/udaddy.c
+++ b/examples/udaddy.c
@@ -363,8 +363,8 @@ static int cma_handler(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
 	case RDMA_CM_EVENT_CONNECT_ERROR:
 	case RDMA_CM_EVENT_UNREACHABLE:
 	case RDMA_CM_EVENT_REJECTED:
-		printf("udaddy: event: %d, error: %d\n", event->event,
-			event->status);
+		printf("udaddy: event: %s, error: %d\n",
+		       rdma_event_str(event->event), event->status);
 		connect_error();
 		ret = event->status;
 		break;




More information about the general mailing list