[openib-general] [PATCH] [kdapl CM] Implement reverse address translation (dapl_ib_cm_remote_addr)

Hal Rosenstock halr at voltaire.com
Mon Jul 18 05:08:39 PDT 2005


[kdapl CM] Implement reverse address translation
(dapl_ib_cm_remote_addr)

Signed-off-by: Hal Rosenstock <halr at voltaire.com>


-- dapl_openib_cm.c.atkill	2005-07-16 08:54:39.000000000 -0400
+++ dapl_openib_cm.c	2005-07-17 20:53:30.000000000 -0400
@@ -220,6 +220,7 @@ static struct dapl_cm_ctx * dapl_get_cm_
 	cm_ctx->sp = comm_id->context;
 	comm_id->context = cm_ctx;
 	spin_lock_init(&cm_ctx->lock);
+	init_waitqueue_head(&cm_ctx->wait);
 	return cm_ctx;
 }
 
@@ -247,6 +248,9 @@ static int dapl_cm_passive_cb_handler(st
 
 	switch (event->event) {
 	case IB_CM_REQ_RECEIVED:
+		memcpy(&cm_ctx->dapl_path,
+		       ((struct ib_cm_req_event_param *)&event->param)->primary_path, 
+		       sizeof cm_ctx->dapl_path);
 		dapl_cr_callback(cm_ctx, DAT_CONNECTION_REQUEST_EVENT, 
 				 event->private_data, cm_ctx->sp);
 		break;
@@ -464,6 +468,7 @@ int dapl_ib_connect(struct dapl_ep *ep,
 	memset(cm_ctx, 0, sizeof *cm_ctx);
 
 	spin_lock_init(&cm_ctx->lock);
+	init_waitqueue_head(&cm_ctx->wait);
 	cm_ctx->ep = ep;
 	cm_ctx->cm_id = ib_create_cm_id(dapl_cm_active_cb_handler, cm_ctx);
 	if (IS_ERR(cm_ctx->cm_id)) {
@@ -846,28 +851,63 @@ reject:
 	return status;
 }
 
-static int ib_cm_get_remote_gid(struct dapl_cm_ctx *cm_ctx,
-				union ib_gid *remote_gid)
+static void dapl_ips_comp_handler(u64 req_id, void *context, int rec_num)
 {
-	return -ENOSYS;	/* for now!!! */
+	struct dapl_cm_ctx *cm_ctx = context;
+
+	atomic_set(&cm_ctx->wait_event, 0);
+	wake_up(&cm_ctx->wait);
 }
 
 /* 
- * Get IP address corresponding to remote GID
+ * dapl_ib_cm_remote_addr
+ *
+ * Obtain the IP address for a connection on an IA 
+ *
  */
 int dapl_ib_cm_remote_addr(struct dapl_ia *ia, struct dapl_cm_ctx *cm_ctx,
 			   struct sockaddr_in6 *remote_ia_address)
 {
+	union ib_gid *remote_gid;
+	u32 remote_ip;
+	struct sockaddr_in *ipv4_addr;
+	unsigned long flags;
 	int status;
-	union ib_gid remote_gid;
 
-	status = ib_cm_get_remote_gid(cm_ctx, &remote_gid);
-	if (status < 0)
-		return status;
+	spin_lock_irqsave(&cm_ctx->lock, flags);
+	if (atomic_read(&cm_ctx->wait_event) == 1) {
+		spin_unlock_irqrestore(&cm_ctx->lock, flags);
+		return -EAGAIN;
+	}
+	atomic_set(&cm_ctx->wait_event, 1);
+	spin_unlock_irqrestore(&cm_ctx->lock, flags);
 
-	if (!memcmp(&ia->hca->gid, &remote_gid, sizeof ia->hca->gid))
+	if (cm_ctx->sp)		/* passive side */
+		remote_gid = &cm_ctx->dapl_path.sgid;
+	else
+		remote_gid = &cm_ctx->dapl_path.dgid;
+	if (!memcmp(&ia->hca->gid, remote_gid, sizeof ia->hca->gid))
 		memcpy(remote_ia_address, &ia->hca->hca_address,
 		       sizeof *remote_ia_address);
 
+	/* Reverse ATS: lookup IP address by GID */
+	cm_ctx->dapl_comp.fn = &dapl_ips_comp_handler;
+	cm_ctx->dapl_comp.context = cm_ctx;
+	status = ib_at_ips_by_gid(remote_gid, &remote_ip, 1,
+				  &cm_ctx->dapl_comp);
+	if (status < 0) {
+		atomic_set(&cm_ctx->wait_event, 0);
+		dapl_dbg_log(DAPL_DBG_TYPE_ERR, " ib_at_ips_by_gid failed "
+			     "with status %d\n", status);
+		return -EAGAIN;
+	}
+
+	if (status != 1)
+		wait_event(cm_ctx->wait, !atomic_read(&cm_ctx->wait_event));
+
+	remote_ip = be32_to_cpu(remote_ip); /* or other way 'round ? */
+	ipv4_addr = (struct sockaddr_in *) remote_ia_address;
+	ipv4_addr->sin_family = AF_INET;
+	memcpy(&ipv4_addr->sin_addr.s_addr, &remote_ip, 4);
 	return 0;
 }





More information about the general mailing list