diff mbox

[librdmacm,3/5] rsockets: Add ability to set the IB route directly

Message ID 1375482022-5953-4-git-send-email-sean.hefty@intel.com (mailing list archive)
State Rejected
Headers show

Commit Message

Hefty, Sean Aug. 2, 2013, 10:20 p.m. UTC
From: Sean Hefty <sean.hefty@intel.com>

Add an RDMA specific rsocket option that allows the user
to program the RDMA route directly.  This is useful
for apps that have path record data available, e.g. from
ibacm.

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
---
 include/rdma/rsocket.h |    3 ++-
 src/rsocket.c          |   30 +++++++++++++++++++++++++++---
 2 files changed, 29 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/include/rdma/rsocket.h b/include/rdma/rsocket.h
index f220c13..efd0db5 100644
--- a/include/rdma/rsocket.h
+++ b/include/rdma/rsocket.h
@@ -78,7 +78,8 @@  enum {
 	RDMA_SQSIZE,
 	RDMA_RQSIZE,
 	RDMA_INLINE,
-	RDMA_IOMAPSIZE
+	RDMA_IOMAPSIZE,
+	RDMA_ROUTE
 };
 
 int rsetsockopt(int socket, int level, int optname,
diff --git a/src/rsocket.c b/src/rsocket.c
index e2b1cc7..57df290 100644
--- a/src/rsocket.c
+++ b/src/rsocket.c
@@ -329,6 +329,8 @@  struct rsocket {
 	long		  fd_flags;
 	uint64_t	  so_opts;
 	uint64_t	  ipv6_opts;
+	void		  *optval;
+	size_t		  optlen;
 	int		  state;
 	int		  cq_armed;
 	int		  retries;
@@ -1243,13 +1245,26 @@  resolve_addr:
 		rs->retries = 0;
 resolve_route:
 		to = 1000 << rs->retries++;
-		ret = rdma_resolve_route(rs->cm_id, to);
-		if (!ret)
-			goto do_connect;
+		if (rs->optval) {
+			ret = rdma_set_option(rs->cm_id,  RDMA_OPTION_IB,
+					      RDMA_OPTION_IB_PATH, rs->optval,
+					      rs->optlen);
+			free(rs->optval);
+			rs->optval = NULL;
+			if (!ret) {
+				rs->state = rs_resolving_route;
+				goto resolving_route;
+			}
+		} else {
+			ret = rdma_resolve_route(rs->cm_id, to);
+			if (!ret)
+				goto do_connect;
+		}
 		if (errno == EAGAIN || errno == EWOULDBLOCK)
 			rs->state = rs_resolving_route;
 		break;
 	case rs_resolving_route:
+resolving_route:
 		ret = ucma_complete(rs->cm_id);
 		if (ret) {
 			if (errno == ETIMEDOUT && rs->retries <= RS_CONN_RETRIES)
@@ -3312,6 +3327,15 @@  int rsetsockopt(int socket, int level, int optname,
 			rs->target_iomap_size = (uint16_t) rs_scale_to_value(
 				(uint8_t) rs_value_to_scale(*(int *) optval, 8), 8);
 			break;
+		case RDMA_ROUTE:
+			if ((rs->optval = calloc(optlen, 1))) {
+				memcpy(rs->optval, optval, optlen);
+				rs->optlen = optlen;
+				ret = 0;
+			} else {
+				ret = ERR(ENOMEM);
+			}
+			break;
 		default:
 			break;
 		}